Skip to content

Commit 9496be8

Browse files
patapenka-alexeybigbes
authored andcommitted
api: implement namer
Closes TNTP-4190
1 parent c36b4a8 commit 9496be8

File tree

9 files changed

+771
-48
lines changed

9 files changed

+771
-48
lines changed

hasher/hasher_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func TestSHA256Hasher(t *testing.T) {
6161
t.Parallel()
6262

6363
tests := []struct {
64-
name string
65-
in []byte
66-
out string
64+
name string
65+
in []byte
66+
expected string
6767
}{
6868
{"empty", []byte(""), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
6969
{"abc", []byte("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"},
@@ -77,7 +77,7 @@ func TestSHA256Hasher(t *testing.T) {
7777

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

80-
assert.Equal(t, test.out, hex.EncodeToString(result))
80+
assert.Equal(t, test.expected, hex.EncodeToString(result))
8181
})
8282
}
8383
}

kv/kv.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type KeyValue struct {
99
Key []byte
1010
// Value is the serialized representation of the value.
1111
Value []byte
12-
1312
// ModRevision is the revision number of the last modification to this key.
1413
ModRevision int64
1514
}

marshaller/marshaller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ var ErrUnmarshall = errors.New("failed to unmarshal")
1717
// implements one time for all objects.
1818
// Required for `integrity.Storage` to set marshalling format for any type object
1919
// and as recommendation for developers of `Storage` wrappers.
20-
type DefaultMarshaller interface {
20+
type DefaultMarshaller interface { //nolint:iface
2121
Marshal(data any) ([]byte, error)
2222
Unmarshal(data []byte, out any) error
2323
}
2424

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

3333
// YAMLMarshaller struct represent realization.
3434
type YAMLMarshaller struct{}
3535

3636
// NewYamlMarshaller creates new NewYamlMarshaller object.
37-
func NewYamlMarshaller() YAMLMarshaller {
37+
func NewYamlMarshaller() Marshallable {
3838
return YAMLMarshaller{}
3939
}
4040

namer/key.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package namer
2+
3+
// KeyType represents key types.
4+
type KeyType int
5+
6+
const (
7+
// KeyTypeValue represents data type.
8+
KeyTypeValue KeyType = iota + 1
9+
// KeyTypeHash represents hash of the data type.
10+
KeyTypeHash
11+
// KeyTypeSignature represents signature of the data type.
12+
KeyTypeSignature
13+
)
14+
15+
// Key defines the minimal interface required by keys.
16+
type Key interface {
17+
Name() string // Get object name.
18+
Type() KeyType // Get key type.
19+
Property() string // Get metadata (e.g., algorithm version).
20+
Build() string // Reconstruct raw key string.
21+
}
22+
23+
// DefaultKey implements default realization.
24+
type DefaultKey struct {
25+
name string // Object identifier.
26+
keyType KeyType // Type of object (hash/signature/value).
27+
property string // Additional metadata (version/algorithm).
28+
raw string // Raw key string.
29+
}
30+
31+
// NewDefaultKey returns new Key object.
32+
func NewDefaultKey(name string, keytype KeyType, property string, raw string) DefaultKey {
33+
return DefaultKey{
34+
name: name,
35+
keyType: keytype,
36+
property: property,
37+
raw: raw,
38+
}
39+
}
40+
41+
// Name returns name of the key.
42+
func (k DefaultKey) Name() string {
43+
return k.name
44+
}
45+
46+
// Type returns type of the key.
47+
func (k DefaultKey) Type() KeyType {
48+
return k.keyType
49+
}
50+
51+
// Property returns property of the key.
52+
func (k DefaultKey) Property() string {
53+
return k.property
54+
}
55+
56+
// Build reconstructs key string.
57+
func (k DefaultKey) Build() string {
58+
return k.raw
59+
}

0 commit comments

Comments
 (0)