From 36340918040627d93808c09dea8d9bd7b7457f82 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 24 May 2026 11:07:16 +0000 Subject: object/id: Rename algorithm to object format --- object/id/object_format_ops.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 object/id/object_format_ops.go (limited to 'object/id/object_format_ops.go') 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{}, + } +} -- cgit v1.3.1-10-gc9f91