Commit aadcf3c5 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Rename CredentialIdentifier -> CredentialTypeIdentifier

parent 3a6e8e88
...@@ -154,7 +154,7 @@ func (attr *MetadataAttribute) CredentialType() *CredentialType { ...@@ -154,7 +154,7 @@ func (attr *MetadataAttribute) CredentialType() *CredentialType {
return MetaStore.hashToCredentialType(attr.field(credentialID)) return MetaStore.hashToCredentialType(attr.field(credentialID))
} }
func (attr *MetadataAttribute) setCredentialIdentifier(id string) { func (attr *MetadataAttribute) setCredentialTypeIdentifier(id string) {
bytes := sha256.Sum256([]byte(id)) bytes := sha256.Sum256([]byte(id))
attr.setField(credentialID, bytes[:16]) attr.setField(credentialID, bytes[:16])
} }
......
...@@ -48,7 +48,7 @@ type CredentialType struct { ...@@ -48,7 +48,7 @@ type CredentialType struct {
// ContainsAttribute tests whether the specified attribute is contained in this // ContainsAttribute tests whether the specified attribute is contained in this
// credentialtype. // credentialtype.
func (ct *CredentialType) ContainsAttribute(ai AttributeIdentifier) bool { func (ct *CredentialType) ContainsAttribute(ai AttributeIdentifier) bool {
if ai.CredentialIdentifier().String() != ct.Identifier().String() { if ai.CredentialTypeIdentifier().String() != ct.Identifier().String() {
return false return false
} }
for _, desc := range ct.Attributes { for _, desc := range ct.Attributes {
...@@ -106,8 +106,8 @@ func (ts *TranslatedString) Translation(lang string) string { ...@@ -106,8 +106,8 @@ func (ts *TranslatedString) Translation(lang string) string {
} }
// Identifier returns the identifier of the specified credential type. // Identifier returns the identifier of the specified credential type.
func (ct *CredentialType) Identifier() CredentialIdentifier { func (ct *CredentialType) Identifier() CredentialTypeIdentifier {
return NewCredentialIdentifier(ct.SchemeManagerID + "." + ct.IssuerID + "." + ct.ID) return NewCredentialTypeIdentifier(ct.SchemeManagerID + "." + ct.IssuerID + "." + ct.ID)
} }
// IssuerIdentifier returns the issuer identifier of the specified credential type. // IssuerIdentifier returns the issuer identifier of the specified credential type.
......
...@@ -14,8 +14,8 @@ type IssuerIdentifier struct { ...@@ -14,8 +14,8 @@ type IssuerIdentifier struct {
objectIdentifier objectIdentifier
} }
// CredentialIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard". // CredentialTypeIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialIdentifier struct { type CredentialTypeIdentifier struct {
objectIdentifier objectIdentifier
} }
...@@ -48,9 +48,9 @@ func NewIssuerIdentifier(id string) IssuerIdentifier { ...@@ -48,9 +48,9 @@ func NewIssuerIdentifier(id string) IssuerIdentifier {
return IssuerIdentifier{objectIdentifier(id)} return IssuerIdentifier{objectIdentifier(id)}
} }
// NewCredentialIdentifier converts the specified identifier to a CredentialIdentifier. // NewCredentialTypeIdentifier converts the specified identifier to a CredentialTypeIdentifier.
func NewCredentialIdentifier(id string) CredentialIdentifier { func NewCredentialTypeIdentifier(id string) CredentialTypeIdentifier {
return CredentialIdentifier{objectIdentifier(id)} return CredentialTypeIdentifier{objectIdentifier(id)}
} }
// NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier. // NewAttributeIdentifier converts the specified identifier to a AttributeIdentifier.
...@@ -64,11 +64,11 @@ func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier { ...@@ -64,11 +64,11 @@ func (id IssuerIdentifier) SchemeManagerIdentifier() SchemeManagerIdentifier {
} }
// IssuerIdentifier returns the IssuerIdentifier of the credential identifier. // IssuerIdentifier returns the IssuerIdentifier of the credential identifier.
func (id CredentialIdentifier) IssuerIdentifier() IssuerIdentifier { func (id CredentialTypeIdentifier) IssuerIdentifier() IssuerIdentifier {
return NewIssuerIdentifier(id.Parent()) return NewIssuerIdentifier(id.Parent())
} }
// CredentialIdentifier returns the CredentialIdentifier of the attribute identifier. // CredentialTypeIdentifier returns the CredentialTypeIdentifier of the attribute identifier.
func (id AttributeIdentifier) CredentialIdentifier() CredentialIdentifier { func (id AttributeIdentifier) CredentialTypeIdentifier() CredentialTypeIdentifier {
return NewCredentialIdentifier(id.Parent()) return NewCredentialTypeIdentifier(id.Parent())
} }
...@@ -55,7 +55,7 @@ func parseAndroidStorage(t *testing.T) { ...@@ -55,7 +55,7 @@ func parseAndroidStorage(t *testing.T) {
} }
func verifyStoreIsUnmarshaled(t *testing.T) { func verifyStoreIsUnmarshaled(t *testing.T) {
cred, err := Manager.Credential(NewCredentialIdentifier("irma-demo.RU.studentCard"), 0) cred, err := Manager.Credential(NewCredentialTypeIdentifier("irma-demo.RU.studentCard"), 0)
assert.NoError(t, err, "could not fetch credential") assert.NoError(t, err, "could not fetch credential")
assert.NotNil(t, cred, "Credential should exist") assert.NotNil(t, cred, "Credential should exist")
assert.NotNil(t, cred.Attributes[0], "Metadata attribute of irma-demo.RU.studentCard should not be nil") 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) { ...@@ -102,12 +102,12 @@ func TestParseStore(t *testing.T) {
"irma-demo.RU issuer has unexpected name") "irma-demo.RU issuer has unexpected name")
assert.Equal(t, assert.Equal(t,
"Student Card", "Student Card",
MetaStore.Credentials[NewCredentialIdentifier("irma-demo.RU.studentCard")].ShortName.Translation("en"), MetaStore.Credentials[NewCredentialTypeIdentifier("irma-demo.RU.studentCard")].ShortName.Translation("en"),
"irma-demo.RU.studentCard has unexpected name") "irma-demo.RU.studentCard has unexpected name")
assert.Equal(t, assert.Equal(t,
"studentID", "studentID",
MetaStore.Credentials[NewCredentialIdentifier("irma-demo.RU.studentCard")].Attributes[2].ID, MetaStore.Credentials[NewCredentialTypeIdentifier("irma-demo.RU.studentCard")].Attributes[2].ID,
"irma-demo.RU.studentCard.studentID has unexpected name") "irma-demo.RU.studentCard.studentID has unexpected name")
// Hash algorithm pseudocode: // Hash algorithm pseudocode:
...@@ -144,7 +144,7 @@ func TestMetadataCompatibility(t *testing.T) { ...@@ -144,7 +144,7 @@ func TestMetadataCompatibility(t *testing.T) {
assert.NotNil(t, attr.CredentialType(), "attr.CredentialType() should not be nil") assert.NotNil(t, attr.CredentialType(), "attr.CredentialType() should not be nil")
assert.Equal(t, assert.Equal(t,
NewCredentialIdentifier("irma-demo.RU.studentCard"), NewCredentialTypeIdentifier("irma-demo.RU.studentCard"),
attr.CredentialType().Identifier(), attr.CredentialType().Identifier(),
"Metadata credential type was not irma-demo.RU.studentCard", "Metadata credential type was not irma-demo.RU.studentCard",
) )
......
...@@ -18,13 +18,13 @@ var Manager = newCredentialManager() ...@@ -18,13 +18,13 @@ var Manager = newCredentialManager()
type CredentialManager struct { type CredentialManager struct {
secretkey *big.Int secretkey *big.Int
storagePath string storagePath string
attributes map[CredentialIdentifier][]*AttributeList attributes map[CredentialTypeIdentifier][]*AttributeList
credentials map[CredentialIdentifier]map[int]*Credential credentials map[CredentialTypeIdentifier]map[int]*Credential
} }
func newCredentialManager() *CredentialManager { func newCredentialManager() *CredentialManager {
return &CredentialManager{ return &CredentialManager{
credentials: make(map[CredentialIdentifier]map[int]*Credential), credentials: make(map[CredentialTypeIdentifier]map[int]*Credential),
} }
} }
...@@ -50,7 +50,7 @@ func (cm *CredentialManager) Init(path string) (err error) { ...@@ -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 // 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 CredentialTypeIdentifier) []*AttributeList {
list, exists := cm.attributes[id] list, exists := cm.attributes[id]
if !exists { if !exists {
list = make([]*AttributeList, 0, 1) list = make([]*AttributeList, 0, 1)
...@@ -60,7 +60,7 @@ func (cm *CredentialManager) attrs(id CredentialIdentifier) []*AttributeList { ...@@ -60,7 +60,7 @@ func (cm *CredentialManager) attrs(id CredentialIdentifier) []*AttributeList {
} }
// creds returns cm.credentials[id], initializing it to an empty map if neccesary // 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 CredentialTypeIdentifier) map[int]*Credential {
list, exists := cm.credentials[id] list, exists := cm.credentials[id]
if !exists { if !exists {
list = make(map[int]*Credential) list = make(map[int]*Credential)
...@@ -70,7 +70,7 @@ func (cm *CredentialManager) creds(id CredentialIdentifier) 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. // 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 CredentialTypeIdentifier, counter int) (attributes *AttributeList) {
list := cm.attrs(id) list := cm.attrs(id)
if len(list) <= counter { if len(list) <= counter {
return return
...@@ -79,7 +79,7 @@ func (cm *CredentialManager) Attributes(id CredentialIdentifier, counter int) (a ...@@ -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. // 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 CredentialTypeIdentifier, counter int) (cred *Credential, err error) {
// If the requested credential is not in credential map, we check if its attributes were // 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, // 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 // so we read that, construct the credential, and add it to the credential map
......
...@@ -112,7 +112,7 @@ func (cm *CredentialManager) storeSignature(cred *Credential, counter int) (err ...@@ -112,7 +112,7 @@ func (cm *CredentialManager) storeSignature(cred *Credential, counter int) (err
} }
func (cm *CredentialManager) storeAttributes() (err error) { func (cm *CredentialManager) storeAttributes() (err error) {
// Unfortunately, the type of cm.attributes (map[CredentialIdentifier][]*AttributeList) // Unfortunately, the type of cm.attributes (map[CredentialTypeIdentifier][]*AttributeList)
// cannot be passed directly to json.Marshal(), so we copy it into a temp list. // cannot be passed directly to json.Marshal(), so we copy it into a temp list.
temp := make(map[string][]*AttributeList) temp := make(map[string][]*AttributeList)
for credid, list := range cm.attributes { for credid, list := range cm.attributes {
...@@ -128,7 +128,7 @@ func (cm *CredentialManager) storeAttributes() (err error) { ...@@ -128,7 +128,7 @@ func (cm *CredentialManager) storeAttributes() (err error) {
return return
} }
func (cm *CredentialManager) loadSignature(id CredentialIdentifier, counter int) (signature *gabi.CLSignature, err error) { func (cm *CredentialManager) loadSignature(id CredentialTypeIdentifier, counter int) (signature *gabi.CLSignature, err error) {
path := cm.signatureFilename(id.String(), counter) path := cm.signatureFilename(id.String(), counter)
exists, err := pathExists(path) exists, err := pathExists(path)
if err != nil || !exists { if err != nil || !exists {
...@@ -166,8 +166,8 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) { ...@@ -166,8 +166,8 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) {
return sk, nil return sk, nil
} }
func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]*AttributeList, err error) { func (cm *CredentialManager) loadAttributes() (list map[CredentialTypeIdentifier][]*AttributeList, err error) {
list = make(map[CredentialIdentifier][]*AttributeList) list = make(map[CredentialTypeIdentifier][]*AttributeList)
temp := make(map[string][]*AttributeList) temp := make(map[string][]*AttributeList)
exists, err := pathExists(cm.path(attributesFile)) exists, err := pathExists(cm.path(attributesFile))
...@@ -185,7 +185,7 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]* ...@@ -185,7 +185,7 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialIdentifier][]*
} }
for credid, attrs := range temp { for credid, attrs := range temp {
list[NewCredentialIdentifier(credid)] = attrs list[NewCredentialTypeIdentifier(credid)] = attrs
} }
return list, nil return list, nil
} }
...@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore() ...@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore()
type ConfigurationStore struct { type ConfigurationStore struct {
SchemeManagers map[SchemeManagerIdentifier]*SchemeManager SchemeManagers map[SchemeManagerIdentifier]*SchemeManager
Issuers map[IssuerIdentifier]*Issuer Issuers map[IssuerIdentifier]*Issuer
Credentials map[CredentialIdentifier]*CredentialType Credentials map[CredentialTypeIdentifier]*CredentialType
PublicKeys map[IssuerIdentifier][]*gabi.PublicKey PublicKeys map[IssuerIdentifier][]*gabi.PublicKey
reverseHashes map[string]CredentialIdentifier reverseHashes map[string]CredentialTypeIdentifier
initialized bool initialized bool
} }
...@@ -31,9 +31,9 @@ func newConfigurationStore() (store *ConfigurationStore) { ...@@ -31,9 +31,9 @@ func newConfigurationStore() (store *ConfigurationStore) {
store = &ConfigurationStore{ store = &ConfigurationStore{
SchemeManagers: make(map[SchemeManagerIdentifier]*SchemeManager), SchemeManagers: make(map[SchemeManagerIdentifier]*SchemeManager),
Issuers: make(map[IssuerIdentifier]*Issuer), Issuers: make(map[IssuerIdentifier]*Issuer),
Credentials: make(map[CredentialIdentifier]*CredentialType), Credentials: make(map[CredentialTypeIdentifier]*CredentialType),
PublicKeys: make(map[IssuerIdentifier][]*gabi.PublicKey), PublicKeys: make(map[IssuerIdentifier][]*gabi.PublicKey),
reverseHashes: make(map[string]CredentialIdentifier), reverseHashes: make(map[string]CredentialTypeIdentifier),
} }
return return
} }
...@@ -48,7 +48,7 @@ func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *ga ...@@ -48,7 +48,7 @@ func (store *ConfigurationStore) PublicKey(id IssuerIdentifier, counter int) *ga
return nil return nil
} }
func (store *ConfigurationStore) addReverseHash(credid CredentialIdentifier) { func (store *ConfigurationStore) addReverseHash(credid CredentialTypeIdentifier) {
hash := sha256.Sum256([]byte(credid.String())) hash := sha256.Sum256([]byte(credid.String()))
store.reverseHashes[base64.StdEncoding.EncodeToString(hash[:16])] = credid store.reverseHashes[base64.StdEncoding.EncodeToString(hash[:16])] = credid
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment