Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: "2"

run:
timeout: 3m
Expand All @@ -9,20 +9,22 @@ formatters:

issues:
# Disable limits on the number of printed issues
max-issues-per-linter: 0 # 0 = no limit
max-same-issues: 0 # 0 = no limit
max-issues-per-linter: 0 # 0 = no limit
max-same-issues: 0 # 0 = no limit

linters:
default: all

disable:
- dupl # Dupl is disabled, since we're generating a lot of boilerplate code.
- cyclop # Cyclop is disabled, since cyclomatic complexities is very abstract metric,
# that sometimes lead to strange linter behaviour.
- wsl # WSL is disabled, since it's obsolete. Using WSL_v5.
- dupl # Dupl is disabled, since we're generating a lot of boilerplate code.
- cyclop # Cyclop is disabled, since cyclomatic complexities is very abstract metric,
# that sometimes lead to strange linter behaviour.
- wsl # WSL is disabled, since it's obsolete. Using WSL_v5.
- nlreturn # nlreturn is disabled, since it's duplicated by wsl_v5.return check.
- ireturn # ireturn is disabled, since it's not needed.
- godox # godox is disabled to allow TODO comments for unimplemented functionality.
- ireturn # ireturn is disabled, since it's not needed.
- godox # godox is disabled to allow TODO comments for unimplemented functionality.
- gocognit # gocognit is disabled, cognitive complexity is too restrictive.
- funlen # funlen is disabled, function length limits are too restrictive.

exclusions:
generated: lax
Expand All @@ -40,6 +42,14 @@ linters:
ignore-decls:
- mc *minimock.Controller
- t T
revive:
rules:
- name: var-naming
arguments:
- []
- []
- - skip-package-name-checks: true

godot:
scope: all
lll:
Expand Down
2 changes: 1 addition & 1 deletion crypto/rsapss.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crypto //nolint:revive
package crypto

