<s> from twisted . web . resource import Resource <EOL> from unpaddedbase64 import encode_base64 <EOL> import json <EOL> from sydent . db . invite_tokens import JoinTokenStore <EOL> from sydent . http . servlets import require_args <EOL> class Ed25519Servlet ( Resource ) : <EOL> isLeaf = True <EOL> def __init__ ( self , syd ) : <EOL> self . sydent = syd <EOL> def render_GET ( self , request ) : <EOL> pubKey = self . sydent . keyring . ed25519 . verify_key <EOL> pubKeyBase64 = encode_base64 ( pubKey . encode ( ) ) <EOL> return json . dumps ( { '<STR_LIT>' : pubKeyBase64 } ) <EOL> class PubkeyIsValidServlet ( Resource ) : <EOL> isLeaf = True <EOL> def __init__ ( self , syd ) : <EOL> self . sydent = syd <EOL> def render_GET ( self , request ) : <EOL> err = require_args ( request , ( "<STR_LIT>" , ) ) <EOL> if err : <EOL> return json . dumps ( err ) <EOL> pubKey = self . sydent . keyring . ed25519 . verify_key <EOL> pubKeyBase64 = encode_base64 ( pubKey . encode ( ) ) <EOL> return json . dumps ( { '<STR_LIT>' : request . args [ "<STR_LIT>" ] [ <NUM_LIT:0> ] == pubKeyBase64 } ) <EOL> class EphemeralPubkeyIsValidServlet ( Resource ) : <EOL> isLeaf = True <EOL> def __init__ ( self , syd ) : <EOL> self . joinTokenStore = JoinTokenStore ( syd ) <EOL> def render_GET ( self , request ) : <EOL> err = require_args ( request , ( "<STR_LIT>" , ) ) <EOL> if err : <EOL> return json . dumps ( err ) <EOL> publicKey = request . args [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> return json . dumps ( { <EOL> '<STR_LIT>' : self . joinTokenStore . validateEphemeralPublicKey ( publicKey ) , <EOL> } ) </s>
