From 6fbaac7a14d2a03b74e10a4a82b1147ee1dd7d49 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Tue, 24 Sep 2019 15:38:32 -0400 Subject: [PATCH] switch to a documentable data structure --- src/PaymentServer/Issuer.hs | 5 +++-- src/PaymentServer/Ristretto.hs | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/PaymentServer/Issuer.hs b/src/PaymentServer/Issuer.hs index a3473b5..939910c 100644 --- a/src/PaymentServer/Issuer.hs +++ b/src/PaymentServer/Issuer.hs @@ -14,7 +14,8 @@ module PaymentServer.Issuer ) where import PaymentServer.Ristretto - ( ristretto + ( Issuance(Issuance) + , ristretto ) import Data.Text @@ -68,5 +69,5 @@ ristrettoIssue ristrettoIssue signingKey tokens = do let issuance = ristretto signingKey tokens case issuance of - Right (publicKey, tokens, proof) -> Right $ ChallengeBypass publicKey tokens proof + Right (Issuance publicKey tokens proof) -> Right $ ChallengeBypass publicKey tokens proof Left err -> Left . pack . show $ err diff --git a/src/PaymentServer/Ristretto.hs b/src/PaymentServer/Ristretto.hs index 77f0735..4927860 100644 --- a/src/PaymentServer/Ristretto.hs +++ b/src/PaymentServer/Ristretto.hs @@ -3,7 +3,8 @@ {-# LANGUAGE EmptyDataDecls #-} module PaymentServer.Ristretto - ( randomSigningKey + ( Issuance(Issuance) + , randomSigningKey , ristretto ) where @@ -62,14 +63,15 @@ foreign import ccall "batch_dleq_proof_encode_base64" batch_dleq_proof_encode_ba foreign import ccall "batch_dleq_proof_destroy" batch_dleq_proof_destroy :: Ptr C_BatchDLEQProof -> IO () -- | Private type to represent the return value of ristretto. -type Issuance = - ( Text -- ^ The base64-encoded public key corresponding to the - -- signing key which generated the signatures. - , [Text] -- ^ A list of base64-encoded token signatures. - , Text -- ^ The base64-encoded batch DLEQ proof that the signatures - -- were made with the signing key corresponding to the public - -- key. - ) +data Issuance = + Issuance + { publicKey :: Text -- ^ The base64-encoded public key corresponding to the + -- signing key which generated the signatures. + , signatures :: [Text] -- ^ A list of base64-encoded token signatures. + , proof :: Text -- ^ The base64-encoded batch DLEQ proof that the signatures + -- were made with the signing key corresponding to the public + -- key. + } data RistrettoFailure = SigningKeyAllocation @@ -147,7 +149,7 @@ ristretto textSigningKey textTokens = False -> do encodedSignedTokens <- mapM peekCString encodedCStringSignedTokens encodedProof <- newEncodedProof blindedTokens signedTokens signingKey - return $ Right (pack encodedPublicKey, map pack encodedSignedTokens, pack encodedProof) + return . Right $ Issuance (pack encodedPublicKey) (map pack encodedSignedTokens) (pack encodedProof) -- | randomSigningKey generates a new signing key at random and returns it -- GitLab