credential.go 971 Bytes
Newer Older
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
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
	*irmago.MetadataAttribute
	attrs *irmago.AttributeList
}

func newCredential(gabicred *gabi.Credential, store *irmago.ConfigurationStore) (*credential, error) {
	meta := irmago.MetadataFromInt(gabicred.Attributes[1], store)
	cred := &credential{
		Credential:        gabicred,
		MetadataAttribute: meta,
	}
	var err error
	cred.Pk, err = store.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
	if err != nil {
		return nil, err
	}
	return cred, nil
}

func (cred *credential) AttributeList() *irmago.AttributeList {
	if cred.attrs == nil {
		cred.attrs = irmago.NewAttributeListFromInts(cred.Credential.Attributes[1:], cred.MetadataAttribute.Store)
	}
	return cred.attrs
}