Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package openpgp

import 
NewCanonicalTextHash reformats text written to it into the canonical form and then applies the hash h. See RFC 4880, section 5.2.1.
func ( hash.Hash) hash.Hash {
	return &canonicalTextHash{, 0}
}

type canonicalTextHash struct {
	h hash.Hash
	s int
}

var newline = []byte{'\r', '\n'}

func ( *canonicalTextHash) ( []byte) (int, error) {
	 := 0

	for ,  := range  {
		switch .s {
		case 0:
			if  == '\r' {
				.s = 1
			} else if  == '\n' {
				.h.Write([:])
				.h.Write(newline)
				 =  + 1
			}
		case 1:
			.s = 0
		}
	}

	.h.Write([:])
	return len(), nil
}

func ( *canonicalTextHash) ( []byte) []byte {
	return .h.Sum()
}

func ( *canonicalTextHash) () {
	.h.Reset()
	.s = 0
}

func ( *canonicalTextHash) () int {
	return .h.Size()
}

func ( *canonicalTextHash) () int {
	return .h.BlockSize()