def addKey(self, cname, key): if cname and not isValidUserName(cname): return self._error("Bad username.") k = RSAKey() try: k.fromPEM_PublicKey(pemPublicKey) except RSAError: return self._error("Bad PEM-encoded key.") contact = Contact(k, cname) self._onAddContact(contact)
def _onLookupResponse(self, responseCode, data): if responseCode != 200: self._addOp.notify(None) return inp = StringIO.StringIO(data) name = inp.readline().strip() pemPublicKey = inp.read() if name and not isValidUserName(name): self._addOp.notify(None) return k = RSAKey() try: k.fromPEM_PublicKey(pemPublicKey) except RSAError: self._addOp.notify(None) contact = Contact(k, self._addOp.cname) self._addOp.notify(contact)