Commit 658c3375 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Make CredentialInfo.Attributes a map


Co-authored-by: Tomas's avatarConfiks <confiks@scriptbase.org>
parent bde25dff
......@@ -65,6 +65,7 @@ type AttributeList struct {
*MetadataAttribute `json:"-"`
Ints []*big.Int
strings []TranslatedString
attrMap map[AttributeTypeIdentifier]TranslatedString
info *CredentialInfo
h string
}
......@@ -96,6 +97,20 @@ func (al *AttributeList) Hash() string {
return al.h
}
func (al *AttributeList) Map(conf *Configuration) map[AttributeTypeIdentifier]TranslatedString {
if al.attrMap == nil {
al.attrMap = make(map[AttributeTypeIdentifier]TranslatedString)
ctid := al.CredentialType().Identifier()
strings := al.Strings()
ct := conf.CredentialTypes[ctid]
for i := range ct.Attributes {
attrid := ct.Attributes[i].GetAttributeTypeIdentifier(ctid)
al.attrMap[attrid] = strings[i]
}
}
return al.attrMap
}
// Strings converts the current instance to human-readable strings.
func (al *AttributeList) Strings() []TranslatedString {
if al.strings == nil {
......
......@@ -8,16 +8,16 @@ import (
// CredentialInfo contains all information of an IRMA credential.
type CredentialInfo struct {
ID string // e.g., "studentCard"
CredentialTypeID CredentialTypeIdentifier // e.g., "irma-demo.RU.studentCard"
IssuerID IssuerIdentifier // e.g., "irma-demo.RU"
SchemeManagerID SchemeManagerIdentifier // e.g., "irma-demo"
Index int // This is the Index-th credential instance of this type
SignedOn Timestamp // Unix timestamp
Expires Timestamp // Unix timestamp
Attributes []TranslatedString // Human-readable rendered attributes
Logo string // Path to logo on storage
Hash string // SHA256 hash over the attributes
ID string // e.g., "studentCard"
CredentialTypeID CredentialTypeIdentifier // e.g., "irma-demo.RU.studentCard"
IssuerID IssuerIdentifier // e.g., "irma-demo.RU"
SchemeManagerID SchemeManagerIdentifier // e.g., "irma-demo"
Index int // This is the Index-th credential instance of this type
SignedOn Timestamp // Unix timestamp
Expires Timestamp // Unix timestamp
Attributes map[AttributeTypeIdentifier]TranslatedString // Human-readable rendered attributes
Logo string // Path to logo on storage
Hash string // SHA256 hash over the attributes
}
// A CredentialInfoList is a list of credentials (implements sort.Interface).
......@@ -40,7 +40,7 @@ func NewCredentialInfo(ints []*big.Int, conf *Configuration) *CredentialInfo {
SchemeManagerID: issid.SchemeManagerIdentifier(),
SignedOn: Timestamp(meta.SigningDate()),
Expires: Timestamp(meta.Expiry()),
Attributes: attrs.Strings(),
Attributes: attrs.Map(conf),
Logo: credtype.Logo(conf),
Hash: attrs.Hash(),
}
......
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