1
0
mirror of https://github.com/opencontainers/go-digest.git synced 2025-07-06 08:02:29 +03:00

digest: update package methods to reflect changes

We made a change to call the _hex_ portion the _encoded_ portion and
this makes a few updates to make that clearer for prospective users of
this package.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-04-25 12:46:22 -07:00
parent 5ab10f5714
commit 55f675811a
3 changed files with 31 additions and 13 deletions

View File

@ -125,6 +125,14 @@ func (a Algorithm) Hash() hash.Hash {
return algorithms[a].New()
}
// Encode encodes the raw bytes of a digest, typically from a hash.Hash, into
// the encoded portion of the digest.
func (a Algorithm) Encode(d []byte) string {
// TODO(stevvooe): Currently, all algorithms use a hex encoding. When we
// add support for back registration, we can modify this accordingly.
return fmt.Sprintf("%x", d)
}
// FromReader returns the digest of the reader using the algorithm.
func (a Algorithm) FromReader(rd io.Reader) (Digest, error) {
digester := a.Digester()