Commit 6b3112b6 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Fix inconsistent serialization to storage

parent 8c780ff8
...@@ -119,7 +119,9 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int ...@@ -119,7 +119,9 @@ func (cm *CredentialManager) credential(id CredentialTypeIdentifier, counter int
return cm.credentials[id][counter], nil return cm.credentials[id][counter], nil
} }
func (cm *CredentialManager) addCredential(cred *credential) error { // addCredential adds the specified credential to the CredentialManager, saving its signature
// imediately, and optionally cm.attributes as well.
func (cm *CredentialManager) addCredential(cred *credential, storeAttributes bool) (err error) {
attrs, err := NewAttributeListFromInts(cred.Attributes[1:]) attrs, err := NewAttributeListFromInts(cred.Attributes[1:])
if err != nil { if err != nil {
return err return err
...@@ -132,24 +134,13 @@ func (cm *CredentialManager) addCredential(cred *credential) error { ...@@ -132,24 +134,13 @@ func (cm *CredentialManager) addCredential(cred *credential) error {
} }
counter := len(cm.attributes[id]) - 1 counter := len(cm.attributes[id]) - 1
cm.credentials[id][counter] = cred cm.credentials[id][counter] = cred
return nil
}
// add adds the specified credential to the CredentialManager.
func (cm *CredentialManager) add(cred *credential) (err error) {
if cred.CredentialType() == nil {
return errors.New("cannot add unknown credential type")
}
if err = cm.addCredential(cred); err != nil {
return
}
counter := len(cm.credentials[cred.CredentialType().Identifier()]) - 1
if err = cm.storeSignature(cred, counter); err != nil { if err = cm.storeSignature(cred, counter); err != nil {
return return
} }
err = cm.storeAttributes() if storeAttributes {
err = cm.storeAttributes()
}
return return
} }
...@@ -333,7 +324,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess ...@@ -333,7 +324,7 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
} }
for _, cred := range creds { for _, cred := range creds {
cm.add(newCredential(cred)) cm.addCredential(newCredential(cred), true)
} }
return nil return nil
......
...@@ -136,14 +136,13 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) { ...@@ -136,14 +136,13 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) {
for _, list := range parsedjson { for _, list := range parsedjson {
cm.secretkey = list[0].Attributes[0] cm.secretkey = list[0].Attributes[0]
for i, gabicred := range list { for _, gabicred := range list {
cred := newCredential(gabicred) cred := newCredential(gabicred)
if cred.CredentialType() == nil { if cred.CredentialType() == nil {
return errors.New("cannot add unknown credential type") return errors.New("cannot add unknown credential type")
} }
cm.addCredential(cred) err = cm.addCredential(cred, false)
err = cm.storeSignature(cred, i)
if err != nil { if err != nil {
return err return err
} }
......
Supports Markdown
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