-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature_method_enum.go
80 lines (72 loc) · 2.1 KB
/
signature_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package xmldsig
import (
"crypto"
"crypto/x509"
"hash"
)
type SignatureMethodEnum int
const (
SignatureMethod_RSA_SHA1 SignatureMethodEnum = iota
SignatureMethod_RSA_SHA256
SignatureMethod_RSA_SHA384
SignatureMethod_RSA_SHA512
)
func (s SignatureMethodEnum) GetUri() string {
switch s {
case SignatureMethod_RSA_SHA1:
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
case SignatureMethod_RSA_SHA256:
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
case SignatureMethod_RSA_SHA384:
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
case SignatureMethod_RSA_SHA512:
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
}
return ""
}
func (s SignatureMethodEnum) GetHashAlgorithm() (crypto.Hash, error) {
switch s {
case SignatureMethod_RSA_SHA1:
return crypto.SHA1, nil
case SignatureMethod_RSA_SHA256:
return crypto.SHA256, nil
case SignatureMethod_RSA_SHA384:
return crypto.SHA384, nil
case SignatureMethod_RSA_SHA512:
return crypto.SHA512, nil
}
return 0, ErrInvalidSignatureMethod
}
func (s SignatureMethodEnum) CreateHashAlgorithm() (hash.Hash, error) {
hash, err := s.GetHashAlgorithm()
if err != nil {
return nil, err
}
return hash.New(), nil
}
func (s SignatureMethodEnum) GetSignatureAlgorithm() (x509.SignatureAlgorithm, error) {
switch s {
case SignatureMethod_RSA_SHA1:
return x509.SHA1WithRSA, nil
case SignatureMethod_RSA_SHA256:
return x509.SHA256WithRSA, nil
case SignatureMethod_RSA_SHA384:
return x509.SHA384WithRSA, nil
case SignatureMethod_RSA_SHA512:
return x509.SHA512WithRSA, nil
}
return 0, ErrInvalidSignatureMethod
}
func GetSignatureMethod(uri string) (SignatureMethodEnum, error) {
switch uri {
case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
return SignatureMethod_RSA_SHA1, nil
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":
return SignatureMethod_RSA_SHA256, nil
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384":
return SignatureMethod_RSA_SHA384, nil
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":
return SignatureMethod_RSA_SHA512, nil
}
return 0, ErrInvalidSignatureMethod
}