1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // NewCanonicalTextHash reformats text written to it into the canonical
10 // form and then applies the hash h. See RFC 4880, section 5.2.1.
11 func NewCanonicalTextHash(h hash.Hash) hash.Hash {
12 return &canonicalTextHash{h, 0}
15 type canonicalTextHash struct {
20 var newline = []byte{'\r', '\n'}
22 func (cth *canonicalTextHash) Write(buf []byte) (int, error) {
25 for i, c := range buf {
31 cth.h.Write(buf[start:i])
40 cth.h.Write(buf[start:])
44 func (cth *canonicalTextHash) Sum(in []byte) []byte {
48 func (cth *canonicalTextHash) Reset() {
53 func (cth *canonicalTextHash) Size() int {
57 func (cth *canonicalTextHash) BlockSize() int {
58 return cth.h.BlockSize()