aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/ulikunitz/xz/crc.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/crc.go')
-rw-r--r--vendor/github.com/ulikunitz/xz/crc.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/crc.go b/vendor/github.com/ulikunitz/xz/crc.go
new file mode 100644
index 0000000..b44dca9
--- /dev/null
+++ b/vendor/github.com/ulikunitz/xz/crc.go
@@ -0,0 +1,54 @@
1// Copyright 2014-2017 Ulrich Kunitz. 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
5package xz
6
7import (
8 "hash"
9 "hash/crc32"
10 "hash/crc64"
11)
12
13// crc32Hash implements the hash.Hash32 interface with Sum returning the
14// crc32 value in little-endian encoding.
15type crc32Hash struct {
16 hash.Hash32
17}
18
19// Sum returns the crc32 value as little endian.
20func (h crc32Hash) Sum(b []byte) []byte {
21 p := make([]byte, 4)
22 putUint32LE(p, h.Hash32.Sum32())
23 b = append(b, p...)
24 return b
25}
26
27// newCRC32 returns a CRC-32 hash that returns the 64-bit value in
28// little-endian encoding using the IEEE polynomial.
29func newCRC32() hash.Hash {
30 return crc32Hash{Hash32: crc32.NewIEEE()}
31}
32
33// crc64Hash implements the Hash64 interface with Sum returning the
34// CRC-64 value in little-endian encoding.
35type crc64Hash struct {
36 hash.Hash64
37}
38
39// Sum returns the CRC-64 value in little-endian encoding.
40func (h crc64Hash) Sum(b []byte) []byte {
41 p := make([]byte, 8)
42 putUint64LE(p, h.Hash64.Sum64())
43 b = append(b, p...)
44 return b
45}
46
47// crc64Table is used to create a CRC-64 hash.
48var crc64Table = crc64.MakeTable(crc64.ECMA)
49
50// newCRC64 returns a CRC-64 hash that returns the 64-bit value in
51// little-endian encoding using the ECMA polynomial.
52func newCRC64() hash.Hash {
53 return crc64Hash{Hash64: crc64.New(crc64Table)}
54}