import (
"crypto"
Expand Down
4 changes: 2 additions & 2 deletions driver/etcd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func TestEtcdDriver_VersionEqualPredicate(t *testing.T) {

putValue(ctx, t, driver, key, value)

kv := getValue(ctx, t, driver, key)
initialRevision := kv.ModRevision
kvi := getValue(ctx, t, driver, key)
initialRevision := kvi.ModRevision

response, err := driver.Execute(ctx, []predicate.Predicate{
predicate.VersionEqual(key, initialRevision),
Expand Down
1 change: 1 addition & 0 deletions hasher/hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/tarantool/go-storage/hasher"
)

Expand Down
249 changes: 249 additions & 0 deletions integrity/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
package integrity

import (
"encoding/hex"
"fmt"
"strings"
)

// ImpossibleError represents an error when an integrity operation cannot be performed due to internal problems.
type ImpossibleError struct {
text string
}

func errImpossibleHasher(property string) error {
return ImpossibleError{
text: "hasher not found: " + property,
}
}

func errImpossibleSigner(property string) error {
return ImpossibleError{
text: "signer not found: " + property,
}
}

func errImpossibleKeyType(keyType string) error {
return ImpossibleError{
text: "unknown key type: " + keyType,
}
}

func (e ImpossibleError) Error() string {
return e.text
}

// ValidationError represents an error when validation fails.
type ValidationError struct {
text string
parent error
}

// Error returns a string representation of the validation error.
func (e ValidationError) Error() string {
if e.parent == nil {
return e.text
}

return fmt.Sprintf("%s: %s", e.text, e.parent)
}

func (e ValidationError) Unpack() error {
return e.parent
}

// FailedToGenerateKeysError represents an error when key generation fails.
type FailedToGenerateKeysError struct {
parent error
}

func errFailedToGenerateKeys(parent error) error {
return FailedToGenerateKeysError{parent: parent}
}

// Unwrap returns the underlying error that caused the key generation failure.
func (e FailedToGenerateKeysError) Unwrap() error {
return e.parent
}

// Error returns a string representation of the key generation error.
func (e FailedToGenerateKeysError) Error() string {
if e.parent == nil {
return "failed to generate keys"
}

return "failed to generate keys: " + e.parent.Error()
}

// FailedToMarshalValueError represents an error when value marshalling fails.
type FailedToMarshalValueError struct {
parent error
}

func errFailedToMarshalValue(parent error) error {
return FailedToMarshalValueError{parent: parent}
}

// Unwrap returns the underlying error that caused the marshalling failure.
func (e FailedToMarshalValueError) Unwrap() error {
return e.parent
}

// Error returns a string representation of the marshalling error.
func (e FailedToMarshalValueError) Error() string {
if e.parent == nil {
return "failed to marshal value"
}

return "failed to marshal value: " + e.parent.Error()
}

// FailedToComputeHashError represents an error when hash computation fails.
type FailedToComputeHashError struct {
parent error
}

func errFailedToComputeHash(parent error) error {
return FailedToComputeHashError{parent: parent}
}

// Unwrap returns the underlying error that caused the hash computation failure.
func (e FailedToComputeHashError) Unwrap() error {
return e.parent
}

// Error returns a string representation of the hash computation error.
func (e FailedToComputeHashError) Error() string {
if e.parent == nil {
return "failed to compute hash"
}

return "failed to compute hash: " + e.parent.Error()
}

// FailedToGenerateSignatureError represents an error when signature generation fails.
type FailedToGenerateSignatureError struct {
parent error
}

func errFailedToGenerateSignature(parent error) error {
return FailedToGenerateSignatureError{parent: parent}
}

// Unwrap returns the underlying error that caused the signature generation failure.
func (e FailedToGenerateSignatureError) Unwrap() error {
return e.parent
}

// Error returns a string representation of the signature generation error.
func (e FailedToGenerateSignatureError) Error() string {
if e.parent == nil {
return "failed to generate signature"
}

return "failed to generate signature: " + e.parent.Error()
}

// FailedToValidateAggregatedError represents aggregated validation errors.
type FailedToValidateAggregatedError struct {
parent []error
}

func errHashNotVerifiedMissing(hasherName string) error {
return ValidationError{
text: fmt.Sprintf("hash \"%s\" not verified (missing)", hasherName),
parent: nil,
}
}

func errSignatureNotVerifiedMissing(verifierName string) error {
return ValidationError{
text: fmt.Sprintf("signature \"%s\" not verified (missing)", verifierName),
parent: nil,
}
}

func errHashMismatch(hasherName string, expected, got []byte) error {
return ValidationError{
text: fmt.Sprintf("hash mismatch for \"%s\"", hasherName),
parent: hashMismatchDetailError{expected: expected, got: got},
}
}

type hashMismatchDetailError struct {
expected []byte
got []byte
}

func (h hashMismatchDetailError) Error() string {
return fmt.Sprintf("expected \"%s\", got \"%s\"", hex.Dump(h.expected), hex.Dump(h.got))
}

func errFailedToParseKey(parent error) error {
return ValidationError{
text: "failed to parse key",
parent: parent,
}
}

func errFailedToComputeHashWith(hasherName string, parent error) error {
return ValidationError{
text: fmt.Sprintf("failed to calculate hash \"%s\"", hasherName),
parent: parent,
}
}

func errSignatureVerificationFailed(verifierName string, parent error) error {
return ValidationError{
text: fmt.Sprintf("signature verification failed for \"%s\"", verifierName),
parent: parent,
}
}

func errFailedToUnmarshal(parent error) error {
return ValidationError{
text: "failed to unmarshal record",
parent: parent,
}
}

// Unwrap returns the underlying slice of errors.
func (e *FailedToValidateAggregatedError) Unwrap() []error {
return e.parent
}

// Append adds an error to the aggregated error.
func (e *FailedToValidateAggregatedError) Append(err error) {
if err != nil {
e.parent = append(e.parent, err)
}
}

// Error returns a string representation of the aggregated error.
func (e *FailedToValidateAggregatedError) Error() string {
switch {
case len(e.parent) == 0:
return ""
case len(e.parent) == 1:
return e.parent[0].Error()
default:
var errStrings []string
for _, p := range e.parent {
errStrings = append(errStrings, p.Error())
}

return "aggregated error: " + strings.Join(errStrings, ", ")
}
}

// Finalize returns nil if there are no errors, otherwise returns error or the aggregated error.
func (e *FailedToValidateAggregatedError) Finalize() error {
switch len(e.parent) {
case 0:
return nil
case 1:
return e.parent[0]
default:
return e
}
}
Loading
Loading