helpers.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2016 The Linux Foundation
  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. // http://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 identity
  15. import (
  16. _ "crypto/sha256" // side-effect to install impls, sha256
  17. _ "crypto/sha512" // side-effect to install impls, sha384/sh512
  18. "io"
  19. digest "github.com/opencontainers/go-digest"
  20. )
  21. // FromReader consumes the content of rd until io.EOF, returning canonical
  22. // digest.
  23. func FromReader(rd io.Reader) (digest.Digest, error) {
  24. return digest.Canonical.FromReader(rd)
  25. }
  26. // FromBytes digests the input and returns a Digest.
  27. func FromBytes(p []byte) digest.Digest {
  28. return digest.Canonical.FromBytes(p)
  29. }
  30. // FromString digests the input and returns a Digest.
  31. func FromString(s string) digest.Digest {
  32. return digest.Canonical.FromString(s)
  33. }