credential.go 1.04 KB
Newer Older
1
2
3
package irmaclient

import (
4
	"github.com/privacybydesign/irmago"
5
6
7
8
9
10
11
	"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
	cred := &credential{
		Credential:        gabicred,
		MetadataAttribute: meta,
	}
22
23
24
25
26
27

	if cred.CredentialType() == nil {
		// Unknown credtype, populate Pk field later
		return cred, nil
	}

28
	var err error
29
	cred.Pk, err = conf.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
30
31
32
33
34
35
	if err != nil {
		return nil, err
	}
	return cred, nil
}

36
func (cred *credential) AttributeList() *irma.AttributeList {
37
	if cred.attrs == nil {
38
		cred.attrs = irma.NewAttributeListFromInts(cred.Credential.Attributes[1:], cred.MetadataAttribute.Conf)
39
40
41
	}
	return cred.attrs
}