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