-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace dynamically generated errors with constants #711
Merged
iamnotacake
merged 8 commits into
cossacklabs:master
from
iamnotacake:T977-use-statically-created-errors
Sep 5, 2020
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1cf684b
Replace dymanically generated errors with const ones
iamnotacake de4f0d0
Replace dymanically generated callback errors with const ones
iamnotacake bec889d
Updates after review
iamnotacake 2505434
Rename ErrOverflow -> ErrOutOfMemory
iamnotacake f204717
Updates after review
iamnotacake 89d2876
Unify few session errors into ErrMessageSize and ErrMessageData
iamnotacake f4f0857
Fix typo in changelog, change deprecation version
iamnotacake 2e5a258
Make error messages start with lowercase
iamnotacake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,9 +77,16 @@ const ( | |
|
||
// Errors returned by Secure Comparator. | ||
var ( | ||
ErrMissingSecret = errors.NewWithCode(errors.InvalidParameter, "empty secret for Secure Comparator") | ||
ErrMissingData = errors.NewWithCode(errors.InvalidParameter, "empty comparison message for Secure Comparator") | ||
ErrOverflow = errors.NewWithCode(errors.NoMemory, "Secure Comparator cannot allocate enough memory") | ||
ErrAppendSecret = errors.New("Failed to append secret") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
ErrCreateComparatorObject = errors.New("Failed to create comparator object") | ||
ErrDestroyComparatorObject = errors.New("Failed to destroy comparator object") | ||
ilammy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ErrGetCmpData = errors.New("Failed to get compare data") | ||
ErrGetCmpResult = errors.New("Failed to get compare result") | ||
ErrGetOutput = errors.New("Failed to get output") | ||
ErrGetOutputSize = errors.New("Failed to get output size") | ||
ilammy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ErrMissingSecret = errors.NewWithCode(errors.InvalidParameter, "empty secret for Secure Comparator") | ||
ErrMissingData = errors.NewWithCode(errors.InvalidParameter, "empty comparison message for Secure Comparator") | ||
ErrOutOfMemory = errors.NewWithCode(errors.NoMemory, "Secure Comparator cannot allocate enough memory") | ||
) | ||
|
||
// SecureCompare is an interactive protocol for two parties that compares whether | ||
|
@@ -103,7 +110,7 @@ func sizeOverflow(n C.size_t) bool { | |
func New() (*SecureCompare, error) { | ||
ctx := C.compare_init() | ||
if nil == ctx { | ||
return nil, errors.New("Failed to create comparator object") | ||
return nil, ErrCreateComparatorObject | ||
} | ||
|
||
sc := &SecureCompare{ctx} | ||
|
@@ -118,7 +125,7 @@ func (sc *SecureCompare) Close() error { | |
if bool(C.compare_destroy(sc.ctx)) { | ||
sc.ctx = nil | ||
} else { | ||
return errors.New("Failed to destroy comparator object") | ||
return ErrDestroyComparatorObject | ||
} | ||
} | ||
|
||
|
@@ -131,7 +138,7 @@ func (sc *SecureCompare) Append(secret []byte) error { | |
return ErrMissingSecret | ||
} | ||
if !bool(C.compare_append(sc.ctx, unsafe.Pointer(&secret[0]), C.size_t(len(secret)))) { | ||
return errors.New("Failed to append secret") | ||
return ErrAppendSecret | ||
} | ||
|
||
return nil | ||
|
@@ -142,16 +149,16 @@ func (sc *SecureCompare) Begin() ([]byte, error) { | |
var outLen C.size_t | ||
|
||
if !bool(C.compare_begin_size(sc.ctx, &outLen)) { | ||
return nil, errors.New("Failed to get output size") | ||
return nil, ErrGetOutputSize | ||
} | ||
if sizeOverflow(outLen) { | ||
return nil, ErrOverflow | ||
return nil, ErrOutOfMemory | ||
} | ||
|
||
out := make([]byte, outLen) | ||
|
||
if !bool(C.compare_begin(sc.ctx, unsafe.Pointer(&out[0]), outLen)) { | ||
return nil, errors.New("Failed to get compare data") | ||
return nil, ErrGetCmpData | ||
} | ||
|
||
return out, nil | ||
|
@@ -167,10 +174,10 @@ func (sc *SecureCompare) Proceed(data []byte) ([]byte, error) { | |
} | ||
|
||
if !bool(C.compare_proceed_size(sc.ctx, unsafe.Pointer(&data[0]), C.size_t(len(data)), &outLen)) { | ||
return nil, errors.New("Failed to get output size") | ||
return nil, ErrGetOutputSize | ||
} | ||
if sizeOverflow(outLen) { | ||
return nil, ErrOverflow | ||
return nil, ErrOutOfMemory | ||
} | ||
|
||
if 0 == outLen { | ||
|
@@ -187,7 +194,7 @@ func (sc *SecureCompare) Proceed(data []byte) ([]byte, error) { | |
return out, nil | ||
} | ||
|
||
return nil, errors.New("Failed to get output") | ||
return nil, ErrGetOutput | ||
} | ||
|
||
// Result returns the result of the comparison. | ||
|
@@ -198,5 +205,5 @@ func (sc *SecureCompare) Result() (int, error) { | |
return int(res), nil | ||
} | ||
|
||
return NotReady, errors.New("Failed to get compare result") | ||
return NotReady, ErrGetCmpResult | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go's convention seems to start error messages with lowercase. There are some legacy error messages which do not follow this convention. I would ask you to fix the messages to use lowercase while extracting them into constants. (For avoidance of doubt, "Secure Cell" is a proper name so it should be capitalized.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still upper case error messages