doc.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019, 2020 OCI Contributors
  2. // Copyright 2017 Docker, Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // https://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // Package digest provides a generalized type to opaquely represent message
  16. // digests and their operations within the registry. The Digest type is
  17. // designed to serve as a flexible identifier in a content-addressable system.
  18. // More importantly, it provides tools and wrappers to work with
  19. // hash.Hash-based digests with little effort.
  20. //
  21. // Basics
  22. //
  23. // The format of a digest is simply a string with two parts, dubbed the
  24. // "algorithm" and the "digest", separated by a colon:
  25. //
  26. // <algorithm>:<digest>
  27. //
  28. // An example of a sha256 digest representation follows:
  29. //
  30. // sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
  31. //
  32. // The "algorithm" portion defines both the hashing algorithm used to calculate
  33. // the digest and the encoding of the resulting digest, which defaults to "hex"
  34. // if not otherwise specified. Currently, all supported algorithms have their
  35. // digests encoded in hex strings.
  36. //
  37. // In the example above, the string "sha256" is the algorithm and the hex bytes
  38. // are the "digest".
  39. //
  40. // Because the Digest type is simply a string, once a valid Digest is
  41. // obtained, comparisons are cheap, quick and simple to express with the
  42. // standard equality operator.
  43. //
  44. // Verification
  45. //
  46. // The main benefit of using the Digest type is simple verification against a
  47. // given digest. The Verifier interface, modeled after the stdlib hash.Hash
  48. // interface, provides a common write sink for digest verification. After
  49. // writing is complete, calling the Verifier.Verified method will indicate
  50. // whether or not the stream of bytes matches the target digest.
  51. //
  52. // Missing Features
  53. //
  54. // In addition to the above, we intend to add the following features to this
  55. // package:
  56. //
  57. // 1. A Digester type that supports write sink digest calculation.
  58. //
  59. // 2. Suspend and resume of ongoing digest calculations to support efficient digest verification in the registry.
  60. //
  61. package digest