-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.go
52 lines (43 loc) · 756 Bytes
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package otp
import (
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"hash"
)
type Hash uint8
const (
HashSHA1 Hash = iota + 1
HashSHA256
HashSHA512
)
// String returns the representation of hash in string.
func (h Hash) String() string {
switch h {
case HashSHA1:
return "SHA1"
case HashSHA256:
return "SHA256"
}
return "SHA512"
}
// Size returns the size of a checksum for hash in bytes.
func (h Hash) Size() int {
switch h {
case HashSHA1:
return sha1.Size
case HashSHA256:
return sha256.Size
}
return sha512.Size
}
// Hash returns [hash.Hash], computing checksum for hash.
func (h Hash) Hash() hash.Hash {
switch h {
case HashSHA1:
return sha1.New()
case HashSHA256:
return sha256.New()
}
return sha512.New()
}