-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigest_method_enum.go
65 lines (58 loc) · 1.5 KB
/
digest_method_enum.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package xmldsig
import (
"crypto"
"hash"
)
type DigestMethodEnum int
const (
DigestMethod_SHA1 DigestMethodEnum = iota
DigestMethod_SHA256
DigestMethod_SHA384
DigestMethod_SHA512
)
func (d DigestMethodEnum) GetUri() string {
switch d {
case DigestMethod_SHA1:
return "http://www.w3.org/2000/09/xmldsig#sha1"
case DigestMethod_SHA256:
return "http://www.w3.org/2001/04/xmlenc#sha256"
case DigestMethod_SHA384:
return "http://www.w3.org/2001/04/xmldsig-more#sha384"
case DigestMethod_SHA512:
return "http://www.w3.org/2001/04/xmlenc#sha512"
}
return ""
}
func (d DigestMethodEnum) GetHashAlgorithm() (crypto.Hash, error) {
switch d {
case DigestMethod_SHA1:
return crypto.SHA1, nil
case DigestMethod_SHA256:
return crypto.SHA256, nil
case DigestMethod_SHA384:
return crypto.SHA384, nil
case DigestMethod_SHA512:
return crypto.SHA512, nil
}
return 0, ErrInvalidDigestMethod
}
func (d DigestMethodEnum) CreateHashAlgorithm() (hash.Hash, error) {
hash, err := d.GetHashAlgorithm()
if err != nil {
return nil, err
}
return hash.New(), nil
}
func GetDigestMethod(uri string) (DigestMethodEnum, error) {
switch uri {
case "http://www.w3.org/2000/09/xmldsig#sha1":
return DigestMethod_SHA1, nil
case "http://www.w3.org/2001/04/xmlenc#sha256":
return DigestMethod_SHA256, nil
case "http://www.w3.org/2001/04/xmldsig-more#sha384":
return DigestMethod_SHA384, nil
case "http://www.w3.org/2001/04/xmlenc#sha512":
return DigestMethod_SHA512, nil
}
return 0, ErrInvalidDigestMethod
}