From a0e58b8736e2e7967b91d39c3cfa7bd0e345a643 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 27 Nov 2019 15:15:33 -0800 Subject: [PATCH] Update per Dans' Comments --- applications/token_app.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/applications/token_app.go b/applications/token_app.go index c1f17f0..f46fc2a 100644 --- a/applications/token_app.go +++ b/applications/token_app.go @@ -16,6 +16,7 @@ type TokenApplication struct { // HasTokensCapability is granted once the client has obtained signed tokens const HasTokensCapability = tapir.Capability("HasTokensCapability") +const numTokens = 10 // NewInstance should always return a new instantiation of the application. func (tokenapp *TokenApplication) NewInstance() tapir.Application { @@ -29,7 +30,7 @@ func (tokenapp *TokenApplication) Init(connection tapir.Connection) { tokenapp.Transcript().NewProtocol("token-app") log.Debugf(tokenapp.Transcript().OutputTranscriptToAudit()) if connection.IsOutbound() { - tokens, blinded := privacypass.GenerateBlindedTokenBatch(10) + tokens, blinded := privacypass.GenerateBlindedTokenBatch(numTokens) data, _ := json.Marshal(blinded) connection.Send(data) var signedBatch privacypass.SignedBatchWithProof @@ -47,15 +48,17 @@ func (tokenapp *TokenApplication) Init(connection tapir.Connection) { // If the connection closes without the HasTokensCapability then the error can be handled by whatever client needs it log.Debugf("Failed to verify signed token batch") } - } else { - var blinded []privacypass.BlindedToken - err := json.Unmarshal(connection.Expect(), &blinded) - if err == nil { - batchProof := tokenapp.TokenService.SignBlindedTokenBatch(blinded, tokenapp.Transcript()) - log.Debugf(tokenapp.Transcript().OutputTranscriptToAudit()) - data, _ := json.Marshal(batchProof) - connection.Send(data) - return - } + return + } + + // We are the server + var blinded []privacypass.BlindedToken + err := json.Unmarshal(connection.Expect(), &blinded) + if err == nil { + batchProof := tokenapp.TokenService.SignBlindedTokenBatch(blinded, tokenapp.Transcript()) + log.Debugf(tokenapp.Transcript().OutputTranscriptToAudit()) + data, _ := json.Marshal(batchProof) + connection.Send(data) + return } }