Commit 1a5b4d62 authored by Ayke van Laethem's avatar Ayke van Laethem
Browse files

Add support for optional attributes

parent c10536c1
......@@ -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
}
......
......@@ -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())
......
......@@ -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")
}
}
}
......
<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>
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
......
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