(module auth-example racket/base (provide (except-out (all-defined-out) :decode-embedded :encode-embedded) (rename-out (:decode-embedded decode-embedded:auth-example) (:encode-embedded encode-embedded:auth-example))) (require preserves) (require preserves-schema/methods) (require preserves-schema/support) (require racket/match) (require racket/set) (require racket/dict) (require (only-in racket/generic define/generic)) (define :decode-embedded values) (define :encode-embedded values) (struct Ed25519PrivateKey (q d) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((Ed25519PrivateKey ?q ?d) (record 'ed25519-private-key (list (*->preserve ?q) (*->preserve ?d)))))))) (define (parse-Ed25519PrivateKey input) (match input ((and dest (record 'ed25519-private-key (list (and ?q (? bytes?)) (and ?d (? bytes?)) _ ...))) (Ed25519PrivateKey ?q ?d)) (_ eof))) (define parse-Ed25519PrivateKey! (parse-success-or-error 'parse-Ed25519PrivateKey parse-Ed25519PrivateKey)) (struct Ed25519PublicKey (q) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((Ed25519PublicKey ?q) (record 'ed25519-public-key (list (*->preserve ?q)))))))) (define (parse-Ed25519PublicKey input) (match input ((and dest (record 'ed25519-public-key (list (and ?q (? bytes?)) _ ...))) (Ed25519PublicKey ?q)) (_ eof))) (define parse-Ed25519PublicKey! (parse-success-or-error 'parse-Ed25519PublicKey parse-Ed25519PublicKey)) (struct PublicKey (value) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((PublicKey src) (*->preserve src)))))) (define (parse-PublicKey input) (match input ((app parse-Ed25519PublicKey (and dest (not (== eof)))) (PublicKey dest)) (_ eof))) (define parse-PublicKey! (parse-success-or-error 'parse-PublicKey parse-PublicKey)) (define (SshAuthMethod? p) (or (SshAuthMethod-none? p) (SshAuthMethod-publickey? p) (SshAuthMethod-password? p))) (struct SshAuthMethod-none () #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthMethod-none) '#"none"))))) (struct SshAuthMethod-publickey () #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthMethod-publickey) '#"publickey"))))) (struct SshAuthMethod-password () #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthMethod-password) '#"password"))))) (define (parse-SshAuthMethod input) (match input ((and dest (== '#"none")) (SshAuthMethod-none)) ((and dest (== '#"publickey")) (SshAuthMethod-publickey)) ((and dest (== '#"password")) (SshAuthMethod-password)) (_ eof))) (define parse-SshAuthMethod! (parse-success-or-error 'parse-SshAuthMethod parse-SshAuthMethod)) (define (SshAuthRequest? p) (or (SshAuthRequest-none? p) (SshAuthRequest-publickey? p) (SshAuthRequest-password? p))) (struct SshAuthRequest-none (username) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthRequest-none ?username) (record 'none (list (*->preserve ?username)))))))) (struct SshAuthRequest-publickey (username key) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthRequest-publickey ?username ?key) (record 'publickey (list (*->preserve ?username) (*->preserve ?key)))))))) (struct SshAuthRequest-password (username password) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthRequest-password ?username ?password) (record 'password (list (*->preserve ?username) (*->preserve ?password)))))))) (define (parse-SshAuthRequest input) (match input ((and dest (record 'none (list (and ?username (? string?)) _ ...))) (SshAuthRequest-none ?username)) ((and dest (record 'publickey (list (and ?username (? string?)) (app parse-PublicKey (and ?key (not (== eof)))) _ ...))) (SshAuthRequest-publickey ?username ?key)) ((and dest (record 'password (list (and ?username (? string?)) (and ?password (? string?)) _ ...))) (SshAuthRequest-password ?username ?password)) (_ eof))) (define parse-SshAuthRequest! (parse-success-or-error 'parse-SshAuthRequest parse-SshAuthRequest)) (struct SshAuthenticatedUser (username service) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthenticatedUser ?username ?service) (record 'authenticated (list (*->preserve ?username) (*->preserve ?service)))))))) (define (parse-SshAuthenticatedUser input) (match input ((and dest (record 'authenticated (list (and ?username (? string?)) (and ?service (? bytes?)) _ ...))) (SshAuthenticatedUser ?username ?service)) (_ eof))) (define parse-SshAuthenticatedUser! (parse-success-or-error 'parse-SshAuthenticatedUser parse-SshAuthenticatedUser)) (struct SshAuthenticationAcceptable (method request ok) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthenticationAcceptable ?method ?request ?ok) (record 'authentication-acceptable? (list (*->preserve ?method) (*->preserve ?request) (*->preserve ?ok)))))))) (define (parse-SshAuthenticationAcceptable input) (match input ((and dest (record 'authentication-acceptable? (list (app parse-SshAuthMethod (and ?method (not (== eof)))) (app parse-SshAuthRequest (and ?request (not (== eof)))) (and ?ok (? boolean?)) _ ...))) (SshAuthenticationAcceptable ?method ?request ?ok)) (_ eof))) (define parse-SshAuthenticationAcceptable! (parse-success-or-error 'parse-SshAuthenticationAcceptable parse-SshAuthenticationAcceptable)) (struct SshAuthenticationMethodAcceptable (method) #:transparent #:methods gen:preservable ((define/generic *->preserve ->preserve) (define (->preserve preservable) (match preservable ((SshAuthenticationMethodAcceptable ?method) (record 'authentication-method-acceptable (list (*->preserve ?method)))))))) (define (parse-SshAuthenticationMethodAcceptable input) (match input ((and dest (record 'authentication-method-acceptable (list (app parse-SshAuthMethod (and ?method (not (== eof)))) _ ...))) (SshAuthenticationMethodAcceptable ?method)) (_ eof))) (define parse-SshAuthenticationMethodAcceptable! (parse-success-or-error 'parse-SshAuthenticationMethodAcceptable parse-SshAuthenticationMethodAcceptable)))