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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ coveralls-deps:
.PHONY: lint-deps
lint-deps:
@echo "Installing lint deps"
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2

.PHONY: lint
lint: lint-deps
Expand Down
2 changes: 1 addition & 1 deletion crypto/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package crypto implements crypto interfaces.
// Package crypto implements verification interfaces.
package crypto

// Signer implements high-level API for package signing.
Expand Down
8 changes: 4 additions & 4 deletions crypto/rsa.go → crypto/rsapss.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crypto
package crypto //nolint:revive

import (
"crypto"
Expand Down Expand Up @@ -29,12 +29,12 @@ func NewRSAPSS(privKey rsa.PrivateKey, pubKey rsa.PublicKey) RSAPSS {
}

// Name implements SignerVerifier interface.
func (r *RSAPSS) Name() string {
func (r RSAPSS) Name() string {
return "RSASSA-PSS"
}

// Sign generates SHA-256 digest and signs it using RSASSA-PSS.
func (r *RSAPSS) Sign(data []byte) ([]byte, error) {
func (r RSAPSS) Sign(data []byte) ([]byte, error) {
digest, err := r.hasher.Hash(data)
if err != nil {
return []byte{}, fmt.Errorf("failed to get hash: %w", err)
Expand All @@ -52,7 +52,7 @@ func (r *RSAPSS) Sign(data []byte) ([]byte, error) {
}

// Verify compares data with signature.
func (r *RSAPSS) Verify(data []byte, signature []byte) error {
func (r RSAPSS) Verify(data []byte, signature []byte) error {
digest, err := r.hasher.Hash(data)
if err != nil {
return fmt.Errorf("failed to get hash: %w", err)
Expand Down
1 change: 1 addition & 0 deletions crypto/rsa_test.go → crypto/rsapss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/require"

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

Expand Down
8 changes: 4 additions & 4 deletions hasher/hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func TestSHA256Hasher(t *testing.T) {
t.Parallel()

tests := []struct {
name string
in []byte
out string
name string
in []byte
expected string
}{
{"empty", []byte(""), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
{"abc", []byte("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"},
Expand All @@ -77,7 +77,7 @@ func TestSHA256Hasher(t *testing.T) {

result, _ := h.Hash(test.in)

assert.Equal(t, test.out, hex.EncodeToString(result))
assert.Equal(t, test.expected, hex.EncodeToString(result))
})
}
}
Expand Down
1 change: 0 additions & 1 deletion kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type KeyValue struct {
Key []byte
// Value is the serialized representation of the value.
Value []byte

// ModRevision is the revision number of the last modification to this key.
ModRevision int64
}
8 changes: 4 additions & 4 deletions marshaller/marshaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ var ErrUnmarshall = errors.New("failed to unmarshal")
// implements one time for all objects.
// Required for `integrity.Storage` to set marshalling format for any type object
// and as recommendation for developers of `Storage` wrappers.
type DefaultMarshaller interface {
type DefaultMarshaller interface { //nolint:iface
Marshal(data any) ([]byte, error)
Unmarshal(data []byte, out any) error
}

// Marshallable - custom object serialization, implements for each object.
// Required for `integrity.Storage` type to set marshalling format to specific object
// and as recommendation for developers of `Storage` wrappers.
type Marshallable interface {
Marshal() ([]byte, error)
type Marshallable interface { //nolint:iface
Marshal(data any) ([]byte, error)
Unmarshal(data []byte, out any) error
}

// YAMLMarshaller struct represent realization.
type YAMLMarshaller struct{}

// NewYamlMarshaller creates new NewYamlMarshaller object.
func NewYamlMarshaller() YAMLMarshaller {
func NewYamlMarshaller() Marshallable {
return YAMLMarshaller{}
}

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

import (
"fmt"
)

// InvalidKeyError represents an error for invalid key format.
type InvalidKeyError struct {
Key string
Problem string
}

func (e InvalidKeyError) Error() string {
return fmt.Sprintf("invalid key '%s': %s", e.Key, e.Problem)
}

func errInvalidKey(key string, problem string) error {
return InvalidKeyError{
Key: key,
Problem: problem,
}
}

// InvalidNameError represents an error for invalid name format.
type InvalidNameError struct {
Name string
Problem string
}

func (e InvalidNameError) Error() string {
return fmt.Sprintf("invalid name '%s': %s", e.Name, e.Problem)
}

func errInvalidName(name string, problem string) error {
return InvalidNameError{
Name: name,
Problem: problem,
}
}
23 changes: 23 additions & 0 deletions namer/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package namer_test

import (
"testing"

"github.com/stretchr/testify/assert"

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

func TestInvalidNameError_Error(t *testing.T) {
t.Parallel()

err := namer.InvalidNameError{Name: "name", Problem: "problem"}
assert.Equal(t, "invalid name 'name': problem", err.Error())
}

func TestInvalidKeyError_Error(t *testing.T) {
t.Parallel()

err := namer.InvalidKeyError{Key: "name", Problem: "problem"}
assert.Equal(t, "invalid key 'name': problem", err.Error())
}
59 changes: 59 additions & 0 deletions namer/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package namer

// KeyType represents key types.
type KeyType int

const (
// KeyTypeValue represents data type.
KeyTypeValue KeyType = iota + 1
// KeyTypeHash represents hash of the data type.
KeyTypeHash
// KeyTypeSignature represents signature of the data type.
KeyTypeSignature
)

// Key defines the minimal interface required by keys.
type Key interface {
Name() string // Get object name.
Type() KeyType // Get key type.
Property() string // Get metadata (e.g., algorithm version).
Build() string // Reconstruct raw key string.
}

// DefaultKey implements default realization.
type DefaultKey struct {
name string // Object identifier.
keyType KeyType // Type of object (hash/signature/value).
property string // Additional metadata (version/algorithm).
raw string // Raw key string.
}

// NewDefaultKey returns new Key object.
func NewDefaultKey(name string, keytype KeyType, property string, raw string) DefaultKey {
return DefaultKey{
name: name,
keyType: keytype,
property: property,
raw: raw,
}
}

// Name returns name of the key.
func (k DefaultKey) Name() string {
return k.name
}

// Type returns type of the key.
func (k DefaultKey) Type() KeyType {
return k.keyType
}

// Property returns property of the key.
func (k DefaultKey) Property() string {
return k.property
}

// Build reconstructs key string.
func (k DefaultKey) Build() string {
return k.raw
}
52 changes: 52 additions & 0 deletions namer/key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package namer_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

const (
defaultName = "all"
defaultType = namer.KeyTypeHash
defaultProperty = "sha256"
defaultRaw = "/config/hash/sha256/all"
)

func TestNewDefaultKey(t *testing.T) {
t.Parallel()

a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw)
require.NotEmpty(t, a)
}

func TestDefaultKey_Build(t *testing.T) {
t.Parallel()

a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw)
require.Equal(t, defaultRaw, a.Build())
}

func TestDefaultKey_Name(t *testing.T) {
t.Parallel()

a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw)
assert.Equal(t, defaultName, a.Name())
}

func TestDefaultKey_Type(t *testing.T) {
t.Parallel()

a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw)
assert.Equal(t, defaultType, a.Type())
}

func TestDefaultKey_Property(t *testing.T) {
t.Parallel()

a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw)
assert.Equal(t, defaultProperty, a.Property())
}
Loading
Loading