def recvSecurityResult(self, data): ''' Read security result packet ''' result = UInt32Be() data.readType(result) if result == UInt32Be(1): print "Authentification failed" if self._version == ProtocolVersion.RFB003008: self.expectWithHeader(4, self.recvSecurityFailed) else: print "Authentification OK" self.sendClientInit()
def readInteger(s): ''' read integer structure from stream @param s: stream @return: int or long python ''' if not readUniversalTag(s, Tag.BER_TAG_INTEGER, False): raise InvalidExpectedDataException("bad integer tag") size = readLength(s) if size == 1: integer = UInt8() s.readType(integer) return integer.value elif size == 2: integer = UInt16Be() s.readType(integer) return integer.value elif size == 3: integer1 = UInt8() integer2 = UInt16Be() s.readType(integer1) s.readType(integer2) return integer2.value + (integer1.value << 16) elif size == 4: integer = UInt32Be() s.readType(integer) return integer.value else: raise InvalidExpectedDataException("wrong integer size")
def writeInteger(value): ''' write integer value @param param: int or python long @return ber interger structure ''' if value <= 0xff: return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(1), UInt8(value)) elif value <= 0xffff: return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(2), UInt16Be(value)) else: return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(4), UInt32Be(value))
def writeInteger(value): ''' write python long or int into per integer format @param value: int or long python value @return: UInt8, UInt16Be or UInt32Be ''' if value <= 0xff: return (writeLength(1), UInt8(value)) elif value < 0xffff: return (writeLength(2), UInt16Be(value)) else: return (writeLength(4), UInt32Be(value))
def expectedBody(self, data): ''' read header and wait header value to call next state @param data: Stream that length are to header length (1|2|4 bytes) set next state to callBack body when length read from header are received ''' bodyLen = None if data.len == 1: bodyLen = UInt8() elif data.len == 2: bodyLen = UInt16Be() elif data.len == 4: bodyLen = UInt32Be() else: print "invalid header length" return data.readType(bodyLen) self.expect(bodyLen.value, self._callbackBody)
def readInteger(s): ''' 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
def __init__(self, text=""): CompositeType.__init__(self) self.padding = (UInt16Be(), UInt8()) self.size = UInt32Be(len(text)) self.message = String(text)
def __init__(self, downFlag=False, key=0): CompositeType.__init__(self) self.downFlag = UInt8(downFlag) self.padding = UInt16Be() self.key = UInt32Be(key)