...
1
2
3
4
5
6
7 package crc
8
9 import (
10 "hash"
11 "hash/crc32"
12 )
13
14
15 const Size = 4
16
17 type digest struct {
18 crc uint32
19 tab *crc32.Table
20 }
21
22
23
24
25 func New(prev uint32, tab *crc32.Table) hash.Hash32 { return &digest{prev, tab} }
26
27 func (d *digest) Size() int { return Size }
28
29 func (d *digest) BlockSize() int { return 1 }
30
31 func (d *digest) Reset() { d.crc = 0 }
32
33 func (d *digest) Write(p []byte) (n int, err error) {
34 d.crc = crc32.Update(d.crc, d.tab, p)
35 return len(p), nil
36 }
37
38 func (d *digest) Sum32() uint32 { return d.crc }
39
40 func (d *digest) Sum(in []byte) []byte {
41 s := d.Sum32()
42 return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s))
43 }
44
View as plain text