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 {
return MetaStore.hashToCredentialType(attr.field(credentialID))
}
func (attr *MetadataAttribute) setCredentialIdentifier(id string) {
func (attr *MetadataAttribute) setCredentialTypeIdentifier(id string) {
bytes := sha256.Sum256([]byte(id))
attr.setField(credentialID, bytes[:16])
}
......
......@@ -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.CredentialTypeIdentifier().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() CredentialTypeIdentifier {
return NewCredentialTypeIdentifier(ct.SchemeManagerID + "." + ct.IssuerID + "." + ct.ID)
}
// IssuerIdentifier returns the issuer identifier of the specified credential type.
......
......@@ -14,8 +14,8 @@ type IssuerIdentifier struct {
objectIdentifier
}
// CredentialIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialIdentifier struct {
// CredentialTypeIdentifier identifies a credentialtype. For example "irma-demo.RU.studentCard".
type CredentialTypeIdentifier 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)}
// NewCredentialTypeIdentifier converts the specified identifier to a CredentialTypeIdentifier.
func NewCredentialTypeIdentifier(id string) CredentialTypeIdentifier {
return CredentialTypeIdentifier{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 CredentialTypeIdentifier) IssuerIdentifier() IssuerIdentifier {
return NewIssuerIdentifier(id.Parent())
}
// CredentialIdentifier returns the CredentialIdentifier of the attribute identifier.
func (id AttributeIdentifier) CredentialIdentifier() CredentialIdentifier {
return NewCredentialIdentifier(id.Parent())
// CredentialTypeIdentifier returns the CredentialTypeIdentifier of the attribute identifier.
func (id AttributeIdentifier) CredentialTypeIdentifier() CredentialTypeIdentifier {
return NewCredentialTypeIdentifier(id.Parent())
}
......@@ -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(NewCredentialTypeIdentifier("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[NewCredentialTypeIdentifier("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[NewCredentialTypeIdentifier("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"),
NewCredentialTypeIdentifier("irma-demo.RU.studentCard"),
attr.CredentialType().Identifier(),
"Metadata credential type was not irma-demo.RU.studentCard",
)
......
......@@ -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[CredentialTypeIdentifier][]*AttributeList
credentials map[CredentialTypeIdentifier]map[int]*Credential
}
func newCredentialManager() *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) {
}
// 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]
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 CredentialTypeIdentifier) 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 CredentialTypeIdentifier, 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 CredentialTypeIdentifier, 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
......
......@@ -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[CredentialTypeIdentifier][]*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 CredentialTypeIdentifier, 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[CredentialTypeIdentifier][]*AttributeList, err error) {
list = make(map[CredentialTypeIdentifier][]*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[NewCredentialTypeIdentifier(credid)] = attrs
}
return list, nil
}
......@@ -20,10 +20,10 @@ var MetaStore = newConfigurationStore()
type ConfigurationStore struct {
SchemeManagers map[SchemeManagerIdentifier]*SchemeManager
Issuers map[IssuerIdentifier]*Issuer
Credentials map[CredentialIdentifier]*CredentialType
Credentials map[CredentialTypeIdentifier]*CredentialType
PublicKeys map[IssuerIdentifier][]*gabi.PublicKey
reverseHashes map[string]CredentialIdentifier
reverseHashes map[string]CredentialTypeIdentifier
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[CredentialTypeIdentifier]*CredentialType),
PublicKeys: make(map[IssuerIdentifier][]*gabi.PublicKey),
reverseHashes: make(map[string]CredentialIdentifier),
reverseHashes: make(map[string]CredentialTypeIdentifier),
}
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 CredentialTypeIdentifier) {
hash := sha256.Sum256([]byte(credid.String()))
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