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
ad48738e
Commit
ad48738e
authored
Aug 21, 2017
by
Sietse Ringers
Browse files
Documenting
parent
dd251895
Changes
2
Hide whitespace changes
Inline
Side-by-side
protocol/attributes.go
View file @
ad48738e
...
...
@@ -7,7 +7,8 @@ import (
"github.com/credentials/irmago"
)
// AttributeDisjunction ...
// An AttributeDisjunction encapsulates a list of possible attributes, one
// of which should be disclused.
type
AttributeDisjunction
struct
{
Label
string
Attributes
[]
irmago
.
AttributeTypeIdentifier
...
...
@@ -16,12 +17,17 @@ type AttributeDisjunction struct {
selected
*
irmago
.
AttributeTypeIdentifier
}
// An AttributeDisjunctionList is a list of AttributeDisjunctions.
type
AttributeDisjunctionList
[]
*
AttributeDisjunction
// HasValues indicates if the attributes of this disjunction have values
// that should be satisfied.
func
(
disjunction
*
AttributeDisjunction
)
HasValues
()
bool
{
return
disjunction
.
Values
!=
nil
&&
len
(
disjunction
.
Values
)
!=
0
}
// Satisfied indicates if this disjunction has a valid chosen attribute
// to be disclosed.
func
(
disjunction
*
AttributeDisjunction
)
Satisfied
()
bool
{
if
disjunction
.
selected
==
nil
{
return
false
...
...
@@ -71,28 +77,30 @@ func (dl AttributeDisjunctionList) Find(ai irmago.AttributeTypeIdentifier) *Attr
return
nil
}
// MarshalJSON marshals the disjunction to JSON.
func
(
disjunction
*
AttributeDisjunction
)
MarshalJSON
()
([]
byte
,
error
)
{
if
!
disjunction
.
HasValues
()
{
temp
:=
struct
{
Label
string
`json:"label"`
Label
string
`json:"label"`
Attributes
[]
irmago
.
AttributeTypeIdentifier
`json:"attributes"`
}{
Label
:
disjunction
.
Label
,
Attributes
:
disjunction
.
Attributes
,
}
return
json
.
Marshal
(
temp
)
}
else
{
temp
:=
struct
{
Label
string
`json:"label"`
Attributes
map
[
irmago
.
AttributeTypeIdentifier
]
string
`json:"attributes"`
}{
Label
:
disjunction
.
Label
,
Attributes
:
disjunction
.
Values
,
}
return
json
.
Marshal
(
temp
)
}
temp
:=
struct
{
Label
string
`json:"label"`
Attributes
map
[
irmago
.
AttributeTypeIdentifier
]
string
`json:"attributes"`
}{
Label
:
disjunction
.
Label
,
Attributes
:
disjunction
.
Values
,
}
return
json
.
Marshal
(
temp
)
}
// UnmarshalJSON unmarshals an attribute disjunction from JSON.
func
(
disjunction
*
AttributeDisjunction
)
UnmarshalJSON
(
bytes
[]
byte
)
error
{
if
disjunction
.
Values
==
nil
{
disjunction
.
Values
=
make
(
map
[
irmago
.
AttributeTypeIdentifier
]
string
)
...
...
protocol/messages.go
View file @
ad48738e
...
...
@@ -4,29 +4,45 @@ import (
"fmt"
"strconv"
"time"
"github.com/credentials/irmago"
)
// Session types.
const
(
DISCLOSING
=
"disclosing"
ISSUING
=
"issuing"
SIGNING
=
"signing"
DISCLOSING
=
SessionType
(
"disclosing"
)
ISSUING
=
SessionType
(
"issuing"
)
SIGNING
=
SessionType
(
"signing"
)
)
// Timestamp is a time.Time that marshals to Unix timestamps.
type
Timestamp
time
.
Time
// SessionType is a session type (DISCLOSING, ISSUING or SIGNING).
type
SessionType
string
// Qr contains the data of an IRMA session QR.
type
Qr
struct
{
Url
string
`json:"u"`
ProtocolVersion
string
`json:"v"`
ProtocolMaxVersion
string
`json:"vmax"`
Type
string
`json:"irmaqr"`
URL
string
`json:"u"`
ProtocolVersion
string
`json:"v"`
ProtocolMaxVersion
string
`json:"vmax"`
Type
SessionType
`json:"irmaqr"`
}
// A DisclosureChoice contains the attributes chosen to be disclosed.
type
DisclosureChoice
struct
{
Request
SessionRequest
Attributes
[]
*
irmago
.
AttributeIdentifier
}
// MarshalJSON marshals a timestamp.
func
(
t
*
Timestamp
)
MarshalJSON
()
([]
byte
,
error
)
{
ts
:=
time
.
Time
(
*
t
)
.
Unix
()
stamp
:=
fmt
.
Sprint
(
ts
)
return
[]
byte
(
stamp
),
nil
}
// UnmarshalJSON unmarshals a timestamp.
func
(
t
*
Timestamp
)
UnmarshalJSON
(
b
[]
byte
)
error
{
ts
,
err
:=
strconv
.
Atoi
(
string
(
b
))
if
err
!=
nil
{
...
...
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