digester.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 Docker, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package digest
  15. import "hash"
  16. // Digester calculates the digest of written data. Writes should go directly
  17. // to the return value of Hash, while calling Digest will return the current
  18. // value of the digest.
  19. type Digester interface {
  20. Hash() hash.Hash // provides direct access to underlying hash instance.
  21. Digest() Digest
  22. }
  23. // digester provides a simple digester definition that embeds a hasher.
  24. type digester struct {
  25. alg Algorithm
  26. hash hash.Hash
  27. }
  28. func (d *digester) Hash() hash.Hash {
  29. return d.hash
  30. }
  31. func (d *digester) Digest() Digest {
  32. return NewDigest(d.alg, d.hash)
  33. }