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

Fix empty Manager.CredentialList() after Init()

parent be6b9198
......@@ -44,16 +44,50 @@ type MetadataAttribute struct {
// AttributeList contains attributes, excluding the secret key,
// providing convenient access to the metadata attribute.
type AttributeList struct {
*MetadataAttribute `json:"-"`
Ints []*big.Int
strings []string
*MetadataAttribute `json:"-"`
info *Credential
}
func (al *AttributeList) MarshalJSON() ([]byte, error) {
return json.Marshal(al.Ints)
}
func (al *AttributeList) UnmarshalJSON(bytes []byte) error {
ints := []*big.Int{}
if err := json.Unmarshal(bytes, &ints); err != nil {
return err
}
*al = *NewAttributeListFromInts(ints)
return nil
}
// NewAttributeListFromInts initializes a new AttributeList from a list of bigints.
func NewAttributeListFromInts(ints []*big.Int) *AttributeList {
meta := MetadataFromInt(ints[0])
credtype := meta.CredentialType()
issid := credtype.IssuerIdentifier()
attrs := make([]TranslatedString, len(credtype.Attributes))
for i := range credtype.Attributes {
val := string(ints[i+1].Bytes())
attrs[i] = TranslatedString(map[string]string{"en": val, "nl": val})
}
return &AttributeList{
Ints: ints,
MetadataAttribute: MetadataFromInt(ints[0]),
MetadataAttribute: meta,
info: &Credential{
ID: credtype.Identifier().String(),
SignedOn: Timestamp(meta.SigningDate()),
Expires: Timestamp(meta.Expiry()),
Type: credtype,
Issuer: MetaStore.Issuers[issid],
SchemeManager: MetaStore.SchemeManagers[issid.SchemeManagerIdentifier()],
Attributes: attrs,
Logo: "", // TODO
},
}
}
......
......@@ -11,8 +11,6 @@ import (
type credential struct {
*gabi.Credential
*MetadataAttribute
info *Credential
}
// A Credential contains all information of an IRMA credential.
......@@ -32,31 +30,11 @@ type CredentialList []*Credential
func newCredential(gabicred *gabi.Credential) (cred *credential) {
meta := MetadataFromInt(gabicred.Attributes[1])
credtype := meta.CredentialType()
issid := credtype.IssuerIdentifier()
attrs := make([]TranslatedString, len(credtype.Attributes))
for i := range credtype.Attributes {
val := string(gabicred.Attributes[i+2].Bytes())
attrs[i] = TranslatedString(map[string]string{"en": val, "nl": val})
}
cred = &credential{
Credential: gabicred,
MetadataAttribute: meta,
info: &Credential{
ID: credtype.Identifier().String(),
SignedOn: Timestamp(meta.SigningDate()),
Expires: Timestamp(meta.Expiry()),
Type: credtype,
Issuer: MetaStore.Issuers[issid],
SchemeManager: MetaStore.SchemeManagers[issid.SchemeManagerIdentifier()],
Attributes: attrs,
Logo: "", // TODO
},
}
cred.Pk = MetaStore.PublicKey(issid, cred.KeyCounter())
cred.Pk = MetaStore.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
return
}
......
......@@ -68,6 +68,8 @@ func verifyStoreIsUnmarshaled(t *testing.T) {
assert.NotNil(t, cred, "Credential should exist")
assert.NotNil(t, cred.Attributes[0], "Metadata attribute of irma-demo.RU.studentCard should not be nil")
assert.NotEmpty(t, Manager.CredentialList())
assert.True(t,
cred.Signature.Verify(cred.PublicKey(), cred.Attributes),
"Credential should be valid",
......
......@@ -36,11 +36,13 @@ func newCredentialManager() *CredentialManager {
// CredentialList returns a list of information of all contained credentials.
func (cm *CredentialManager) CredentialList() CredentialList {
list := CredentialList([]*Credential{})
for _, credlist := range cm.credentials {
for _, cred := range credlist {
list = append(list, cred.info)
for _, attrlistlist := range cm.attributes {
for _, attrlist := range attrlistlist {
list = append(list, attrlist.info)
}
}
sort.Sort(list)
return list
}
......
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