forked from privacybydesign/irmago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential.go
41 lines (35 loc) · 1.05 KB
/
credential.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package irmaclient
import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/irmago"
)
// credential represents an IRMA credential, whose zeroth attribute
// is always the secret key and the first attribute the metadata attribute.
type credential struct {
*gabi.Credential
*irma.MetadataAttribute
attrs *irma.AttributeList
}
func newCredential(gabicred *gabi.Credential, conf *irma.Configuration) (*credential, error) {
meta := irma.MetadataFromInt(gabicred.Attributes[1], conf)
cred := &credential{
Credential: gabicred,
MetadataAttribute: meta,
}
if cred.CredentialType() == nil {
// Unknown credtype, populate Pk field later
return cred, nil
}
var err error
cred.Pk, err = conf.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
if err != nil {
return nil, err
}
return cred, nil
}
func (cred *credential) AttributeList() *irma.AttributeList {
if cred.attrs == nil {
cred.attrs = irma.NewAttributeListFromInts(cred.Credential.Attributes[1:], cred.MetadataAttribute.Conf)
}
return cred.attrs
}