descriptions.go 3.24 KB
Newer Older
Sietse Ringers's avatar
Sietse Ringers committed
1
2
package irmago

3
4
5
6
7
import (
	"encoding/xml"

	"github.com/mhe/gabi"
)
Sietse Ringers's avatar
Sietse Ringers committed
8
9
10
11
12
13
14
15
16
17

// SchemeManagerDescription describes a scheme manager.
type SchemeManagerDescription struct {
	Name              string `xml:"Id"`
	URL               string `xml:"Contact"`
	HRName            string `xml:"Name"`
	Description       string
	KeyshareServer    string
	KeyshareWebsite   string
	KeyshareAttribute string
Sietse Ringers's avatar
Sietse Ringers committed
18
	XMLVersion        int      `xml:"version,attr"`
Sietse Ringers's avatar
Sietse Ringers committed
19
20
21
22
23
24
25
26
27
28
29
30
	XMLName           xml.Name `xml:"SchemeManager"`
}

// IssuerDescription describes an issuer.
type IssuerDescription struct {
	HRName            string `xml:"Name"`
	HRShortName       string `xml:"ShortName"`
	Name              string `xml:"ID"`
	SchemeManagerName string `xml:"SchemeManager"`
	ContactAddress    string
	ContactEMail      string
	URL               string `xml:"baseURL"`
Sietse Ringers's avatar
Sietse Ringers committed
31
	XMLVersion        int    `xml:"version,attr"`
Sietse Ringers's avatar
Sietse Ringers committed
32
33
34
35
36
37
38
39
40
41
42
43
	identifier        *IssuerIdentifier
}

// CredentialDescription is a description of a credential type, specifying (a.o.) its name, issuer, and attributes.
type CredentialDescription struct {
	HRName            string `xml:"Name"`
	HRShortName       string `xml:"ShortName"`
	IssuerName        string `xml:"IssuerID"`
	SchemeManagerName string `xml:"SchemeManager"`
	Name              string `xml:"CredentialID"`
	IsSingleton       bool   `xml:"ShouldBeSingleton"`
	Description       string
Sietse Ringers's avatar
Sietse Ringers committed
44
45
46
	Attributes        []AttributeDescription `xml:"Attributes>Attribute"`
	XMLVersion        int                    `xml:"version,attr"`
	XMLName           xml.Name               `xml:"IssueSpecification"`
Sietse Ringers's avatar
Sietse Ringers committed
47
48
49
	identifier        *CredentialTypeIdentifier
}

Sietse Ringers's avatar
Sietse Ringers committed
50
51
// AttributeDescription is a description of an attribute within a credential type.
type AttributeDescription struct {
Sietse Ringers's avatar
Sietse Ringers committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	Name        string
	Description string
}

// Identifier returns the identifier of the specified credential type.
func (cd *CredentialDescription) Identifier() *CredentialTypeIdentifier {
	if cd.identifier == nil {
		cd.identifier = NewCredentialTypeIdentifier(cd.SchemeManagerName + "." + cd.IssuerName + "." + cd.Name)
	}
	return cd.identifier
}

// Identifier returns the identifier of the specified issuer description.
func (id *IssuerDescription) Identifier() *IssuerIdentifier {
	if id.identifier == nil {
		id.identifier = NewIssuerIdentifier(id.SchemeManagerName + "." + id.Name)
	}
	return id.identifier
}
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

// CurrentPublicKey returns the latest known public key of the issuer identified by this instance.
func (id *IssuerDescription) CurrentPublicKey() *gabi.PublicKey {
	return id.Identifier().CurrentPublicKey()
}

// PublicKey returns the specified public key of the issuer identified by this instance.
func (id *IssuerDescription) PublicKey(index int) *gabi.PublicKey {
	return id.Identifier().PublicKey(index)
}

// CurrentPublicKey returns the latest known public key of the issuer identified by this instance.
func (i *IssuerIdentifier) CurrentPublicKey() *gabi.PublicKey {
	keys := MetaStore.publickeys[i.string]
	if keys == nil || len(keys) == 0 {
		return nil
	}
	return keys[len(keys)-1]
}

// PublicKey returns the specified public key of the issuer identified by this instance.
func (i *IssuerIdentifier) PublicKey(index int) *gabi.PublicKey {
	keys := MetaStore.publickeys[i.string]
	if keys == nil || index >= len(keys) {
		return nil
	}
	return keys[index]
}