Skip to content

Commit

Permalink
Unprotect error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dissoupov committed Mar 7, 2024
1 parent f77f13f commit 4cc0ae1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.16
v0.17
4 changes: 2 additions & 2 deletions dataprotection/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func ProtectObject(ctx context.Context, p Provider, v interface{}) (string, erro
}
ejs, err := p.Protect(ctx, js)
if err != nil {
return "", errors.WithMessage(err, "failed to protect")
return "", err
}
return base64.RawURLEncoding.EncodeToString(ejs), nil
}
Expand All @@ -42,7 +42,7 @@ func UnprotectObject(ctx context.Context, p Provider, protected string, v interf
}
js, err = p.Unprotect(ctx, js)
if err != nil {
return errors.WithMessage(err, "failed to unprotect data")
return err
}

if err = json.Unmarshal(js, v); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions dataprotection/symmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func (p symProvider) Protect(_ context.Context, data []byte) ([]byte, error) {
// Unprotect returns unprotected data
func (p symProvider) Unprotect(_ context.Context, protected []byte) ([]byte, error) {
if len(protected) < p.nonceSize {
return nil, errors.Errorf("invalid data")
return nil, errors.Errorf("invalid data: less than nonce size")
}
plaintext, err := p.gcm.Open(nil, protected[:p.nonceSize], protected[p.nonceSize:], nil)
if err != nil {
return nil, errors.WithMessage(err, "failed to upprotect")
return nil, errors.Wrapf(err, "failed to unprotect")
}

return plaintext, nil
Expand Down
10 changes: 5 additions & 5 deletions dataprotection/symmetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func TestNewSymmetric(t *testing.T) {
// modify the data
protected[0] = protected[1]
_, err = p.Unprotect(ctx, protected)
assert.EqualError(t, err, "failed to upprotect: cipher: message authentication failed")
assert.EqualError(t, err, "failed to unprotect: cipher: message authentication failed")

_, err = p.Unprotect(ctx, nil)
assert.EqualError(t, err, "invalid data")
assert.EqualError(t, err, "invalid data: less than nonce size")

_, err = p.Unprotect(ctx, protected[:11])
assert.EqualError(t, err, "invalid data")
assert.EqualError(t, err, "invalid data: less than nonce size")

s := state{Str: "hello", ID: 123}
b64, err := ProtectObject(ctx, p, s)
Expand All @@ -43,10 +43,10 @@ func TestNewSymmetric(t *testing.T) {
assert.Equal(t, s, s2)

err = UnprotectObject(ctx, p, "b64", &s2)
assert.EqualError(t, err, "failed to unprotect data: invalid data")
assert.EqualError(t, err, "invalid data: less than nonce size")

err = UnprotectObject(ctx, p, "Aa"+b64, &s2)
assert.EqualError(t, err, "failed to unprotect data: failed to upprotect: cipher: message authentication failed")
assert.EqualError(t, err, "failed to unprotect: cipher: message authentication failed")
}

type state struct {
Expand Down

0 comments on commit 4cc0ae1

Please sign in to comment.