credential.go 950 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
package irmaclient

import (
	"github.com/credentials/irmago"
	"github.com/mhe/gabi"
)

// 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
12
13
	*irma.MetadataAttribute
	attrs *irma.AttributeList
14
15
}

16
17
func newCredential(gabicred *gabi.Credential, conf *irma.Configuration) (*credential, error) {
	meta := irma.MetadataFromInt(gabicred.Attributes[1], conf)
18
19
20
21
22
	cred := &credential{
		Credential:        gabicred,
		MetadataAttribute: meta,
	}
	var err error
23
	cred.Pk, err = conf.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
24
25
26
27
28
29
	if err != nil {
		return nil, err
	}
	return cred, nil
}

30
func (cred *credential) AttributeList() *irma.AttributeList {
31
	if cred.attrs == nil {
32
		cred.attrs = irma.NewAttributeListFromInts(cred.Credential.Attributes[1:], cred.MetadataAttribute.Conf)
33
34
35
	}
	return cred.attrs
}