Commit 7106720d authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers
Browse files

Fixed removal of multiple credentials causing lookup getting out of sync

parent ee35495b
...@@ -48,7 +48,7 @@ type Client struct { ...@@ -48,7 +48,7 @@ type Client struct {
keyshareServers map[irma.SchemeManagerIdentifier]*keyshareServer keyshareServers map[irma.SchemeManagerIdentifier]*keyshareServer
updates []update updates []update
lookup map[string]credLookup lookup map[string]*credLookup
// Where we store/load it to/from // Where we store/load it to/from
storage storage storage storage
...@@ -203,10 +203,10 @@ func New( ...@@ -203,10 +203,10 @@ func New(
return nil, errors.New("Too many keyshare servers") return nil, errors.New("Too many keyshare servers")
} }
client.lookup = map[string]credLookup{} client.lookup = map[string]*credLookup{}
for _, attrlistlist := range client.attributes { for _, attrlistlist := range client.attributes {
for i, attrlist := range attrlistlist { for i, attrlist := range attrlistlist {
client.lookup[attrlist.Hash()] = credLookup{id: attrlist.CredentialType().Identifier(), counter: i} client.lookup[attrlist.Hash()] = &credLookup{id: attrlist.CredentialType().Identifier(), counter: i}
} }
} }
...@@ -344,7 +344,7 @@ func (client *Client) addCredential(cred *credential) (err error) { ...@@ -344,7 +344,7 @@ func (client *Client) addCredential(cred *credential) (err error) {
} }
counter := len(client.attributes[id]) - 1 counter := len(client.attributes[id]) - 1
client.credentialsCache[id][counter] = cred client.credentialsCache[id][counter] = cred
client.lookup[cred.attrs.Hash()] = credLookup{id: id, counter: counter} client.lookup[cred.attrs.Hash()] = &credLookup{id: id, counter: counter}
} }
return client.storage.Transaction(func(tx *transaction) error { return client.storage.Transaction(func(tx *transaction) error {
...@@ -402,6 +402,10 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storeL ...@@ -402,6 +402,10 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storeL
client.credentialsCache[id] = creds client.credentialsCache[id] = creds
} }
} }
delete(client.lookup, attrs.Hash())
for i, attrs := range client.attributes[id] {
client.lookup[attrs.Hash()].counter = i
}
return nil return nil
} }
......
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