Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
aadcf3c5
Commit
aadcf3c5
authored
Jul 26, 2017
by
Sietse Ringers
Browse files
Rename CredentialIdentifier -> CredentialTypeIdentifier
parent
3a6e8e88
Changes
7
Hide whitespace changes
Inline
Side-by-side
attributes.go
View file @
aadcf3c5
...
...
@@ -154,7 +154,7 @@ func (attr *MetadataAttribute) CredentialType() *CredentialType {
return
MetaStore
.
hashToCredentialType
(
attr
.
field
(
credentialID
))
}
func
(
attr
*
MetadataAttribute
)
setCredentialIdentifier
(
id
string
)
{
func
(
attr
*
MetadataAttribute
)
setCredential
Type
Identifier
(
id
string
)
{
bytes
:=
sha256
.
Sum256
([]
byte
(
id
))
attr
.
setField
(
credentialID
,
bytes
[
:
16
])
}
...
...
descriptions.go
View file @
aadcf3c5
...
...
@@ -48,7 +48,7 @@ type CredentialType struct {
// ContainsAttribute tests whether the specified attribute is contained in this
// credentialtype.
func
(
ct
*
CredentialType
)
ContainsAttribute
(
ai
AttributeIdentifier
)
bool
{
if
ai
.
CredentialIdentifier
()
.
String
()
!=
ct
.
Identifier
()
.
String
()
{
if
ai
.
Credential
Type
Identifier
()
.
String
()
!=
ct
.
Identifier
()
.
String
()
{
return
false
}
for
_
,
desc
:=
range
ct
.
Attributes
{
...
...
@@ -106,8 +106,8 @@ func (ts *TranslatedString) Translation(lang string) string {
}
// Identifier returns the identifier of the specified credential type.
func
(
ct
*
CredentialType
)
Identifier
()
CredentialIdentifier
{
return
NewCredentialIdentifier
(
ct
.
SchemeManagerID
+
"."
+
ct
.
IssuerID
+
"."
+
ct
.
ID
)
func
(
ct
*
CredentialType
)
Identifier
()
Credential
Type
Identifier
{
return
NewCredential
Type
Identifier
(
ct
.
SchemeManagerID
+
"."
+
ct
.
IssuerID
+
"."
+
ct
.
ID
)
}
// IssuerIdentifier returns the issuer identifier of the specified credential type.
...
...
identifiers.go
View file @
aadcf3c5
...
...
@@ -14,8 +14,8 @@ type IssuerIdentifier struct {
objectIdentifier
}
// CredentialIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type
CredentialIdentifier
struct
{
// Credential
Type
Identifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type
Credential
Type
Identifier
struct
{
objectIdentifier
}
...
...
@@ -48,9 +48,9 @@ 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
)}
// NewCredential
Type
Identifier converts the specified identifier to a Credential
Type
Identifier.
func
NewCredential
Type
Identifier
(
id
string
)
Credential
Type
Identifier
{
return
Credential
Type
Identifier
{
objectIdentifier
(
id
)}
}
// NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier.
...
...
@@ -64,11 +64,11 @@ func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier {
}
// IssuerIdentifier returns the IssuerIdentifier of the credential identifier.
func
(
id
CredentialIdentifier
)
IssuerIdentifier
()
IssuerIdentifier
{
func
(
id
Credential
Type
Identifier
)
IssuerIdentifier
()
IssuerIdentifier
{
return
NewIssuerIdentifier
(
id
.
Parent
())
}
// CredentialIdentifier returns the CredentialIdentifier of the attribute identifier.
func
(
id
AttributeIdentifier
)
CredentialIdentifier
()
CredentialIdentifier
{
return
NewCredentialIdentifier
(
id
.
Parent
())
// Credential
Type
Identifier returns the Credential
Type
Identifier of the attribute identifier.
func
(
id
AttributeIdentifier
)
Credential
Type
Identifier
()
Credential
Type
Identifier
{
return
NewCredential
Type
Identifier
(
id
.
Parent
())
}
irmago_test.go
View file @
aadcf3c5
...
...
@@ -55,7 +55,7 @@ func parseAndroidStorage(t *testing.T) {
}
func
verifyStoreIsUnmarshaled
(
t
*
testing
.
T
)
{
cred
,
err
:=
Manager
.
Credential
(
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
),
0
)
cred
,
err
:=
Manager
.
Credential
(
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
),
0
)
assert
.
NoError
(
t
,
err
,
"could not fetch credential"
)
assert
.
NotNil
(
t
,
cred
,
"Credential should exist"
)
assert
.
NotNil
(
t
,
cred
.
Attributes
[
0
],
"Metadata attribute of irma-demo.RU.studentCard should not be nil"
)
...
...
@@ -102,12 +102,12 @@ func TestParseStore(t *testing.T) {
"irma-demo.RU issuer has unexpected name"
)
assert
.
Equal
(
t
,
"Student Card"
,
MetaStore
.
Credentials
[
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
.
Translation
(
"en"
),
MetaStore
.
Credentials
[
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
.
Translation
(
"en"
),
"irma-demo.RU.studentCard has unexpected name"
)
assert
.
Equal
(
t
,
"studentID"
,
MetaStore
.
Credentials
[
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
)]
.
Attributes
[
2
]
.
ID
,
MetaStore
.
Credentials
[
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
)]
.
Attributes
[
2
]
.
ID
,
"irma-demo.RU.studentCard.studentID has unexpected name"
)
// Hash algorithm pseudocode:
...
...
@@ -144,7 +144,7 @@ func TestMetadataCompatibility(t *testing.T) {
assert
.
NotNil
(
t
,
attr
.
CredentialType
(),
"attr.CredentialType() should not be nil"
)
assert
.
Equal
(
t
,
NewCredentialIdentifier
(
"irma-demo.RU.studentCard"
),
NewCredential
Type
Identifier
(
"irma-demo.RU.studentCard"
),
attr
.
CredentialType
()
.
Identifier
(),
"Metadata credential type was not irma-demo.RU.studentCard"
,
)
...
...
manager.go
View file @
aadcf3c5
...
...
@@ -18,13 +18,13 @@ var Manager = newCredentialManager()
type
CredentialManager
struct
{
secretkey
*
big
.
Int
storagePath
string
attributes
map
[
CredentialIdentifier
][]
*
AttributeList
credentials
map
[
CredentialIdentifier
]
map
[
int
]
*
Credential
attributes
map
[
Credential
Type
Identifier
][]
*
AttributeList
credentials
map
[
Credential
Type
Identifier
]
map
[
int
]
*
Credential
}
func
newCredentialManager
()
*
CredentialManager
{
return
&
CredentialManager
{
credentials
:
make
(
map
[
CredentialIdentifier
]
map
[
int
]
*
Credential
),
credentials
:
make
(
map
[
Credential
Type
Identifier
]
map
[
int
]
*
Credential
),
}
}
...
...
@@ -50,7 +50,7 @@ func (cm *CredentialManager) Init(path string) (err error) {
}
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
func
(
cm
*
CredentialManager
)
attrs
(
id
CredentialIdentifier
)
[]
*
AttributeList
{
func
(
cm
*
CredentialManager
)
attrs
(
id
Credential
Type
Identifier
)
[]
*
AttributeList
{
list
,
exists
:=
cm
.
attributes
[
id
]
if
!
exists
{
list
=
make
([]
*
AttributeList
,
0
,
1
)
...
...
@@ -60,7 +60,7 @@ func (cm *CredentialManager) attrs(id CredentialIdentifier) []*AttributeList {
}
// creds returns cm.credentials[id], initializing it to an empty map if neccesary
func
(
cm
*
CredentialManager
)
creds
(
id
CredentialIdentifier
)
map
[
int
]
*
Credential
{
func
(
cm
*
CredentialManager
)
creds
(
id
Credential
Type
Identifier
)
map
[
int
]
*
Credential
{
list
,
exists
:=
cm
.
credentials
[
id
]
if
!
exists
{
list
=
make
(
map
[
int
]
*
Credential
)
...
...
@@ -70,7 +70,7 @@ func (cm *CredentialManager) creds(id CredentialIdentifier) map[int]*Credential
}
// Attributes returns the attribute list of the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Attributes
(
id
CredentialIdentifier
,
counter
int
)
(
attributes
*
AttributeList
)
{
func
(
cm
*
CredentialManager
)
Attributes
(
id
Credential
Type
Identifier
,
counter
int
)
(
attributes
*
AttributeList
)
{
list
:=
cm
.
attrs
(
id
)
if
len
(
list
)
<=
counter
{
return
...
...
@@ -79,7 +79,7 @@ func (cm *CredentialManager) Attributes(id CredentialIdentifier, counter int) (a
}
// Credential returns the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Credential
(
id
CredentialIdentifier
,
counter
int
)
(
cred
*
Credential
,
err
error
)
{
func
(
cm
*
CredentialManager
)
Credential
(
id
Credential
Type
Identifier
,
counter
int
)
(
cred
*
Credential
,
err
error
)
{
// If the requested credential is not in credential map, we check if its attributes were
// deserialized during Init(). If so, there should be a corresponding signature file,
// so we read that, construct the credential, and add it to the credential map
...
...
storage.go
View file @
aadcf3c5
...
...
@@ -112,7 +112,7 @@ func (cm *CredentialManager) storeSignature(cred *Credential, counter int) (err
}
func
(
cm
*
CredentialManager
)
storeAttributes
()
(
err
error
)
{
// Unfortunately, the type of cm.attributes (map[CredentialIdentifier][]*AttributeList)
// Unfortunately, the type of cm.attributes (map[Credential
Type
Identifier][]*AttributeList)
// cannot be passed directly to json.Marshal(), so we copy it into a temp list.
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
for
credid
,
list
:=
range
cm
.
attributes
{
...
...
@@ -128,7 +128,7 @@ func (cm *CredentialManager) storeAttributes() (err error) {
return
}
func
(
cm
*
CredentialManager
)
loadSignature
(
id
CredentialIdentifier
,
counter
int
)
(
signature
*
gabi
.
CLSignature
,
err
error
)
{
func
(
cm
*
CredentialManager
)
loadSignature
(
id
Credential
Type
Identifier
,
counter
int
)
(
signature
*
gabi
.
CLSignature
,
err
error
)
{
path
:=
cm
.
signatureFilename
(
id
.
String
(),
counter
)
exists
,
err
:=
pathExists
(
path
)
if
err
!=
nil
||
!
exists
{
...
...
@@ -166,8 +166,8 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) {
return
sk
,
nil
}
func
(
cm
*
CredentialManager
)
loadAttributes
()
(
list
map
[
CredentialIdentifier
][]
*
AttributeList
,
err
error
)
{
list
=
make
(
map
[
CredentialIdentifier
][]
*
AttributeList
)
func
(
cm
*
CredentialManager
)
loadAttributes
()
(
list
map
[
Credential
Type
Identifier
][]
*
AttributeList
,
err
error
)
{
list
=
make
(
map
[
Credential
Type
Identifier
][]
*
AttributeList
)
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
exists
,
err
:=
pathExists
(
cm
.
path
(
attributesFile
))
...
...
@@ -185,7 +185,7 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]*
}
for
credid
,
attrs
:=
range
temp
{
list
[
NewCredentialIdentifier
(
credid
)]
=
attrs
list
[
NewCredential
Type
Identifier
(
credid
)]
=
attrs
}
return
list
,
nil
}
store.go
View file @
aadcf3c5
...
...
@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore()
type
ConfigurationStore
struct
{
SchemeManagers
map
[
SchemeManagerIdentifier
]
*
SchemeManager
Issuers
map
[
IssuerIdentifier
]
*
Issuer
Credentials
map
[
CredentialIdentifier
]
*
CredentialType
Credentials
map
[
Credential
Type
Identifier
]
*
CredentialType
PublicKeys
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
reverseHashes
map
[
string
]
CredentialIdentifier
reverseHashes
map
[
string
]
Credential
Type
Identifier
initialized
bool
}
...
...
@@ -31,9 +31,9 @@ func newConfigurationStore() (store *ConfigurationStore) {
store
=
&
ConfigurationStore
{
SchemeManagers
:
make
(
map
[
SchemeManagerIdentifier
]
*
SchemeManager
),
Issuers
:
make
(
map
[
IssuerIdentifier
]
*
Issuer
),
Credentials
:
make
(
map
[
CredentialIdentifier
]
*
CredentialType
),
Credentials
:
make
(
map
[
Credential
Type
Identifier
]
*
CredentialType
),
PublicKeys
:
make
(
map
[
IssuerIdentifier
][]
*
gabi
.
PublicKey
),
reverseHashes
:
make
(
map
[
string
]
CredentialIdentifier
),
reverseHashes
:
make
(
map
[
string
]
Credential
Type
Identifier
),
}
return
}
...
...
@@ -48,7 +48,7 @@ func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *ga
return
nil
}
func
(
store
*
ConfigurationStore
)
addReverseHash
(
credid
CredentialIdentifier
)
{
func
(
store
*
ConfigurationStore
)
addReverseHash
(
credid
Credential
Type
Identifier
)
{
hash
:=
sha256
.
Sum256
([]
byte
(
credid
.
String
()))
store
.
reverseHashes
[
base64
.
StdEncoding
.
EncodeToString
(
hash
[
:
16
])]
=
credid
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment