def processOutgoingMessage(self, msg, flags, tlvs=[]): isQuery = self.parseExplicitQuery(msg) is not None if isQuery: return self.user.getDefaultQueryMessage(self.getPolicy) if self.state == STATE_PLAINTEXT: if self.getPolicy('REQUIRE_ENCRYPTION'): if not isQuery: self.lastMessage = msg self.lastSend = time() self.mayRetransmit = 2 # TODO notify msg = self.user.getDefaultQueryMessage(self.getPolicy) return msg if self.getPolicy('SEND_TAG') and \ self.tagOffer != OFFER_REJECTED and \ self.shouldTagMessage(msg): self.tagOffer = OFFER_SENT versions = set() if self.getPolicy('ALLOW_V1'): versions.add(1) if self.getPolicy('ALLOW_V2'): versions.add(2) return proto.TaggedPlaintext(msg, versions) return msg if self.state == STATE_ENCRYPTED: msg = self.crypto.createDataMessage(msg, flags, tlvs) self.lastSend = time() return msg if self.state == STATE_FINISHED: raise NotEncryptedError(EXC_FINISHED)
def taggedBoth(self, text, suffix, vset): self.assertEqual(text + suffix, bytes(proto.TaggedPlaintext(text, vset))) self.assertEqual(proto.TaggedPlaintext(text, vset), proto.TaggedPlaintext.parse(text + suffix))