Documentation
¶
Index ¶
- Constants
- func BlockCountForSourceSize(sourceSize uint64) uint64
- func ExpectedBlockSize(sourceSize, blockIndex uint64) (uint64, error)
- func IsCode(err error, code ErrorCode) bool
- func SeedOffset(blockIndex uint64) (uint64, error)
- func SeedSizeForBlockCount(blockCount uint64) (uint64, error)
- func SourceOffset(blockIndex uint64) (uint64, error)
- type BlockMatches
- type CreateSeedFileOptions
- type Digest
- func DigestFromBytes(value []byte) (Digest, error)
- func DigestFromHex(value string) (Digest, error)
- func HashSeed(ctx context.Context, seed io.Reader) (Digest, error)
- func NewDigest(value []byte) (Digest, error)
- func ParseDigestHex(value string) (Digest, error)
- func ReadBlockHash(ctx context.Context, seed io.ReaderAt, seedSize, blockIndex uint64) (Digest, error)
- func Sum256(value []byte) Digest
- func VerifyBlock(ctx context.Context, block []byte, expected Digest) (Digest, error)
- type Error
- type ErrorCode
- type SeedInfo
- func CreateSeed(ctx context.Context, source io.Reader, sink io.Writer) (SeedInfo, error)
- func CreateSeedFile(ctx context.Context, sourcePath, seedPath string, ...) (info SeedInfo, err error)
- func InspectSeed(ctx context.Context, seed io.Reader) (SeedInfo, error)
- func VerifySeed(ctx context.Context, seed io.Reader, expected Digest) (SeedInfo, error)
- func VerifySeedForSourceSize(ctx context.Context, seed io.Reader, expectedSeedHash Digest, ...) (SeedInfo, error)
- type VerifiedBlock
- type VerifyInfo
Constants ¶
const ( Format = "keymaster-seed-v1" BlockSize = 256 * 1024 DigestSize = 32 HashAlgorithm = "SHA-256" // Upper-case aliases mirror the protocol notation used in the public spec. FORMAT = Format BLOCK_SIZE = BlockSize DIGEST_SIZE = DigestSize HASH_ALGORITHM = HashAlgorithm )
V1 constants are part of the wire format and must not change within V1.
Variables ¶
This section is empty.
Functions ¶
func BlockCountForSourceSize ¶
BlockCountForSourceSize applies the V1 empty-file and aligned-file rules.
func ExpectedBlockSize ¶ added in v1.1.0
ExpectedBlockSize returns the protocol length of a block for a source of sourceSize bytes. Empty sources have no valid block indices.
func SeedOffset ¶
SeedOffset returns blockIndex*DIGEST_SIZE after checking overflow.
func SeedSizeForBlockCount ¶
SeedSizeForBlockCount checks the block-count multiplication used by callers that work with untrusted metadata.
func SourceOffset ¶
SourceOffset returns blockIndex*BLOCK_SIZE after checking overflow.
Types ¶
type BlockMatches ¶ added in v1.1.0
BlockMatches describes all occurrences of a digest in a trusted seed.
func FindBlockHash ¶ added in v1.1.0
func FindBlockHash(ctx context.Context, seed io.Reader, expectedSeedHash Digest, sourceSize uint64, blockHash Digest) (BlockMatches, error)
FindBlockHash scans a trusted seed once and returns the first/last indices and total count of an exact 32-byte digest match.
type CreateSeedFileOptions ¶
CreateSeedFileOptions controls atomic path publishing.
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is an immutable, fixed-size SHA-256 digest value.
func DigestFromBytes ¶
DigestFromBytes constructs a Digest only from exactly 32 bytes.
func DigestFromHex ¶
DigestFromHex is an alias for ParseDigestHex.
func NewDigest ¶
NewDigest is an alias for DigestFromBytes for callers that prefer a constructor-style name.
func ParseDigestHex ¶
ParseDigestHex parses exactly 64 hexadecimal characters. Whitespace and 0x prefixes are intentionally not accepted.
func ReadBlockHash ¶
func ReadBlockHash(ctx context.Context, seed io.ReaderAt, seedSize, blockIndex uint64) (Digest, error)
ReadBlockHash reads one raw digest from a random-access seed file.
func VerifyBlock ¶
VerifyBlock hashes one caller-provided block. A short block is accepted; an API caller needs source-length context to decide whether it is the last one.
type Error ¶
type Error struct {
Code ErrorCode
Message string
Cause error
Operation string
Path string
BlockIndex *uint64
BlockCount *uint64
SourceOffset *uint64
SeedSize *uint64
ExpectedSeedSize *uint64
ExpectedBlockCount *uint64
ActualBlockSize *uint64
Expected *Digest
Actual *Digest
}
Error is the structured error returned by the SDK. Context fields are optional and are populated only when relevant to the failure.
type ErrorCode ¶
type ErrorCode string
ErrorCode is stable across the Go and TypeScript SDKs.
const ( InvalidSeedLength ErrorCode = "INVALID_SEED_LENGTH" InvalidHashEncoding ErrorCode = "INVALID_HASH_ENCODING" SeedHashMismatch ErrorCode = "SEED_HASH_MISMATCH" BlockHashMismatch ErrorCode = "BLOCK_HASH_MISMATCH" SourceTooShort ErrorCode = "SOURCE_TOO_SHORT" SourceTooLong ErrorCode = "SOURCE_TOO_LONG" BlockIndexOutOfRange ErrorCode = "BLOCK_INDEX_OUT_OF_RANGE" IntegerOverflow ErrorCode = "INTEGER_OVERFLOW" TargetExists ErrorCode = "TARGET_EXISTS" ReadFailed ErrorCode = "READ_FAILED" WriteFailed ErrorCode = "WRITE_FAILED" Aborted ErrorCode = "ABORTED" InvalidArgument ErrorCode = "INVALID_ARGUMENT" SeedSizeMismatch ErrorCode = "SEED_SIZE_MISMATCH" BlockNotInSeed ErrorCode = "BLOCK_NOT_IN_SEED" BlockSizeMismatch ErrorCode = "BLOCK_SIZE_MISMATCH" )
type SeedInfo ¶
type SeedInfo struct {
Format string
BlockSize uint64
BlockCount uint64
SourceSize uint64
SourceSizeKnown bool
SeedSize uint64
SeedHash Digest
SeedHashHex string
}
SeedInfo describes a seed file. SourceSizeKnown is false for HashSeed and InspectSeed because a seed file does not encode source length.
func CreateSeed ¶
CreateSeed hashes source in protocol-sized blocks and writes raw 32-byte digests to sink. It never writes hexadecimal text to the sink.
func CreateSeedFile ¶
func CreateSeedFile(ctx context.Context, sourcePath, seedPath string, options CreateSeedFileOptions) (info SeedInfo, err error)
CreateSeedFile writes a seed beside the target, then publishes it. The default is no-overwrite; an incomplete seed is never left at seedPath.
func InspectSeed ¶
InspectSeed computes seed_hash and requires the seed length to be a multiple of the raw digest size.
func VerifySeed ¶
VerifySeed strictly inspects a seed and compares its raw-byte hash with the caller's expected digest using a constant-time comparison.
func VerifySeedForSourceSize ¶ added in v1.1.0
func VerifySeedForSourceSize(ctx context.Context, seed io.Reader, expectedSeedHash Digest, sourceSize uint64) (SeedInfo, error)
VerifySeedForSourceSize verifies seed structure, hash, and its digest count against a caller-provided source size in a single streaming pass.
type VerifiedBlock ¶ added in v1.1.0
VerifiedBlock identifies the first digest occurrence whose protocol block length agrees with the supplied block.
func VerifyBlockInSeed ¶ added in v1.1.0
func VerifyBlockInSeed(ctx context.Context, seed io.Reader, expectedSeedHash Digest, sourceSize uint64, block []byte) (VerifiedBlock, error)
VerifyBlockInSeed verifies membership and protocol block length in one seed pass. Seed integrity and source-size binding are checked before membership errors are returned.
type VerifyInfo ¶
VerifyInfo describes a successful complete source verification.
func VerifySource ¶
VerifySource validates every source block against the raw digests in seed, then checks that neither stream contains extra data.
func VerifySourceFile ¶
func VerifySourceFile(ctx context.Context, sourcePath, seedPath string, expected Digest) (VerifyInfo, error)
VerifySourceFile verifies the seed hash before reopening the seed for the complete source pass, so untrusted seed contents are not used unchecked.