|
| 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 | + Raw() []byte // Get raw data. |
| 21 | + Build() string // Reconstruct raw key string. |
| 22 | +} |
| 23 | + |
| 24 | +// DefaultKey implements default realization. |
| 25 | +type DefaultKey struct { |
| 26 | + name string // Object identifier. |
| 27 | + keytype KeyType // Type of object (hash/signature/value). |
| 28 | + property string // Additional metadata (version/algorithm). |
| 29 | + raw []byte // Raw key string. |
| 30 | +} |
| 31 | + |
| 32 | +// NewDefaultKey returns new Key object. |
| 33 | +func NewDefaultKey(n string, k KeyType, p string, r []byte) DefaultKey { |
| 34 | + return DefaultKey{ |
| 35 | + name: n, |
| 36 | + keytype: k, |
| 37 | + property: p, |
| 38 | + raw: r, |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +// Name returns name of the key. |
| 43 | +func (k DefaultKey) Name() string { |
| 44 | + return k.name |
| 45 | +} |
| 46 | + |
| 47 | +// Type returns type of the key. |
| 48 | +func (k DefaultKey) Type() KeyType { |
| 49 | + return k.keytype |
| 50 | +} |
| 51 | + |
| 52 | +// Property returns property of the key. |
| 53 | +func (k DefaultKey) Property() string { |
| 54 | + return k.property |
| 55 | +} |
| 56 | + |
| 57 | +// Raw returns raw of the key. |
| 58 | +func (k DefaultKey) Raw() []byte { |
| 59 | + return k.raw |
| 60 | +} |
| 61 | + |
| 62 | +// Build should reconstruct key from signature and digest or not? |
| 63 | +func (k DefaultKey) Build() string { |
| 64 | + return string(k.raw) |
| 65 | +} |
| 66 | + |
| 67 | +// String returns string representation of the `raw` field. |
| 68 | +func (k DefaultKey) String() string { |
| 69 | + return string(k.raw) |
| 70 | +} |
0 commit comments