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