Commit 38779f80 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Catch some more errors

parent de9c0201
...@@ -374,7 +374,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error { ...@@ -374,7 +374,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error {
Label string `json:"label"` Label string `json:"label"`
Attributes interface{} `json:"attributes"` Attributes interface{} `json:"attributes"`
}{} }{}
json.Unmarshal(bytes, &temp) if err := json.Unmarshal(bytes, &temp); err != nil {
return err
}
disjunction.Label = temp.Label disjunction.Label = temp.Label
switch temp.Attributes.(type) { switch temp.Attributes.(type) {
...@@ -383,7 +385,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error { ...@@ -383,7 +385,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error {
Label string `json:"label"` Label string `json:"label"`
Attributes map[string]string `json:"attributes"` Attributes map[string]string `json:"attributes"`
}{} }{}
json.Unmarshal(bytes, &temp) if err := json.Unmarshal(bytes, &temp); err != nil {
return err
}
for str, value := range temp.Attributes { for str, value := range temp.Attributes {
id := NewAttributeTypeIdentifier(str) id := NewAttributeTypeIdentifier(str)
disjunction.Attributes = append(disjunction.Attributes, id) disjunction.Attributes = append(disjunction.Attributes, id)
...@@ -394,7 +398,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error { ...@@ -394,7 +398,9 @@ func (disjunction *AttributeDisjunction) UnmarshalJSON(bytes []byte) error {
Label string `json:"label"` Label string `json:"label"`
Attributes []string `json:"attributes"` Attributes []string `json:"attributes"`
}{} }{}
json.Unmarshal(bytes, &temp) if err := json.Unmarshal(bytes, &temp); err != nil {
return err
}
for _, str := range temp.Attributes { for _, str := range temp.Attributes {
disjunction.Attributes = append(disjunction.Attributes, NewAttributeTypeIdentifier(str)) disjunction.Attributes = append(disjunction.Attributes, NewAttributeTypeIdentifier(str))
} }
......
...@@ -230,7 +230,6 @@ func (store *ConfigurationStore) Copy(source string, parse bool) error { ...@@ -230,7 +230,6 @@ func (store *ConfigurationStore) Copy(source string, parse bool) error {
return err return err
} }
// TODO skip existing scheme managers? individual files?
err := filepath.Walk(source, filepath.WalkFunc( err := filepath.Walk(source, filepath.WalkFunc(
func(path string, info os.FileInfo, err error) error { func(path string, info os.FileInfo, err error) error {
if path == source { if path == source {
......
...@@ -29,7 +29,7 @@ func TestMain(m *testing.M) { ...@@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
type IgnoringKeyshareHandler struct{} type IgnoringKeyshareHandler struct{}
func (i *IgnoringKeyshareHandler) StartRegistration(m *SchemeManager, callback func(e, p string)) { func (i *IgnoringKeyshareHandler) StartRegistration(m *SchemeManager, callback func(e, p string) error) {
} }
func parseStorage(t *testing.T) *CredentialManager { func parseStorage(t *testing.T) *CredentialManager {
......
...@@ -98,7 +98,7 @@ type proofPCommitmentMap struct { ...@@ -98,7 +98,7 @@ type proofPCommitmentMap struct {
// KeyshareHandler is used for asking the user for his email address and PIN, // KeyshareHandler is used for asking the user for his email address and PIN,
// for registering at a keyshare server. // for registering at a keyshare server.
type KeyshareHandler interface { type KeyshareHandler interface {
StartRegistration(manager *SchemeManager, registrationCallback func(email, pin string)) StartRegistration(manager *SchemeManager, registrationCallback func(email, pin string) error)
} }
const ( const (
......
...@@ -139,8 +139,8 @@ func NewCredentialManager( ...@@ -139,8 +139,8 @@ func NewCredentialManager(
if keyshareHandler == nil { if keyshareHandler == nil {
return nil, errors.New("Keyshare server found but no KeyshareHandler was given") return nil, errors.New("Keyshare server found but no KeyshareHandler was given")
} }
keyshareHandler.StartRegistration(unenrolled[0], func(email, pin string) { keyshareHandler.StartRegistration(unenrolled[0], func(email, pin string) error {
cm.KeyshareEnroll(unenrolled[0].Identifier(), email, pin) return cm.KeyshareEnroll(unenrolled[0].Identifier(), email, pin)
}) })
default: default:
return nil, errors.New("Too many keyshare servers") return nil, errors.New("Too many keyshare servers")
...@@ -209,7 +209,9 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor ...@@ -209,7 +209,9 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor
attrs := list[index] attrs := list[index]
cm.attributes[id] = append(list[:index], list[index+1:]...) cm.attributes[id] = append(list[:index], list[index+1:]...)
if storenow { if storenow {
cm.storage.StoreAttributes(cm.attributes) if err := cm.storage.StoreAttributes(cm.attributes); err != nil {
return err
}
} }
// Remove credential // Remove credential
...@@ -520,7 +522,9 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess ...@@ -520,7 +522,9 @@ func (cm *CredentialManager) ConstructCredentials(msg []*gabi.IssueSignatureMess
if err != nil { if err != nil {
return err return err
} }
cm.addCredential(newcred, true) if err = cm.addCredential(newcred, true); err != nil {
return err
}
} }
return nil return nil
......
...@@ -289,6 +289,6 @@ func (session *session) sendResponse(message interface{}) { ...@@ -289,6 +289,6 @@ func (session *session) sendResponse(message interface{}) {
log, _ = session.createLogEntry(message) // TODO err log, _ = session.createLogEntry(message) // TODO err
} }
session.credManager.addLogEntry(log, true) // TODO err _ = session.credManager.addLogEntry(log, true) // TODO err
session.Handler.Success(session.Action) session.Handler.Success(session.Action)
} }
...@@ -102,8 +102,8 @@ func (transport *HTTPTransport) request(url string, method string, result interf ...@@ -102,8 +102,8 @@ func (transport *HTTPTransport) request(url string, method string, result interf
} }
if res.StatusCode != 200 { if res.StatusCode != 200 {
apierr := &ApiError{} apierr := &ApiError{}
json.Unmarshal(body, apierr) err = json.Unmarshal(body, apierr)
if apierr.ErrorName == "" { // Not an ApiErrorMessage if err != nil || apierr.ErrorName == "" { // Not an ApiErrorMessage
return &SessionError{ErrorType: ErrorServerResponse, Status: res.StatusCode} return &SessionError{ErrorType: ErrorServerResponse, Status: res.StatusCode}
} }
if verbose { if verbose {
...@@ -139,5 +139,5 @@ func (transport *HTTPTransport) Get(url string, result interface{}) error { ...@@ -139,5 +139,5 @@ func (transport *HTTPTransport) Get(url string, result interface{}) error {
// Delete performs a DELETE. // Delete performs a DELETE.
func (transport *HTTPTransport) Delete() { func (transport *HTTPTransport) Delete() {
transport.request("", http.MethodDelete, nil, nil) _ = transport.request("", http.MethodDelete, nil, nil)
} }
...@@ -42,21 +42,19 @@ func (cm *CredentialManager) update() error { ...@@ -42,21 +42,19 @@ func (cm *CredentialManager) update() error {
// Perform all new updates // Perform all new updates
for i := len(cm.updates); i < len(credentialManagerUpdates); i++ { for i := len(cm.updates); i < len(credentialManagerUpdates); i++ {
err = credentialManagerUpdates[i](cm) err = credentialManagerUpdates[i](cm)
update := update{ u := update{
When: Timestamp(time.Now()), When: Timestamp(time.Now()),
Number: i, Number: i,
Success: err == nil, Success: err == nil,
} }
if err != nil { if err != nil {
str := err.Error() str := err.Error()
update.Error = &str u.Error = &str
} }
cm.updates = append(cm.updates, update) cm.updates = append(cm.updates, u)
} }
cm.storage.StoreUpdates(cm.updates) return cm.storage.StoreUpdates(cm.updates)
return nil
} }
// ParseAndroidStorage parses an Android cardemu.xml shared preferences file // ParseAndroidStorage parses an Android cardemu.xml shared preferences file
...@@ -85,7 +83,9 @@ func (cm *CredentialManager) ParseAndroidStorage() (present bool, err error) { ...@@ -85,7 +83,9 @@ func (cm *CredentialManager) ParseAndroidStorage() (present bool, err error) {
Content string `xml:",chardata"` Content string `xml:",chardata"`
} `xml:"string"` } `xml:"string"`
}{} }{}
xml.Unmarshal(bytes, &parsedxml) if err = xml.Unmarshal(bytes, &parsedxml); err != nil {
return
}
parsedjson := make(map[string][]*struct { parsedjson := make(map[string][]*struct {
Signature *gabi.CLSignature `json:"signature"` Signature *gabi.CLSignature `json:"signature"`
......
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