objectid

package
v0.1.172 Latest Latest
Warning

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

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

Documentation

Overview

Package objectid provides Git object IDs and object-ID 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

func Compare

func Compare(left, right ObjectID) int

Compare lexicographically compares two object IDs by their canonical byte representation.

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 ParseSignatureHeaderName added in v0.1.148

func ParseSignatureHeaderName(s string) (Algorithm, bool)

ParseSignatureHeaderName parses one canonical signature header name such as "gpgsig" or "gpgsig-sha256".

func SupportedAlgorithms

func SupportedAlgorithms() []Algorithm

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

func (Algorithm) EmptyTree added in v0.1.115

func (algo Algorithm) EmptyTree() ObjectID

EmptyTree returns the object ID of an empty tree ("tree 0\x00") for this algorithm.

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) PackHashID

func (algo Algorithm) PackHashID() uint32

PackHashID returns the Git pack/rev hash-id encoding for this algorithm.

Unknown algorithms return 0.

func (Algorithm) SignatureHeaderName added in v0.1.148

func (algo Algorithm) SignatureHeaderName() string

SignatureHeaderName returns the signature header name 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.

func (Algorithm) Zero added in v0.1.140

func (algo Algorithm) Zero() ObjectID

Zero returns the all-zero object ID for this 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.

Use Bytes when an independent copy is required.

Labels: Mut-Never.

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