identifiers.go 2.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
}

17
18
// CredentialTypeIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialTypeIdentifier struct {
19
20
21
	objectIdentifier
}

22
23
// AttributeTypeIdentifier identifies an attribute. For example "irma-demo.RU.studentCard.studentID".
type AttributeTypeIdentifier struct {
24
25
26
27
28
	objectIdentifier
}

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

func (oi objectIdentifier) Name() string {
	str := string(oi)
Sietse Ringers's avatar
Sietse Ringers committed
34
	return str[strings.LastIndex(str, ".")+1:]
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
}

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)}
}

51
52
53
// NewCredentialTypeIdentifier converts the specified identifier to a CredentialTypeIdentifier.
func NewCredentialTypeIdentifier(id string) CredentialTypeIdentifier {
	return CredentialTypeIdentifier{objectIdentifier(id)}
54
55
}

56
57
58
// NewAttributeTypeIdentifier converts the specified identifier to a AttributeTypeIdentifier.
func NewAttributeTypeIdentifier(id string) AttributeTypeIdentifier {
	return AttributeTypeIdentifier{objectIdentifier(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
}