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
1a5b4d62
Commit
1a5b4d62
authored
Jan 25, 2018
by
Ayke van Laethem
Browse files
Add support for optional attributes
parent
c10536c1
Changes
6
Hide whitespace changes
Inline
Side-by-side
descriptions.go
View file @
1a5b4d62
...
...
@@ -77,6 +77,7 @@ func (ct *CredentialType) ContainsAttribute(ai AttributeTypeIdentifier) bool {
// AttributeDescription is a description of an attribute within a credential type.
type
AttributeDescription
struct
{
ID
string
`xml:"id,attr"`
Optional
string
`xml:"optional,attr"`
Name
TranslatedString
Description
TranslatedString
}
...
...
irmaclient/session_test.go
View file @
1a5b4d62
...
...
@@ -137,6 +137,32 @@ func getIssuanceRequest(defaultValidity bool) *irma.IssuanceRequest {
}
}
func
getNameIssuanceRequest
(
prefix
bool
)
*
irma
.
IssuanceRequest
{
expiry
:=
irma
.
Timestamp
(
irma
.
NewMetadataAttribute
()
.
Expiry
())
credid
:=
irma
.
NewCredentialTypeIdentifier
(
"irma-demo.MijnOverheid.fullName"
)
req
:=
&
irma
.
IssuanceRequest
{
Credentials
:
[]
*
irma
.
CredentialRequest
{
{
Validity
:
&
expiry
,
CredentialTypeID
:
&
credid
,
Attributes
:
map
[
string
]
string
{
"firstnames"
:
"Johan Pieter"
,
"firstname"
:
"Johan"
,
"familyname"
:
"Stuivezand"
,
"prefix"
:
""
,
},
},
},
}
if
(
prefix
)
{
req
.
Credentials
[
0
]
.
Attributes
[
"prefix"
]
=
"van"
}
return
req
}
func
getIssuanceJwt
(
name
string
,
defaultValidity
bool
)
interface
{}
{
return
irma
.
NewIdentityProviderJwt
(
name
,
getIssuanceRequest
(
defaultValidity
))
}
...
...
@@ -191,6 +217,16 @@ func TestDefaultCredentialValidity(t *testing.T) {
sessionHelper
(
t
,
jwtcontents
,
"issue"
,
client
)
}
func
TestIssuanceOptionalEmptyAttributes
(
t
*
testing
.
T
)
{
jwt
:=
irma
.
NewIdentityProviderJwt
(
"testip"
,
getNameIssuanceRequest
(
false
))
sessionHelper
(
t
,
jwt
,
"issue"
,
nil
)
}
func
TestIssuanceOptionalSetAttributes
(
t
*
testing
.
T
)
{
jwt
:=
irma
.
NewIdentityProviderJwt
(
"testip"
,
getNameIssuanceRequest
(
true
))
sessionHelper
(
t
,
jwt
,
"issue"
,
nil
)
}
func
TestLargeAttribute
(
t
*
testing
.
T
)
{
client
:=
parseStorage
(
t
)
require
.
NoError
(
t
,
client
.
RemoveAllCredentials
())
...
...
requests.go
View file @
1a5b4d62
...
...
@@ -142,21 +142,36 @@ func (cr *CredentialRequest) AttributeList(conf *Configuration) (*AttributeList,
return
nil
,
err
}
attrs
:=
make
([]
*
big
.
Int
,
len
(
cr
.
Attributes
)
+
1
,
len
(
cr
.
Attributes
)
+
1
)
credtype
:=
conf
.
CredentialTypes
[
*
cr
.
CredentialTypeID
]
if
credtype
==
nil
{
return
nil
,
errors
.
New
(
"Unknown credential type"
)
}
if
len
(
credtype
.
Attributes
)
!=
len
(
cr
.
Attributes
)
{
return
nil
,
errors
.
New
(
"Received unexpected amount of attributes"
)
// Check that there are no attributes in the credential request that aren't
// in the credential descriptor.
for
crName
:=
range
cr
.
Attributes
{
found
:=
false
for
_
,
ad
:=
range
credtype
.
Attributes
{
if
ad
.
ID
==
crName
{
found
=
true
break
}
}
if
!
found
{
return
nil
,
errors
.
New
(
"Unknown CR attribute"
)
}
}
attrs
:=
make
([]
*
big
.
Int
,
len
(
credtype
.
Attributes
)
+
1
)
attrs
[
0
]
=
meta
.
Int
for
i
,
attrtype
:=
range
credtype
.
Attributes
{
attrs
[
i
+
1
]
=
new
(
big
.
Int
)
if
str
,
present
:=
cr
.
Attributes
[
attrtype
.
ID
];
present
{
attrs
[
i
+
1
]
=
new
(
big
.
Int
)
.
SetBytes
([]
byte
(
str
))
attrs
[
i
+
1
]
.
SetBytes
([]
byte
(
str
))
}
else
{
return
nil
,
errors
.
New
(
"Unknown attribute"
)
if
(
attrtype
.
Optional
!=
"true"
)
{
return
nil
,
errors
.
New
(
"Required attribute not provided"
)
}
}
}
...
...
testdata/irma_configuration/irma-demo/MijnOverheid/Issues/fullName/description.xml
0 → 100644
View file @
1a5b4d62
<IssueSpecification
version=
"4"
>
<Name>
<en>
Name
</en>
<nl>
Naam
</nl>
</Name>
<ShortName>
<en>
Name
</en>
<nl>
Naam
</nl>
</ShortName>
<SchemeManager>
irma-demo
</SchemeManager>
<IssuerID>
MijnOverheid
</IssuerID>
<CredentialID>
fullName
</CredentialID>
<Description>
<en>
Your full name, as it is known to the government
</en>
<nl>
Uw volledige naam, zoals bekend bij de overheid
</nl>
</Description>
<ShouldBeSingleton>
true
</ShouldBeSingleton>
<Attributes>
<Attribute
id=
"firstnames"
>
<Name>
<en>
First names
</en>
<nl>
Voornamen
</nl>
</Name>
<Description>
<en>
All of your first names
</en>
<nl>
Al uw voornamen
</nl>
</Description>
</Attribute>
<Attribute
id=
"firstname"
>
<Name>
<en>
First name
</en>
<nl>
Voornaam
</nl>
</Name>
<Description>
<en>
Your first name
</en>
<nl>
Uw voornaam
</nl>
</Description>
</Attribute>
<Attribute
id=
"familyname"
>
<Name>
<en>
Family name
</en>
<nl>
Achternaam
</nl>
</Name>
<Description>
<en>
Your family name
</en>
<nl>
Uw achternaam
</nl>
</Description>
</Attribute>
<Attribute
id=
"prefix"
optional=
"true"
>
<Name>
<en>
Prefix
</en>
<nl>
Tussenvoegsel
</nl>
</Name>
<Description>
<en>
Family name prefix
</en>
<nl>
Tussenvoegsel van uw achternaam
</nl>
</Description>
</Attribute>
</Attributes>
</IssueSpecification>
testdata/irma_configuration/irma-demo/index
View file @
1a5b4d62
230ce9f61beca5f52a6a241592c290baff9bae1066385e4b9bcf3a030f4a3b47 irma-demo/MijnOverheid/Issues/fullName/description.xml
5cef2de223075ea192407d66de274f8bc7104ab3537b455df14aca306b4809f7 irma-demo/MijnOverheid/Issues/root/description.xml
3571e30777cdf5b97acbb0820f1b69983d2dc2b6bae91c8fb67cfc79ef4e2543 irma-demo/MijnOverheid/PublicKeys/0.xml
115bd71b738cd2ba10e832559fc5d35ee8222f4049a0fc10fc18d0853c4aa4d9 irma-demo/MijnOverheid/PublicKeys/1.xml
...
...
testdata/irma_configuration/irma-demo/index.sig
View file @
1a5b4d62
No preview for this file type
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