Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
fe20bca4
Commit
fe20bca4
authored
Jul 25, 2018
by
Sietse Ringers
Browse files
Remove code duplication in interactive/manual sessions
parent
303c9f59
Changes
1
Hide whitespace changes
Inline
Side-by-side
irmaclient/session.go
View file @
fe20bca4
...
...
@@ -82,7 +82,7 @@ var supportedVersions = map[int][]int{
// Session constructors
// NewSession starts a new IRMA session, given (along with a handler to pass feedback to)
// either an *irma.QR; a string that contains a JSON-serialized irma.QR;
// either an
irma.QR or
*irma.QR; a string that contains a JSON-serialized irma.QR;
// or a string that contains a serialized *irma.SignatureRequest.
// In any other case it calls the Failure method of the specified Handler.
func
(
client
*
Client
)
NewSession
(
info
interface
{},
handler
Handler
)
SessionDismisser
{
...
...
@@ -138,26 +138,7 @@ func (client *Client) newManualSession(sigrequest *irma.SignatureRequest, handle
session
.
Handler
.
StatusUpdate
(
session
.
Action
,
irma
.
StatusManualStarted
)
if
!
session
.
checkAndUpateConfiguration
()
{
return
nil
}
candidates
,
missing
:=
session
.
client
.
CheckSatisfiability
(
session
.
request
.
ToDisclose
())
if
len
(
missing
)
>
0
{
session
.
Handler
.
UnsatisfiableRequest
(
session
.
Action
,
"E-mail request"
,
missing
)
return
nil
}
session
.
request
.
SetCandidates
(
candidates
)
// Ask for permission to execute the session
callback
:=
PermissionHandler
(
func
(
proceed
bool
,
choice
*
irma
.
DisclosureChoice
)
{
session
.
choice
=
choice
session
.
request
.
SetDisclosureChoice
(
choice
)
go
session
.
doSession
(
proceed
)
})
session
.
Handler
.
RequestSignaturePermission
(
*
session
.
request
.
(
*
irma
.
SignatureRequest
),
"E-mail request"
,
callback
)
session
.
processSessionInfo
(
"Email request"
)
return
session
}
...
...
@@ -183,6 +164,9 @@ func (client *Client) newQrSession(qr *irma.Qr, handler Handler) SessionDismisse
}
session
.
Version
=
version
session
.
transport
.
SetHeader
(
"X-IRMA-ProtocolVersion"
,
version
.
String
())
if
!
strings
.
HasSuffix
(
session
.
ServerURL
,
"/"
)
{
session
.
ServerURL
+=
"/"
}
// Check if the action is one of the supported types
switch
session
.
Action
{
...
...
@@ -196,19 +180,13 @@ func (client *Client) newQrSession(qr *irma.Qr, handler Handler) SessionDismisse
return
nil
}
if
!
strings
.
HasSuffix
(
session
.
ServerURL
,
"/"
)
{
session
.
ServerURL
+=
"/"
}
go
session
.
getSessionInfo
()
return
session
}
// Core session methods
// getSessionInfo retrieves the first message in the IRMA protocol, checks if we can perform
// the request, and informs the user of the outcome.
// getSessionInfo retrieves the first message in the IRMA protocol (only in interactive sessions)
func
(
session
*
session
)
getSessionInfo
()
{
defer
session
.
recoverFromPanic
()
...
...
@@ -240,6 +218,14 @@ func (session *session) getSessionInfo() {
}
}
session
.
processSessionInfo
(
session
.
jwt
.
Requestor
())
}
// processSessionInfo continues the session after all session state has been received:
// it checks if the session can be performed and asks the user for consent.
func
(
session
*
session
)
processSessionInfo
(
requestorname
string
)
{
defer
session
.
recoverFromPanic
()
if
!
session
.
checkAndUpateConfiguration
()
{
return
}
...
...
@@ -263,7 +249,7 @@ func (session *session) getSessionInfo() {
candidates
,
missing
:=
session
.
client
.
CheckSatisfiability
(
session
.
request
.
ToDisclose
())
if
len
(
missing
)
>
0
{
session
.
Handler
.
UnsatisfiableRequest
(
session
.
Action
,
session
.
jwt
.
R
equestor
()
,
missing
)
session
.
Handler
.
UnsatisfiableRequest
(
session
.
Action
,
r
equestor
name
,
missing
)
return
}
session
.
request
.
SetCandidates
(
candidates
)
...
...
@@ -278,13 +264,13 @@ func (session *session) getSessionInfo() {
switch
session
.
Action
{
case
irma
.
ActionDisclosing
:
session
.
Handler
.
RequestVerificationPermission
(
*
session
.
request
.
(
*
irma
.
DisclosureRequest
),
session
.
jwt
.
R
equestor
()
,
callback
)
*
session
.
request
.
(
*
irma
.
DisclosureRequest
),
r
equestor
name
,
callback
)
case
irma
.
ActionSigning
:
session
.
Handler
.
RequestSignaturePermission
(
*
session
.
request
.
(
*
irma
.
SignatureRequest
),
session
.
jwt
.
R
equestor
()
,
callback
)
*
session
.
request
.
(
*
irma
.
SignatureRequest
),
r
equestor
name
,
callback
)
case
irma
.
ActionIssuing
:
session
.
Handler
.
RequestIssuancePermission
(
*
session
.
request
.
(
*
irma
.
IssuanceRequest
),
session
.
jwt
.
R
equestor
()
,
callback
)
*
session
.
request
.
(
*
irma
.
IssuanceRequest
),
r
equestor
name
,
callback
)
default
:
panic
(
"Invalid session type"
)
// does not happen, session.Action has been checked earlier
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment