Beispiel #1
0
def readObjectIdentifier(s, oid):
    """
    @summary: read object identifier
    @param oid: must be a tuple of 6 elements
    @param s: Stream
    @return: true if oid is same as in stream
    """
    size = readLength(s)
    if size != 5:
        raise InvalidValue("size of stream oid is wrong %d != 5" % size)
    a_oid = [0, 0, 0, 0, 0, 0]
    t12 = UInt8()
    s.readType(t12)
    a_oid[0] = t12.value >> 4
    a_oid[1] = t12.value & 0x0f
    s.readType(t12)
    a_oid[2] = t12.value
    s.readType(t12)
    a_oid[3] = t12.value
    s.readType(t12)
    a_oid[4] = t12.value
    s.readType(t12)
    a_oid[5] = t12.value

    if list(oid) != a_oid:
        raise InvalidExpectedDataException("invalid object identifier")
Beispiel #2
0
    def __setValue__(self, value):
        """
        @summary:  Check if new value respect type declaration
                    Ex: UInt8 can be > 256
        @param value: new value (raw python type | lambda | function)
        @raise InvalidValue: if value doesn't respect type range
        @see: CallableValue.__setValue__
        """
        #check static value range
        if not callable(value) and not self.isInRange(value):
            raise InvalidValue("value is out of range for %s" % self.__class__)

        CallableValue.__setValue__(self, value)
Beispiel #3
0
 def readDomainParams(self, s):
     """
     @summary: Read domain parameters structure
     @param s: {Stream}
     @return: {Tuple} (max_channels, max_users, max_tokens, max_pdu_size)
     """
     if not ber.readUniversalTag(s, ber.Tag.BER_TAG_SEQUENCE, True):
         raise InvalidValue("bad BER tags")
     ber.readLength(s)  #length
     max_channels = ber.readInteger(s)
     max_users = ber.readInteger(s)
     max_tokens = ber.readInteger(s)
     ber.readInteger(s)
     ber.readInteger(s)
     ber.readInteger(s)
     max_pdu_size = ber.readInteger(s)
     ber.readInteger(s)
     return (max_channels, max_users, max_tokens, max_pdu_size)
Beispiel #4
0
def readOctetStream(s, octetStream, minValue=0):
    """
    @summary: read string as octet stream and compare with octetStream
    @param octetStream: compare stream
    @param s: Stream
    @param minValue: min value
    @return: if stream read from s is equal to octetStream
    """
    size = readLength(s) + minValue
    if size != len(octetStream):
        raise InvalidValue("incompatible size %d != %d" (len(octetStream),
                                                         size))
    for i in range(0, size):
        c = UInt8()
        s.readType(c)
        if ord(octetStream[i]) != c.value:
            return False

    return True
Beispiel #5
0
def readInteger(s):
    """
    @summary: read interger per format from stream
    @param s: Stream
    @return: python int or long
    @raise InvalidValue: if size of integer is not correct
    """
    result = None
    size = readLength(s)
    if size == 1:
        result = UInt8()
    elif size == 2:
        result = UInt16Be()
    elif size == 4:
        result = UInt32Be()
    else:
        raise InvalidValue("invalid integer size %d" % size)
    s.readType(result)
    return result.value
Beispiel #6
0
    def __getValue__(self):
        """
        @summary:  Check value if match range of type
                    And apply sign
                    Ex: UInt8 can be > 255
        @return: Python value wrap into type
        @raise InvalidValue: if value doesn't respect type range
        @see: CallableValue.__getValue__
        """
        value = CallableValue.__getValue__(self)

        #check value now because it can be an callable value
        #and evaluate a this time

        if not self.isInRange(value):
            raise InvalidValue("value is out of range for %s" % self.__class__)
        if self._signed:
            return value
        else:
            return value & self.mask()
Beispiel #7
0
 def read(self, s):
     old = deepcopy(self)
     oldRead(self, s)
     if self != old:
         raise InvalidValue("CheckValueOnRead %s != %s" % (self, old))