Skip to content
Draft
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
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
70 changes: 70 additions & 0 deletions namer/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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).
Raw() []byte // Get raw data.
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 []byte // Raw key string.
}

// NewDefaultKey returns new Key object.
func NewDefaultKey(n string, k KeyType, p string, r []byte) DefaultKey {
return DefaultKey{
name: n,
keytype: k,
property: p,
raw: r,
}
}

// 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
}

// Raw returns raw of the key.
func (k DefaultKey) Raw() []byte {
return k.raw
}

// Build should reconstruct key from signature and digest or not?
func (k DefaultKey) Build() string {
return string(k.raw)
}

// String returns string representation of the `raw` field.
func (k DefaultKey) String() string {
return string(k.raw)
}
Loading
Loading