Commit 8b00d1cf authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Don't lose credentials of unknown type

parent be569e5e
...@@ -258,21 +258,25 @@ func (cm *CredentialManager) storeSignature(cred *credential, counter int) (err ...@@ -258,21 +258,25 @@ func (cm *CredentialManager) storeSignature(cred *credential, counter int) (err
return err return err
} }
// TODO existence check
filename := cm.signatureFilename(cred.AttributeList()) filename := cm.signatureFilename(cred.AttributeList())
err = ioutil.WriteFile(filename, credbytes, 0600) err = ioutil.WriteFile(filename, credbytes, 0600)
return return
} }
func (cm *CredentialManager) storeAttributes() (err error) { func (cm *CredentialManager) storeAttributes() error {
attrbytes, err := json.Marshal(cm.attributes) temp := []*AttributeList{}
if err != nil { for _, attrlistlist := range cm.attributes {
return err for _, attrlist := range attrlistlist {
temp = append(temp, attrlist)
}
} }
// TODO existence check if attrbytes, err := json.Marshal(temp); err == nil {
err = ioutil.WriteFile(cm.path(attributesFile), attrbytes, 0600) err = ioutil.WriteFile(cm.path(attributesFile), attrbytes, 0600)
return return nil
} else {
return err
}
} }
func (cm *CredentialManager) storeKeyshareServers() (err error) { func (cm *CredentialManager) storeKeyshareServers() (err error) {
...@@ -343,7 +347,6 @@ func (cm *CredentialManager) loadSecretKey() (*secretKey, error) { ...@@ -343,7 +347,6 @@ func (cm *CredentialManager) loadSecretKey() (*secretKey, error) {
} }
func (cm *CredentialManager) loadAttributes() (list map[CredentialTypeIdentifier][]*AttributeList, err error) { func (cm *CredentialManager) loadAttributes() (list map[CredentialTypeIdentifier][]*AttributeList, err error) {
list = make(map[CredentialTypeIdentifier][]*AttributeList)
exists, err := PathExists(cm.path(attributesFile)) exists, err := PathExists(cm.path(attributesFile))
if err != nil || !exists { if err != nil || !exists {
return return
...@@ -352,15 +355,24 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialTypeIdentifier ...@@ -352,15 +355,24 @@ func (cm *CredentialManager) loadAttributes() (list map[CredentialTypeIdentifier
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = json.Unmarshal(bytes, &list)
if err != nil { // The attributes are stored as a list of instances of AttributeList
temp := []*AttributeList{}
list = make(map[CredentialTypeIdentifier][]*AttributeList)
if err = json.Unmarshal(bytes, &temp); err != nil {
return nil, err return nil, err
} }
for _, attrlist := range temp {
for _, attrlistlist := range list {
for _, attrlist := range attrlistlist {
attrlist.MetadataAttribute = MetadataFromInt(attrlist.Ints[0], cm.Store) attrlist.MetadataAttribute = MetadataFromInt(attrlist.Ints[0], cm.Store)
id := attrlist.CredentialType()
var ct CredentialTypeIdentifier
if id != nil {
ct = id.Identifier()
}
if _, contains := list[ct]; !contains {
list[ct] = []*AttributeList{}
} }
list[ct] = append(list[ct], attrlist)
} }
return list, nil return list, nil
......
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