diff options
| author | 2026-05-30 05:13:09 +0000 | |
|---|---|---|
| committer | 2026-05-30 05:13:54 +0000 | |
| commit | 86a2a381cd99fcceef24587d95cddbe94c149482 (patch) | |
| tree | 177837c9c72be3376c1f6e91670fa66c61512b4f /object/id/object_id_parse.go | |
| parent | ci: Simplify with a local script (diff) | |
| signature | No signature | |
object/id: Parse should belong to object format next
Diffstat (limited to 'object/id/object_id_parse.go')
| -rw-r--r-- | object/id/object_id_parse.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/object/id/object_id_parse.go b/object/id/object_id_parse.go deleted file mode 100644 index 59b6669c..00000000 --- a/object/id/object_id_parse.go +++ /dev/null @@ -1,49 +0,0 @@ -package id - -import ( - "encoding/hex" - "fmt" -) - -// FromBytes builds an object ID from raw bytes for the specified object format. -func FromBytes(objectFormat ObjectFormat, b []byte) (ObjectID, error) { - var id ObjectID - if objectFormat.Size() == 0 { - return id, ErrInvalidObjectFormat - } - - if len(b) != objectFormat.Size() { - return id, fmt.Errorf("%w: got %d bytes, expected %d", ErrInvalidObjectID, len(b), objectFormat.Size()) - } - - copy(id.data[:], b) - id.objectFormat = objectFormat - - return id, nil -} - -// FromHex parses an object ID from hex for the specified object format. -func FromHex(objectFormat ObjectFormat, s string) (ObjectID, error) { - var id ObjectID - if objectFormat.Size() == 0 { - return id, ErrInvalidObjectFormat - } - - if len(s)%2 != 0 { - return id, fmt.Errorf("%w: odd hex length %d", ErrInvalidObjectID, len(s)) - } - - if len(s) != objectFormat.HexLen() { - return id, fmt.Errorf("%w: got %d chars, expected %d", ErrInvalidObjectID, len(s), objectFormat.HexLen()) - } - - decoded, err := hex.DecodeString(s) - if err != nil { - return id, fmt.Errorf("%w: decode: %w", ErrInvalidObjectID, err) - } - - copy(id.data[:], decoded) - id.objectFormat = objectFormat - - return id, nil -} |
