aboutsummaryrefslogtreecommitdiff
path: root/object/id/object_id_parse.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-05-24 11:07:16 +0000
committerGravatar Runxi Yu2026-05-24 11:09:59 +0000
commit36340918040627d93808c09dea8d9bd7b7457f82 (patch)
treedab5fa0edbf2f2bf315d1fda73c0f7ac5c8fc6d9 /object/id/object_id_parse.go
parentinternal/testgit: Add Algorithm method (diff)
signatureNo signature
object/id: Rename algorithm to object format
Diffstat (limited to 'object/id/object_id_parse.go')
-rw-r--r--object/id/object_id_parse.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/object/id/object_id_parse.go b/object/id/object_id_parse.go
index b8e7da68..59b6669c 100644
--- a/object/id/object_id_parse.go
+++ b/object/id/object_id_parse.go
@@ -5,36 +5,36 @@ import (
"fmt"
)
-// FromBytes builds an object ID from raw bytes for the specified algorithm.
-func FromBytes(algo Algorithm, b []byte) (ObjectID, error) {
+// 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 algo.Size() == 0 {
- return id, ErrInvalidAlgorithm
+ if objectFormat.Size() == 0 {
+ return id, ErrInvalidObjectFormat
}
- if len(b) != algo.Size() {
- return id, fmt.Errorf("%w: got %d bytes, expected %d", ErrInvalidObjectID, len(b), algo.Size())
+ 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.algo = algo
+ id.objectFormat = objectFormat
return id, nil
}
-// FromHex parses an object ID from hex for the specified algorithm.
-func FromHex(algo Algorithm, s string) (ObjectID, error) {
+// FromHex parses an object ID from hex for the specified object format.
+func FromHex(objectFormat ObjectFormat, s string) (ObjectID, error) {
var id ObjectID
- if algo.Size() == 0 {
- return id, ErrInvalidAlgorithm
+ 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) != algo.HexLen() {
- return id, fmt.Errorf("%w: got %d chars, expected %d", ErrInvalidObjectID, len(s), algo.HexLen())
+ 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)
@@ -43,7 +43,7 @@ func FromHex(algo Algorithm, s string) (ObjectID, error) {
}
copy(id.data[:], decoded)
- id.algo = algo
+ id.objectFormat = objectFormat
return id, nil
}