Esempio n. 1
0
def construct(identity, content):
    return EncryptedFrame(
        RawData('r') + \
        RawData(str_address(identity.location)) + \
        RawData((0,)) + \
        RawData(identity.encryptor.encrypt(content))
    )
Esempio n. 2
0
def construct(identity, content):
    signature = identity.sign(content)
    siglen = len(signature)

    return SignedFrame(
        RawData('s') + \
        RawData(str_address(identity.location)) + \
        RawData((0, siglen // 256, siglen % 256)) + \
        RawData(signature) + \
        RawData(content)
    )
Esempio n. 3
0
    def rcv_callback(self, msg, client):
        '''
        Callback for EJTP client.

        TODO: Filter out messages where EJTP sender does not match "from" field.
        '''
        msg_dict = json.loads(msg.content)
        msg_type = msg_dict['type']
        msg_data = msg_dict['data']
        if msg_type == "ejmail-message":
            self.recv(msg_data, msg.addr)
        elif msg_type == "ejmail-mark":
            saddr = address.str_address(msg.addr)
            for hash in msg_data:
                del self.unread[saddr][hash]
            for unread in self.unread[saddr].values():
                self.send(unread, [('Retrying send...', saddr)])
Esempio n. 4
0
    def send(self, msg, recipients=None):
        '''
        Send ejmail.message.Message object to its recipients.

        >>> import time
        >>> m3addr = ['udp4', ['localhost',9003], 'britta']
        >>> m4addr = ['udp4', ['localhost',9004], 'jeff']
        >>> m3 = Mailbox(m3addr)
        >>> m4 = Mailbox(m4addr)
        >>> m4.client.encryptor_cache = m3.client.encryptor_cache
        >>> m3.client.encryptor_set(m3addr, ['rotate', 5])
        >>> m3.client.encryptor_set(m4addr, ['rotate', -14])
        >>> msg = Message({
        ...     'to':[['Jeff Winger', m4addr]],
        ...     'from':['Britta Perry', m3addr],
        ...     'conversation':'Wazzaaaappp',
        ...     'content':"I'm druunnkkkk",
        ... })
        >>> m3.send(msg); time.sleep(0.1) #doctest: +ELLIPSIS
        UDPJack out: ...
        >>> m4.conversations.keys()
        [u'Wazzaaaappp']
        >>> m4.conversations['Wazzaaaappp'].timeline()[0].content
        u"I'm druunnkkkk"
        >>> m3.unread
        {'["udp4",["localhost",9004],"jeff"]': {}}
        '''
        convo = msg.conversation
        self.add_conversation(convo)
        convo_obj = self.conversations[convo]
        convo_obj.register_message(msg)
        recipients = recipients or msg.data['to']
        for recipient in recipients:
            name, addr = recipient
            self.client.write_json(address.py_address(addr), {
                'type':'ejmail-message',
                'data':msg.data,
            })
            saddr = address.str_address(addr)
            if not saddr in self.unread:
                self.unread[saddr] = {}
            self.unread[saddr][msg.hash] = msg
Esempio n. 5
0
 def key(self):
     return str_address(self.location)
 def _assert(self, expected, value):
     self.assertEqual(expected, str_address(value))
Esempio n. 7
0
	def owns(self, docname):
		# Returns bool for whether document owner is a client.
		owner = document.owner(docname)
		return owner == ejtpaddress.str_address(self.interface)
Esempio n. 8
0
 def owns(self, docname):
     # Returns bool for whether document owner is a client.
     owner = document.owner(docname)
     return owner == ejtpaddress.str_address(self.interface)