forked from Shiloh/githaven
86e2789960
* update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-git/go-billy/v5 * update github.com/go-git/go-git/v5 * update github.com/go-redis/redis/v8 * update github.com/go-testfixtures/testfixtures/v3 * update github.com/jaytaylor/html2text * update github.com/json-iterator/go * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mattn/go-isatty * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/prometheus/client_golang * update github.com/unrolled/render * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark * update github.com/yuin/goldmark-highlighting Co-authored-by: techknowlogick <techknowlogick@gitea.io>
66 lines
1.2 KiB
Go
Vendored
66 lines
1.2 KiB
Go
Vendored
// 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 (
|
|
"hash"
|
|
"io"
|
|
)
|
|
|
|
// NewCanonicalTextHash reformats text written to it into the canonical
|
|
// form and then applies the hash h. See RFC 4880, section 5.2.1.
|
|
func NewCanonicalTextHash(h hash.Hash) hash.Hash {
|
|
return &canonicalTextHash{h, 0}
|
|
}
|
|
|
|
type canonicalTextHash struct {
|
|
h hash.Hash
|
|
s int
|
|
}
|
|
|
|
var newline = []byte{'\r', '\n'}
|
|
|
|
func writeCanonical(cw io.Writer, buf []byte, s *int) (int, error) {
|
|
start := 0
|
|
for i, c := range buf {
|
|
switch *s {
|
|
case 0:
|
|
if c == '\r' {
|
|
*s = 1
|
|
} else if c == '\n' {
|
|
cw.Write(buf[start:i])
|
|
cw.Write(newline)
|
|
start = i + 1
|
|
}
|
|
case 1:
|
|
*s = 0
|
|
}
|
|
}
|
|
|
|
cw.Write(buf[start:])
|
|
return len(buf), nil
|
|
}
|
|
|
|
func (cth *canonicalTextHash) Write(buf []byte) (int, error) {
|
|
return writeCanonical(cth.h, buf, &cth.s)
|
|
}
|
|
|
|
func (cth *canonicalTextHash) Sum(in []byte) []byte {
|
|
return cth.h.Sum(in)
|
|
}
|
|
|
|
func (cth *canonicalTextHash) Reset() {
|
|
cth.h.Reset()
|
|
cth.s = 0
|
|
}
|
|
|
|
func (cth *canonicalTextHash) Size() int {
|
|
return cth.h.Size()
|
|
}
|
|
|
|
func (cth *canonicalTextHash) BlockSize() int {
|
|
return cth.h.BlockSize()
|
|
}
|