talira

go-digest

Content digests for Go, as used across the container ecosystem

open sourceApache-2.0free

go-digest is the Open Container Initiative's Go package for content digests: hex-encoded hashes such as sha256:... used as content identifiers in content-addressable storage, container images and registries. It creates digests from bytes or readers, parses and validates digest strings from untrusted input, and verifies content as it streams through a Verifier. Its makers call it fairly complete and stable.

Problems it solves

  • compute and verify a sha256 content digest in Go the way container registries do
  • validate an untrusted sha256:... digest string in a Go service
  • check that a downloaded blob matches its expected digest while streaming it

Features

  • digests from byte slices and io.Readers
  • parsing and validation of algorithm:hex digest strings
  • streaming verification of content against a digest
  • hash implementations you import yourself, so they can be replaced

Limitations

  • The program must import the hash implementations it uses (crypto/sha256, crypto/sha512) or the package panics.1
  • Handles hex-encoded digests only, not base64 or other encodings.1