• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

digestset/H14-May-2020-

releases/H14-May-2020-

.mailmapH A D14-May-2020228

.pullapprove.ymlH A D14-May-2020444

.travis.ymlH A D14-May-202050

CONTRIBUTING.mdH A D14-May-20202.9 KiB

LICENSEH A D14-May-202010.5 KiB

LICENSE.docsH A D14-May-202019.5 KiB

MAINTAINERSH A D14-May-2020253

README.mdH A D14-May-20204.1 KiB

algorithm.goH A D14-May-20205.7 KiB

algorithm_test.goH A D14-May-20202.6 KiB

digest.goH A D14-May-20204.8 KiB

digest_test.goH A D14-May-20204.1 KiB

digester.goH A D14-May-20201.2 KiB

doc.goH A D14-May-20202.5 KiB

go.modH A D14-May-202052

verifiers.goH A D14-May-20201.3 KiB

verifiers_test.goH A D14-May-20202 KiB

README.md

1# go-digest
2
3[![GoDoc](https://godoc.org/github.com/opencontainers/go-digest?status.svg)](https://godoc.org/github.com/opencontainers/go-digest) [![Go Report Card](https://goreportcard.com/badge/github.com/opencontainers/go-digest)](https://goreportcard.com/report/github.com/opencontainers/go-digest) [![Build Status](https://travis-ci.org/opencontainers/go-digest.svg?branch=master)](https://travis-ci.org/opencontainers/go-digest)
4
5Common digest package used across the container ecosystem.
6
7Please see the [godoc](https://godoc.org/github.com/opencontainers/go-digest) for more information.
8
9# What is a digest?
10
11A digest is just a [hash](https://en.wikipedia.org/wiki/Hash_function).
12
13The most common use case for a digest is to create a content identifier for use in [Content Addressable Storage](https://en.wikipedia.org/wiki/Content-addressable_storage) systems:
14
15```go
16id := digest.FromBytes([]byte("my content"))
17```
18
19In the example above, the id can be used to uniquely identify the byte slice "my content".
20This allows two disparate applications to agree on a verifiable identifier without having to trust one another.
21
22An identifying digest can be verified, as follows:
23
24```go
25if id != digest.FromBytes([]byte("my content")) {
26  return errors.New("the content has changed!")
27}
28```
29
30A `Verifier` type can be used to handle cases where an `io.Reader` makes more sense:
31
32```go
33rd := getContent()
34verifier := id.Verifier()
35io.Copy(verifier, rd)
36
37if !verifier.Verified() {
38  return errors.New("the content has changed!")
39}
40```
41
42Using [Merkle DAGs](https://en.wikipedia.org/wiki/Merkle_tree), this can power a rich, safe, content distribution system.
43
44# Usage
45
46While the [godoc](https://godoc.org/github.com/opencontainers/go-digest) is considered the best resource, a few important items need to be called out when using this package.
47
481. Make sure to import the hash implementations into your application or the package will panic.
49    You should have something like the following in the main (or other entrypoint) of your application:
50
51    ```go
52    import (
53        _ "crypto/sha256"
54        _ "crypto/sha512"
55    )
56    ```
57    This may seem inconvenient but it allows you replace the hash
58    implementations with others, such as https://github.com/stevvooe/resumable.
59
602. Even though `digest.Digest` may be assemblable as a string, _always_ verify your input with `digest.Parse` or use `Digest.Validate` when accepting untrusted input.
61    While there are measures to avoid common problems, this will ensure you have valid digests in the rest of your application.
62
633. While alternative encodings of hash values (digests) are possible (for example, base64), this package deals exclusively with hex-encoded digests.
64
65# Stability
66
67The Go API, at this stage, is considered stable, unless otherwise noted.
68
69As always, before using a package export, read the [godoc](https://godoc.org/github.com/opencontainers/go-digest).
70
71# Contributing
72
73This package is considered fairly complete.
74It has been in production in thousands (millions?) of deployments and is fairly battle-hardened.
75New additions will be met with skepticism.
76If you think there is a missing feature, please file a bug clearly describing the problem and the alternatives you tried before submitting a PR.
77
78## Code of Conduct
79
80Participation in the OpenContainers community is governed by [OpenContainer's Code of Conduct][code-of-conduct].
81
82## Security
83
84If you find an issue, please follow the [security][security] protocol to report it.
85
86# Copyright and license
87
88Copyright © 2019, 2020 OCI Contributors
89Copyright © 2016 Docker, Inc.
90All rights reserved, except as follows.
91Code is released under the [Apache 2.0 license](LICENSE).
92This `README.md` file and the [`CONTRIBUTING.md`](CONTRIBUTING.md) file are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file [`LICENSE.docs`](LICENSE.docs).
93You may obtain a duplicate copy of the same license, titled CC BY-SA 4.0, at http://creativecommons.org/licenses/by-sa/4.0/.
94
95[security]: https://github.com/opencontainers/org/blob/master/security
96[code-of-conduct]: https://github.com/opencontainers/org/blob/master/CODE_OF_CONDUCT.md
97