diff options
| author | 2026-05-24 11:07:16 +0000 | |
|---|---|---|
| committer | 2026-05-24 11:09:59 +0000 | |
| commit | 36340918040627d93808c09dea8d9bd7b7457f82 (patch) | |
| tree | dab5fa0edbf2f2bf315d1fda73c0f7ac5c8fc6d9 /object/id/object_format_ops.go | |
| parent | internal/testgit: Add Algorithm method (diff) | |
| signature | No signature | |
object/id: Rename algorithm to object format
Diffstat (limited to 'object/id/object_format_ops.go')
| -rw-r--r-- | object/id/object_format_ops.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/object/id/object_format_ops.go b/object/id/object_format_ops.go new file mode 100644 index 00000000..76077235 --- /dev/null +++ b/object/id/object_format_ops.go @@ -0,0 +1,41 @@ +package id + +import "hash" + +// HexLen returns the encoded hexadecimal length. +func (objectFormat ObjectFormat) HexLen() int { + return objectFormat.Size() * 2 +} + +// Size returns the hash size in bytes. +func (objectFormat ObjectFormat) Size() int { + return objectFormat.details().size +} + +// New returns a new hash.Hash for this object format. +func (objectFormat ObjectFormat) New() (hash.Hash, error) { + newFn := objectFormat.details().new + if newFn == nil { + return nil, ErrInvalidObjectFormat + } + + return newFn(), nil +} + +// String returns the canonical object format name. +func (objectFormat ObjectFormat) String() string { + return objectFormat.details().name +} + +// Sum computes an object ID from raw data using the selected object format. +func (objectFormat ObjectFormat) Sum(data []byte) ObjectID { + return objectFormat.details().sum(data) +} + +// Zero returns the all-zero object ID for this object format. +func (objectFormat ObjectFormat) Zero() ObjectID { + return ObjectID{ + objectFormat: objectFormat, + data: [maxObjectIDSize]byte{}, + } +} |
