def testPublicKeySerialization(self): keys = crypto.KeyPair(self.temp_dir + "/temp_key") signature = keys.sign("Message") pub_key = keys.get_pub_key() classname, pem_string = pub_key._pack() pub_key = crypto.PublicKey(pem_string=pem_string) self.failUnlessEqual(crypto.verify("Message", signature, pub_key), True) self.failUnlessEqual(rencode.loads(rencode.dumps(pub_key)), str(pub_key)) print rencode.dumps(pub_key) print rencode.loads(rencode.dumps(pub_key)) print pub_key.rsa.as_pem()
def rpc_call(self, func_name, params): '''Performs a rpc call @param func_name: name of the remote callable @param params: a tuple of arguments to pass to the remote callable ''' while not self.connected: self.connect() self.xtime.swait(500) data = rencode.dumps((func_name, params)) self.socket.sendall(_data_pack(data)) recv_encoded_data = _data_unpack_from_stream_socket(self.socket) if not recv_encoded_data: raise RPCNetError('Connection closed before reply') recv_data = rencode.loads(recv_encoded_data) print recv_data logging.debug('Recvd data: %s' % str(recv_data)) # Handling errors # I receive a message with the following format: # ('rmt_error', message_error) # where message_error is a string if isinstance(recv_data, tuple) and recv_data[0] == 'rmt_error': raise RPCError(recv_data[1]) return recv_data
def rpc_call(self, func_name, params): """Performs a rpc call @param func_name: name of the remote callable @param params: a tuple of arguments to pass to the remote callable """ while not self.connected: self.connect() self.xtime.swait(500) data = rencode.dumps((func_name, params)) self.socket.sendall(_data_pack(data)) recv_encoded_data = _data_unpack_from_stream_socket(self.socket) if not recv_encoded_data: raise RPCNetError("Connection closed before reply") recv_data = rencode.loads(recv_encoded_data) print recv_data logging.debug("Recvd data: %s" % str(recv_data)) # Handling errors # I receive a message with the following format: # ('rmt_error', message_error) # where message_error is a string if isinstance(recv_data, tuple) and recv_data[0] == "rmt_error": raise RPCError(recv_data[1]) return recv_data
def rpc_call(self, func_name, params): '''Performs a rpc call @param func_name: name of the remote callable @param params: a tuple of arguments to pass to the remote callable ''' while not self.connected: self.connect() self.xtime.swait(500) data = rencode.dumps((func_name, params)) self.send(_data_pack(data))
def rpc_call(self, func_name, params): """Performs a rpc call @param func_name: name of the remote callable @param params: a tuple of arguments to pass to the remote callable """ while not self.connected: self.connect() self.xtime.swait(500) data = rencode.dumps((func_name, params)) self.send(_data_pack(data))
def marshalled_dispatch(self, caller, data): '''Dispatches a RPC function from marshalled data''' error = 0 try: unpacked = rencode.loads(data) except ValueError: error = 1 if error or not isinstance(unpacked, tuple) or not len(unpacked) == 2: e = 'Malformed packet received from ' + caller.ip logging.debug(e) response = ('rmt_error', str(e)) else: response = self.dispatch(caller, *unpacked) return rencode.dumps(response)
def marshalled_dispatch(self, caller, data): """Dispatches a RPC function from marshalled data""" error = 0 try: unpacked = rencode.loads(data) except ValueError: error = 1 if error or not isinstance(unpacked, tuple) or not len(unpacked) == 2: e = "Malformed packet received from " + caller.ip logging.debug(e) response = ("rmt_error", str(e)) else: response = self.dispatch(caller, *unpacked) return rencode.dumps(response)