func NewDigestVerifier(d Digest) (Verifier, error) {
	if err := d.Validate(); err != nil {
		return nil, err
	}

	alg := d.Algorithm()
	switch alg {
	case "sha256", "sha384", "sha512":
		return hashVerifier{
			hash:   alg.Hash(),
			digest: d,
		}, nil
	default:
		// Assume we have a tarsum.
		version, err := tarsum.GetVersionFromTarsum(string(d))
		if err != nil {
			return nil, err
		}

		pr, pw := io.Pipe()

		// TODO(stevvooe): We may actually want to ban the earlier versions of
		// tarsum. That decision may not be the place of the verifier.

		ts, err := tarsum.NewTarSum(pr, true, version)
		if err != nil {
			return nil, err
		}

		// TODO(sday): Ick! A goroutine per digest verification? We'll have to
		// get the tarsum library to export an io.Writer variant.
		go func() {
			if _, err := io.Copy(ioutil.Discard, ts); err != nil {
				pr.CloseWithError(err)
			} else {
				pr.Close()
			}
		}()

		return &tarsumVerifier{
			digest: d,
			ts:     ts,
			pr:     pr,
			pw:     pw,
		}, nil
	}
}
// NewDigestVerifier returns a verifier that compares the written bytes
// against a passed in digest.
NewDigestVerifier returns a verifier that compares the written bytes
against a passed in digest.
// NewDigestVerifier returns a verifier that compares the written bytes // against a passed in digest .
func NewDigestVerifier(d Digest) (Verifier, error) {
	if err := d.Validate(); err != nil {
		return nil, err
	}
	alg := d.Algorithm()
	switch alg {
	case "sha256", "sha384", "sha512":
		return hashVerifier{
			hash:   alg.Hash(),
			digest: d,
		}, nil
	default:
		version, err := tarsum.GetVersionFromTarsum(string(d))
		if err != nil {
			return nil, err
		}
		pr, pw := io.Pipe()
		ts, err := tarsum.NewTarSum(pr, true, version)
		if err != nil {
			return nil, err
		}
		go func() {
			if _, err := io.Copy(ioutil.Discard, ts); err != nil {
				pr.CloseWithError(err)
			} else {
				pr.Close()
			}
		}()
		return &tarsumVerifier{
			digest: d,
			ts:     ts,
			pr:     pr,
			pw:     pw,
		}, nil
	}
}
func NewDigestVerifier ( d Digest ) ( Verifier , error ) { if err := d . Validate ( ) ; err != nil { return nil , err } alg := d . Algorithm ( ) switch alg { case " " , " " , " " : return hashVerifier { hash : alg . Hash ( ) , digest : d , } , nil default : version , err := tarsum . GetVersionFromTarsum ( string ( d ) ) if err != nil { return nil , err } pr , pw := io . Pipe ( ) ts , err := tarsum . NewTarSum ( pr , true , version ) if err != nil { return nil , err } go func ( ) { if _ , err := io . Copy ( ioutil . Discard , ts ) ; err != nil { pr . CloseWithError ( err ) } else { pr . Close ( ) } } ( ) return & tarsumVerifier { digest : d , ts : ts , pr : pr , pw : pw , } , nil } }
NewDigestVerifier returns a verifier that compares the written bytes
against a passed in digest.
NewDigestVerifier returns a verifier that compares the written bytes against a passed in digest .
// Assume we have a tarsum. // TODO(stevvooe): We may actually want to ban the earlier versions of // tarsum. That decision may not be the place of the verifier. // TODO(sday): Ick! A goroutine per digest verification? We'll have to // get the tarsum library to export an io.Writer variant.