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.
12 type recordingHash struct {
16 func (r recordingHash) Write(b []byte) (n int, err error) {
20 func (r recordingHash) Sum(in []byte) []byte {
21 return append(in, r.buf.Bytes()...)
24 func (r recordingHash) Reset() {
25 panic("shouldn't be called")
28 func (r recordingHash) Size() int {
29 panic("shouldn't be called")
32 func (r recordingHash) BlockSize() int {
33 panic("shouldn't be called")
36 func testCanonicalText(t *testing.T, input, expected string) {
37 r := recordingHash{bytes.NewBuffer(nil)}
38 c := NewCanonicalTextHash(r)
39 c.Write([]byte(input))
41 if expected != string(result) {
42 t.Errorf("input: %x got: %x want: %x", input, result, expected)
46 func TestCanonicalText(t *testing.T) {
47 testCanonicalText(t, "foo\n", "foo\r\n")
48 testCanonicalText(t, "foo", "foo")
49 testCanonicalText(t, "foo\r\n", "foo\r\n")
50 testCanonicalText(t, "foo\r\nbar", "foo\r\nbar")
51 testCanonicalText(t, "foo\r\nbar\n\n", "foo\r\nbar\r\n\r\n")