identifiers.go 2.42 KB
Newer Older
1
2
3
4
package irmago

import "strings"

Sietse Ringers's avatar
Sietse Ringers committed
5
type metaObjectIdentifier string
6
7
8

// SchemeManagerIdentifier identifies a scheme manager. Equal to its ID. For example "irma-demo".
type SchemeManagerIdentifier struct {
Sietse Ringers's avatar
Sietse Ringers committed
9
	metaObjectIdentifier
10
11
12
13
}

// IssuerIdentifier identifies an inssuer. For example "irma-demo.RU".
type IssuerIdentifier struct {
Sietse Ringers's avatar
Sietse Ringers committed
14
	metaObjectIdentifier
15
16
}

17
18
// CredentialTypeIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialTypeIdentifier struct {
Sietse Ringers's avatar
Sietse Ringers committed
19
	metaObjectIdentifier
20
21
}

22
23
// AttributeTypeIdentifier identifies an attribute. For example "irma-demo.RU.studentCard.studentID".
type AttributeTypeIdentifier struct {
Sietse Ringers's avatar
Sietse Ringers committed
24
	metaObjectIdentifier
25
26
}

Sietse Ringers's avatar
Sietse Ringers committed
27
func (oi metaObjectIdentifier) Parent() string {
28
	str := string(oi)
Sietse Ringers's avatar
Sietse Ringers committed
29
	return str[:strings.LastIndex(str, ".")]
30
31
}

Sietse Ringers's avatar
Sietse Ringers committed
32
func (oi metaObjectIdentifier) Name() string {
33
	str := string(oi)
Sietse Ringers's avatar
Sietse Ringers committed
34
	return str[strings.LastIndex(str, ".")+1:]
35
36
}

Sietse Ringers's avatar
Sietse Ringers committed
37
func (oi metaObjectIdentifier) String() string {
38
39
40
41
42
	return string(oi)
}

// NewSchemeManagerIdentifier converts the specified identifier to a SchemeManagerIdentifier.
func NewSchemeManagerIdentifier(id string) SchemeManagerIdentifier {
Sietse Ringers's avatar
Sietse Ringers committed
43
	return SchemeManagerIdentifier{metaObjectIdentifier(id)}
44
45
46
47
}

// NewIssuerIdentifier converts the specified identifier to a IssuerIdentifier.
func NewIssuerIdentifier(id string) IssuerIdentifier {
Sietse Ringers's avatar
Sietse Ringers committed
48
	return IssuerIdentifier{metaObjectIdentifier(id)}
49
50
}

51
52
// NewCredentialTypeIdentifier converts the specified identifier to a CredentialTypeIdentifier.
func NewCredentialTypeIdentifier(id string) CredentialTypeIdentifier {
Sietse Ringers's avatar
Sietse Ringers committed
53
	return CredentialTypeIdentifier{metaObjectIdentifier(id)}
54
55
}

56
57
// NewAttributeTypeIdentifier converts the specified identifier to a AttributeTypeIdentifier.
func NewAttributeTypeIdentifier(id string) AttributeTypeIdentifier {
Sietse Ringers's avatar
Sietse Ringers committed
58
	return AttributeTypeIdentifier{metaObjectIdentifier(id)}
59
60
61
62
63
64
65
66
}

// SchemeManagerIdentifier returns the scheme manager identifer of the issuer.
func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier {
	return NewSchemeManagerIdentifier(id.Parent())
}

// IssuerIdentifier returns the IssuerIdentifier of the credential identifier.
67
func (id CredentialTypeIdentifier) IssuerIdentifier() IssuerIdentifier {
68
69
70
	return NewIssuerIdentifier(id.Parent())
}

71
// CredentialTypeIdentifier returns the CredentialTypeIdentifier of the attribute identifier.
72
func (id AttributeTypeIdentifier) CredentialTypeIdentifier() CredentialTypeIdentifier {
73
	return NewCredentialTypeIdentifier(id.Parent())
74
}