Commit 83e08c7d authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Fix RemoveAll bug

parent 12492d94
...@@ -207,7 +207,7 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor ...@@ -207,7 +207,7 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor
// Remove credential // Remove credential
if creds, exists := cm.credentials[id]; exists { if creds, exists := cm.credentials[id]; exists {
if _, exists := creds[index]; exists { if _, exists := creds[index]; exists {
creds[index] = nil delete(creds, index)
cm.credentials[id] = creds cm.credentials[id] = creds
} }
} }
...@@ -244,14 +244,15 @@ func (cm *CredentialManager) RemoveCredentialByHash(hash string) error { ...@@ -244,14 +244,15 @@ func (cm *CredentialManager) RemoveCredentialByHash(hash string) error {
func (cm *CredentialManager) RemoveAllCredentials() error { func (cm *CredentialManager) RemoveAllCredentials() error {
removed := map[CredentialTypeIdentifier][]TranslatedString{} removed := map[CredentialTypeIdentifier][]TranslatedString{}
list := cm.CredentialInfoList() for _, attrlistlist := range cm.attributes {
for _, cred := range list { for _, attrs := range attrlistlist {
id := NewCredentialTypeIdentifier(cred.CredentialTypeID) if attrs.CredentialType() != nil {
removed[id] = cred.Attributes removed[attrs.CredentialType().Identifier()] = attrs.Strings()
if err := cm.remove(id, cred.Index, false); err != nil { }
return err cm.storage.DeleteSignature(attrs)
} }
} }
cm.attributes = map[CredentialTypeIdentifier][]*AttributeList{}
if err := cm.storage.StoreAttributes(cm.attributes); err != nil { if err := cm.storage.StoreAttributes(cm.attributes); err != nil {
return err return err
} }
...@@ -311,8 +312,15 @@ func (cm *CredentialManager) credentialByHash(hash string) (*credential, int, er ...@@ -311,8 +312,15 @@ func (cm *CredentialManager) credentialByHash(hash string) (*credential, int, er
} }
func (cm *CredentialManager) credentialByID(id CredentialIdentifier) (*credential, error) { func (cm *CredentialManager) credentialByID(id CredentialIdentifier) (*credential, error) {
cred, _, err := cm.credentialByHash(id.Hash) if _, exists := cm.attributes[id.Type]; !exists {
return cred, err return nil, nil
}
for index, attrs := range cm.attributes[id.Type] {
if attrs.hash() == id.Hash {
return cm.credential(attrs.CredentialType().Identifier(), index)
}
}
return nil, nil
} }
// 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.
......
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