objectid

package
v0.1.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package objectid provides utilities around object IDs and hash algorithms.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAlgorithm indicates an unsupported object ID algorithm.
	ErrInvalidAlgorithm = errors.New("objectid: invalid algorithm")
	// ErrInvalidObjectID indicates malformed object ID data.
	ErrInvalidObjectID = errors.New("objectid: invalid object id")
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm uint8

Algorithm identifies the hash algorithm used for Git object IDs.

const (
	AlgorithmUnknown Algorithm = iota
	AlgorithmSHA1
	AlgorithmSHA256
)

func ParseAlgorithm

func ParseAlgorithm(s string) (Algorithm, bool)

ParseAlgorithm parses a canonical algorithm name (e.g. "sha1", "sha256").

func SupportedAlgorithms

func SupportedAlgorithms() []Algorithm

SupportedAlgorithms returns all object ID algorithms supported by furgit. Do not mutate.

func (Algorithm) HexLen

func (algo Algorithm) HexLen() int

HexLen returns the encoded hexadecimal length.

func (Algorithm) New

func (algo Algorithm) New() (hash.Hash, error)

New returns a new hash.Hash for this algorithm.

func (Algorithm) Size

func (algo Algorithm) Size() int

Size returns the hash size in bytes.

func (Algorithm) String

func (algo Algorithm) String() string

String returns the canonical algorithm name.

func (Algorithm) Sum

func (algo Algorithm) Sum(data []byte) ObjectID

Sum computes an object ID from raw data using the selected algorithm.

type ObjectID

type ObjectID struct {
	// contains filtered or unexported fields
}

ObjectID represents a Git object ID.

func FromBytes

func FromBytes(algo Algorithm, b []byte) (ObjectID, error)

FromBytes builds an object ID from raw bytes for the specified algorithm.

func ParseHex

func ParseHex(algo Algorithm, s string) (ObjectID, error)

ParseHex parses an object ID from hex for the specified algorithm.

func (ObjectID) Algorithm

func (id ObjectID) Algorithm() Algorithm

Algorithm returns the object ID's hash algorithm.

func (ObjectID) Bytes

func (id ObjectID) Bytes() []byte

Bytes returns a copy of the object ID bytes.

func (*ObjectID) RawBytes

func (id *ObjectID) RawBytes() []byte

RawBytes returns a direct byte slice view of the object ID bytes.

The returned slice aliases the object ID's internal storage. Callers MUST treat it as read-only and MUST NOT modify its contents.

Use Bytes when an independent copy is required.

func (ObjectID) Size

func (id ObjectID) Size() int

Size returns the object ID size in bytes.

func (ObjectID) String

func (id ObjectID) String() string

String returns the canonical hex representation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL