~sinzui/ubuntu/wily/juju-core/wily-1.24.7

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/openpgp/canonical_text.go

  • Committer: Package Import Robot
  • Author(s): Oleg Strikov
  • Date: 2015-03-26 15:54:39 UTC
  • mfrom: (1.1.32)
  • Revision ID: package-import@ubuntu.com-20150326155439-ot7bwwyoomq13btm
Tags: 1.22.0-0ubuntu1
* New upstream release (LP: #1416051).
* d/patches/fix-detect-new-release.patch: Added upstream patch to redeem
  the ability to handle future Ubuntu releases (LP: #1427879, #1434092).
* d/tests/fake-future.sh: New ability to generate fake /etc/os-release.
* d/copyright: Updated to reflect changes in the codebase.
* d/control:
  - Change build dependency from gccgo to gccgo-go.
  - Use either cloud-image-utils or cloud-utils as dependency for juju-local
    because cloud-image-utils is not available on precise.
  - Compliance to Debian Policy 3.9.6 was declared.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
package openpgp
 
6
 
 
7
import "hash"
 
8
 
 
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}
 
13
}
 
14
 
 
15
type canonicalTextHash struct {
 
16
        h hash.Hash
 
17
        s int
 
18
}
 
19
 
 
20
var newline = []byte{'\r', '\n'}
 
21
 
 
22
func (cth *canonicalTextHash) Write(buf []byte) (int, error) {
 
23
        start := 0
 
24
 
 
25
        for i, c := range buf {
 
26
                switch cth.s {
 
27
                case 0:
 
28
                        if c == '\r' {
 
29
                                cth.s = 1
 
30
                        } else if c == '\n' {
 
31
                                cth.h.Write(buf[start:i])
 
32
                                cth.h.Write(newline)
 
33
                                start = i + 1
 
34
                        }
 
35
                case 1:
 
36
                        cth.s = 0
 
37
                }
 
38
        }
 
39
 
 
40
        cth.h.Write(buf[start:])
 
41
        return len(buf), nil
 
42
}
 
43
 
 
44
func (cth *canonicalTextHash) Sum(in []byte) []byte {
 
45
        return cth.h.Sum(in)
 
46
}
 
47
 
 
48
func (cth *canonicalTextHash) Reset() {
 
49
        cth.h.Reset()
 
50
        cth.s = 0
 
51
}
 
52
 
 
53
func (cth *canonicalTextHash) Size() int {
 
54
        return cth.h.Size()
 
55
}
 
56
 
 
57
func (cth *canonicalTextHash) BlockSize() int {
 
58
        return cth.h.BlockSize()
 
59
}