gittuf/pkg/gitinterface/hash.go
Paulo Gomes 4a53c1b214
refactor: standardize on githash.Hash
Signed-off-by: Paulo Gomes <paulo@entire.io>
2026-08-03 21:27:52 +01:00

46 lines
1.3 KiB
Go

// Copyright The gittuf Authors
// SPDX-License-Identifier: Apache-2.0
package gitinterface
import (
"github.com/gittuf/gittuf/pkg/githash"
)
const (
GitBlobHashName = "gitBlob"
SHA256HashName = "sha256"
)
var (
ErrInvalidHashEncoding = githash.ErrInvalidHashEncoding
ErrInvalidHashLength = githash.ErrInvalidHashLength
)
// Hash represents a Git object hash.
//
// Deprecated: use githash.Hash.
type Hash = githash.Hash
// ZeroHash represents an empty SHA-1 Hash. It is safe to use as an
// error-return sentinel and in comparisons via Hash.IsZero (which matches both
// SHA-1 and SHA-256 zero hashes). When the value is passed to Git or compared
// against a Git-produced ID, prefer Repository.ZeroHash, which returns the zero
// hash matching the repository's object format.
var ZeroHash = githash.ZeroHash
// ZeroHash returns the all-zeroes Hash for the repository's object format. Git
// uses this value to denote, for example, the absence of a previous value when
// creating or deleting a reference.
func (r *Repository) ZeroHash() Hash {
if r.objectFormat == ObjectFormatSHA256 {
return githash.ZeroHashSHA256
}
return githash.ZeroHash
}
// NewHash returns a Hash object after ensuring the input string is correctly
// encoded.
func NewHash(h string) (Hash, error) {
return githash.NewHash(h)
}