Commit c0a1415d authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add PinHandler interface to keyshare and manager api

parent 9f7626c7
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
// KeysharePinRequestor is used to asking the user for his PIN. // KeysharePinRequestor is used to asking the user for his PIN.
type KeysharePinRequestor interface { type KeysharePinRequestor interface {
RequestPin(remainingAttempts int, callback func(proceed bool, pin string)) RequestPin(remainingAttempts int, callback PinHandler)
} }
type keyshareSessionHandler interface { type keyshareSessionHandler interface {
...@@ -203,7 +203,7 @@ func startKeyshareSession( ...@@ -203,7 +203,7 @@ func startKeyshareSession(
// Ask for a pin, repeatedly if necessary, and either continue the keyshare protocol // Ask for a pin, repeatedly if necessary, and either continue the keyshare protocol
// with authorization, or stop the keyshare protocol and inform of failure. // with authorization, or stop the keyshare protocol and inform of failure.
func (ks *keyshareSession) VerifyPin(attempts int) { func (ks *keyshareSession) VerifyPin(attempts int) {
ks.pinRequestor.RequestPin(attempts, func(proceed bool, pin string) { ks.pinRequestor.RequestPin(attempts, PinHandler(func(proceed bool, pin string) {
success, attemptsRemaining, blocked, err := ks.verifyPinAttempt(pin) success, attemptsRemaining, blocked, err := ks.verifyPinAttempt(pin)
if err != nil { if err != nil {
ks.sessionHandler.KeyshareError(err) ks.sessionHandler.KeyshareError(err)
...@@ -222,7 +222,7 @@ func (ks *keyshareSession) VerifyPin(attempts int) { ...@@ -222,7 +222,7 @@ func (ks *keyshareSession) VerifyPin(attempts int) {
} }
// Not successful but no error and not yet blocked: try again // Not successful but no error and not yet blocked: try again
ks.VerifyPin(attemptsRemaining) ks.VerifyPin(attemptsRemaining)
}) }))
} }
// Verify the specified pin at each of the keyshare servers involved in the specified session. // Verify the specified pin at each of the keyshare servers involved in the specified session.
......
...@@ -17,6 +17,8 @@ import ( ...@@ -17,6 +17,8 @@ import (
// and specifying the attributes to be disclosed. // and specifying the attributes to be disclosed.
type PermissionHandler func(proceed bool, choice *DisclosureChoice) type PermissionHandler func(proceed bool, choice *DisclosureChoice)
type PinHandler func(proceed bool, pin string)
// A Handler contains callbacks for communication to the user. // A Handler contains callbacks for communication to the user.
type Handler interface { type Handler interface {
StatusUpdate(action Action, status Status) StatusUpdate(action Action, status Status)
...@@ -31,7 +33,7 @@ type Handler interface { ...@@ -31,7 +33,7 @@ type Handler interface {
RequestSignaturePermission(request SignatureRequest, ServerName string, callback PermissionHandler) RequestSignaturePermission(request SignatureRequest, ServerName string, callback PermissionHandler)
RequestSchemeManagerPermission(manager *SchemeManager, callback func(proceed bool)) RequestSchemeManagerPermission(manager *SchemeManager, callback func(proceed bool))
RequestPin(remainingAttempts int, callback func(proceed bool, pin string)) RequestPin(remainingAttempts int, callback PinHandler)
} }
// A session is an IRMA session. // A session is an IRMA session.
......
...@@ -69,7 +69,7 @@ func (th TestHandler) RequestSignaturePermission(request SignatureRequest, Serve ...@@ -69,7 +69,7 @@ func (th TestHandler) RequestSignaturePermission(request SignatureRequest, Serve
func (th TestHandler) RequestSchemeManagerPermission(manager *SchemeManager, callback func(proceed bool)) { func (th TestHandler) RequestSchemeManagerPermission(manager *SchemeManager, callback func(proceed bool)) {
callback(true) callback(true)
} }
func (th TestHandler) RequestPin(remainingAttempts int, callback func(proceed bool, pin string)) { func (th TestHandler) RequestPin(remainingAttempts int, callback PinHandler) {
callback(true, "12345") callback(true, "12345")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment