identifiers.go 2.3 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package irmago

import "strings"

type objectIdentifier string

// SchemeManagerIdentifier identifies a scheme manager. Equal to its ID. For example "irma-demo".
type SchemeManagerIdentifier struct {
	objectIdentifier
}

// IssuerIdentifier identifies an inssuer. For example "irma-demo.RU".
type IssuerIdentifier struct {
	objectIdentifier
}

// CredentialIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialIdentifier struct {
	objectIdentifier
}

// AttributeIdentifier identifies an attribute. For example "irma-demo.RU.studentCard.studentID".
type AttributeIdentifier struct {
	objectIdentifier
}

func (oi objectIdentifier) Parent() string {
	str := string(oi)
	return str[:strings.LastIndex(str, "/")]
}

func (oi objectIdentifier) Name() string {
	str := string(oi)
	return str[strings.LastIndex(str, "/")+1:]
}

func (oi objectIdentifier) String() string {
	return string(oi)
}

// NewSchemeManagerIdentifier converts the specified identifier to a SchemeManagerIdentifier.
func NewSchemeManagerIdentifier(id string) SchemeManagerIdentifier {
	return SchemeManagerIdentifier{objectIdentifier(id)}
}

// NewIssuerIdentifier converts the specified identifier to a IssuerIdentifier.
func NewIssuerIdentifier(id string) IssuerIdentifier {
	return IssuerIdentifier{objectIdentifier(id)}
}

// NewCredentialIdentifier converts the specified identifier to a CredentialIdentifier.
func NewCredentialIdentifier(id string) CredentialIdentifier {
	return CredentialIdentifier{objectIdentifier(id)}
}

// NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier.
func NewAttributeIdentifier(id string) AttributeIdentifier {
	return AttributeIdentifier{objectIdentifier(id)}
}

// 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.
func (id CredentialIdentifier) IssuerIdentifier() IssuerIdentifier {
	return NewIssuerIdentifier(id.Parent())
}

// CredentialIdentifier returns the CredentialIdentifier of the attribute identifier.
func (id AttributeIdentifier) CredentialIdentifier() CredentialIdentifier {
	return NewCredentialIdentifier(id.Parent())
}