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

Add new map to irma.Configuration for attribute types


Co-authored-by: Tomas's avatarConfiks <confiks@scriptbase.org>
parent 6ad21f06
......@@ -104,7 +104,7 @@ func (al *AttributeList) Map(conf *Configuration) map[AttributeTypeIdentifier]Tr
strings := al.Strings()
ct := conf.CredentialTypes[ctid]
for i := range ct.Attributes {
attrid := ct.Attributes[i].GetAttributeTypeIdentifier(ctid)
attrid := ct.Attributes[i].GetAttributeTypeIdentifier()
al.attrMap[attrid] = strings[i]
}
}
......@@ -166,7 +166,7 @@ func (al *AttributeList) UntranslatedAttribute(identifier AttributeTypeIdentifie
return nil
}
// Attribute returns the content of the specified attribute, or "" if not present in this attribute list.
// Attribute returns the content of the specified attribute, or nil if not present in this attribute list.
func (al *AttributeList) Attribute(identifier AttributeTypeIdentifier) TranslatedString {
if al.CredentialType().Identifier() != identifier.CredentialTypeIdentifier() {
return nil
......
......@@ -55,9 +55,9 @@ type CredentialType struct {
SchemeManagerID string `xml:"SchemeManager"`
IsSingleton bool `xml:"ShouldBeSingleton"`
Description TranslatedString
Attributes []AttributeType `xml:"Attributes>Attribute"`
XMLVersion int `xml:"version,attr"`
XMLName xml.Name `xml:"IssueSpecification"`
Attributes []*AttributeType `xml:"Attributes>Attribute" json:"-"`
XMLVersion int `xml:"version,attr"`
XMLName xml.Name `xml:"IssueSpecification"`
Valid bool `xml:"-"`
}
......@@ -66,13 +66,20 @@ type CredentialType struct {
type AttributeType struct {
ID string `xml:"id,attr"`
Optional string `xml:"optional,attr" json:",omitempty"`
Index *int `xml:"index,attr" json:",omitempty"`
Name TranslatedString
Description TranslatedString
Index int `xml:"-"`
DisplayIndex *int `xml:"displayIndex,attr" json:",omitempty"`
// Taken from containing CredentialType
CredentialTypeID string `xml:"-"`
IssuerID string `xml:"-"`
SchemeManagerID string `xml:"-"`
}
func (ad AttributeType) GetAttributeTypeIdentifier(cred CredentialTypeIdentifier) AttributeTypeIdentifier {
return NewAttributeTypeIdentifier(cred.String() + "." + ad.ID)
func (ad AttributeType) GetAttributeTypeIdentifier() AttributeTypeIdentifier {
return NewAttributeTypeIdentifier(fmt.Sprintf("%s.%s.%s.%s", ad.SchemeManagerID, ad.IssuerID, ad.CredentialTypeID, ad.ID))
}
func (ad AttributeType) IsOptional() bool {
......@@ -112,7 +119,7 @@ func (ct CredentialType) AttributeType(ai AttributeTypeIdentifier) *AttributeTyp
if i == -1 {
return nil
}
return &ct.Attributes[i]
return ct.Attributes[i]
}
// TranslatedString is a map of translated strings.
......
......@@ -40,6 +40,7 @@ type Configuration struct {
SchemeManagers map[SchemeManagerIdentifier]*SchemeManager
Issuers map[IssuerIdentifier]*Issuer
CredentialTypes map[CredentialTypeIdentifier]*CredentialType
Attributes map[AttributeTypeIdentifier]*AttributeType
// Path to the irma_configuration folder that this instance represents
Path string
......@@ -115,6 +116,7 @@ func (conf *Configuration) clear() {
conf.SchemeManagers = make(map[SchemeManagerIdentifier]*SchemeManager)
conf.Issuers = make(map[IssuerIdentifier]*Issuer)
conf.CredentialTypes = make(map[CredentialTypeIdentifier]*CredentialType)
conf.Attributes = make(map[AttributeTypeIdentifier]*AttributeType)
conf.DisabledSchemeManagers = make(map[SchemeManagerIdentifier]*SchemeManagerError)
conf.publicKeys = make(map[IssuerIdentifier]map[int]*gabi.PublicKey)
conf.reverseHashes = make(map[string]CredentialTypeIdentifier)
......@@ -429,6 +431,13 @@ func (conf *Configuration) parseCredentialsFolder(manager *SchemeManager, issuer
credid := cred.Identifier()
conf.CredentialTypes[credid] = cred
conf.addReverseHash(credid)
for index, attr := range cred.Attributes {
attr.Index = index
attr.SchemeManagerID = cred.SchemeManagerID
attr.IssuerID = cred.IssuerID
attr.CredentialTypeID = cred.ID
conf.Attributes[attr.GetAttributeTypeIdentifier()] = attr
}
return nil
})
if !foundcred {
......@@ -1047,16 +1056,16 @@ func (conf *Configuration) checkAttributes(cred *CredentialType) error {
for i, attr := range cred.Attributes {
conf.checkTranslations(fmt.Sprintf("Attribute %s of credential type %s", attr.ID, cred.Identifier().String()), attr)
index := i
if attr.Index != nil {
index = *attr.Index
if attr.DisplayIndex != nil {
index = *attr.DisplayIndex
}
if index >= count {
conf.Warnings = append(conf.Warnings, fmt.Sprintf("Credential type %s has invalid attribute index at attribute %d", name, i))
conf.Warnings = append(conf.Warnings, fmt.Sprintf("Credential type %s has invalid attribute displayIndex at attribute %d", name, i))
}
indices[index] = struct{}{}
}
if len(indices) != count {
conf.Warnings = append(conf.Warnings, fmt.Sprintf("Credential type %s has invalid attribute ordering, check the index-tags", name))
conf.Warnings = append(conf.Warnings, fmt.Sprintf("Credential type %s has invalid attribute ordering, check the displayIndex tags", name))
}
return nil
}
......
......@@ -162,7 +162,7 @@ func NewDisclosedCredentialFromADisclosed(aDisclosed map[int]*big.Int, configura
continue
}
id := cred.Attributes[k-2].GetAttributeTypeIdentifier(cred.Identifier())
id := cred.Attributes[k-2].GetAttributeTypeIdentifier()
attributeValue := decodeAttribute(v, metadata.Version())
rawAttributes[id] = attributeValue
attributes[id] = translateAttribute(attributeValue)
......
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