credential.go 1.72 KB
Newer Older
1
2
package irmago

Sietse Ringers's avatar
Sietse Ringers committed
3
4
5
6
7
import (
	"strings"

	"github.com/mhe/gabi"
)
8

Sietse Ringers's avatar
Sietse Ringers committed
9
// credential represents an IRMA credential, whose zeroth attribute
10
// is always the secret key and the first attribute the metadata attribute.
Sietse Ringers's avatar
Sietse Ringers committed
11
type credential struct {
12
13
	*gabi.Credential
	*MetadataAttribute
Sietse Ringers's avatar
Sietse Ringers committed
14
15
16
17
18
19
20
21
22
23
24
25
}

// A Credential contains all information of an IRMA credential.
type Credential struct {
	ID            string             // e.g., "irma-demo.RU.studentCard"
	SignedOn      Timestamp          // Unix timestamp
	Expires       Timestamp          // Unix timestamp
	Type          *CredentialType    // Credential information from MetaStore
	Issuer        *Issuer            // Issuer information from MetaStore
	SchemeManager *SchemeManager     // Scheme manager information from MetaStore
	Attributes    []TranslatedString // Human-readable rendered attributes
	Logo          string             // Path to logo on storage
26
27
}

Sietse Ringers's avatar
Sietse Ringers committed
28
29
30
// A CredentialList is a list of credentials (implements sort.Interface).
type CredentialList []*Credential

Sietse Ringers's avatar
Sietse Ringers committed
31
func newCredential(gabicred *gabi.Credential) (cred *credential) {
Sietse Ringers's avatar
Sietse Ringers committed
32
33
34
35
36
	meta := MetadataFromInt(gabicred.Attributes[1])
	cred = &credential{
		Credential:        gabicred,
		MetadataAttribute: meta,
	}
37
	cred.Pk = MetaStore.PublicKey(meta.CredentialType().IssuerIdentifier(), cred.KeyCounter())
38
39
	return
}
Sietse Ringers's avatar
Sietse Ringers committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

// Len implements sort.Interface.
func (cl CredentialList) Len() int {
	return len(cl)
}

// Swap implements sort.Interface.
func (cl CredentialList) Swap(i, j int) {
	cl[i], cl[j] = cl[j], cl[i]
}

// Less implements sort.Interface.
func (cl CredentialList) Less(i, j int) bool {
	// TODO Decide on sorting, and if it depends on a TranslatedString, allow language choosing
	return strings.Compare(cl[i].Type.Name["en"], cl[j].Type.Name["en"]) > 0
}