This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
64 lines (61 loc) · 3.64 KB
/
errors.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
package httpsignatures
import (
"net/http"
"strings"
)
var (
ErrorNoAlgorithmConfigured = "No algorithm configured"
ErrorNoKeyIDConfigured = "No keyID configured"
ErrorMissingRequiredHeader = "Missing required header"
ErrorMissingSignatureParameterSignature = "Missing signature parameter 'signature'"
ErrorMissingSignatureParameterAlgorithm = "Missing signature parameter 'algorithm'"
ErrorMissingSignatureParameterKeyId = "Missing signature parameter 'keyId'"
ErrorNoSignatureHeaderFoundInRequest = "No Signature header found in request"
ErrorURLNotInRequest = "URL not in Request"
ErrorMethodNotInRequest = "Method not in Request"
ErrorSignaturesDoNotMatch = "Signatures do not match"
ErrorAllowedClockskewExceeded = "Allowed clockskew exceeded"
ErrorYouProbablyMisconfiguredAllowedClockSkew = "You probably misconfigured allowedClockSkew, set to -1 to disable"
ErrorRequiredHeaderNotInHeaderList = "Required header not in header list"
ErrorDateHeaderIsMissingForClockSkewComparison = "Date header is missing for clockSkew comparison"
ErrorNoHeadersConfigLoaded = "No headers config loaded"
ErrorAlgorithmNotAllowed = "The used encryption algorithm is not allowed"
)
func ErrorToHTTPCode(errString string) (int, string) {
switch {
case strings.HasPrefix(errString, ErrorNoAlgorithmConfigured):
return http.StatusInternalServerError, ErrorNoAlgorithmConfigured
case strings.HasPrefix(errString, ErrorNoKeyIDConfigured):
return http.StatusInternalServerError, ErrorNoKeyIDConfigured
case strings.HasPrefix(errString, ErrorNoHeadersConfigLoaded):
return http.StatusInternalServerError, ErrorNoHeadersConfigLoaded
case strings.HasPrefix(errString, ErrorYouProbablyMisconfiguredAllowedClockSkew):
return http.StatusInternalServerError, ErrorYouProbablyMisconfiguredAllowedClockSkew
case strings.HasPrefix(errString, ErrorMissingRequiredHeader):
return http.StatusBadRequest, ErrorMissingRequiredHeader
case strings.HasPrefix(errString, ErrorMissingSignatureParameterSignature):
return http.StatusBadRequest, ErrorMissingSignatureParameterSignature
case strings.HasPrefix(errString, ErrorMissingSignatureParameterAlgorithm):
return http.StatusBadRequest, ErrorMissingSignatureParameterAlgorithm
case strings.HasPrefix(errString, ErrorMissingSignatureParameterKeyId):
return http.StatusBadRequest, ErrorMissingSignatureParameterKeyId
case strings.HasPrefix(errString, ErrorNoSignatureHeaderFoundInRequest):
return http.StatusBadRequest, ErrorNoSignatureHeaderFoundInRequest
case strings.HasPrefix(errString, ErrorURLNotInRequest):
return http.StatusBadRequest, ErrorURLNotInRequest
case strings.HasPrefix(errString, ErrorMethodNotInRequest):
return http.StatusBadRequest, ErrorMethodNotInRequest
case strings.HasPrefix(errString, ErrorSignaturesDoNotMatch):
return http.StatusBadRequest, ErrorSignaturesDoNotMatch
case strings.HasPrefix(errString, ErrorAllowedClockskewExceeded):
return http.StatusBadRequest, ErrorAllowedClockskewExceeded
case strings.HasPrefix(errString, ErrorRequiredHeaderNotInHeaderList):
return http.StatusBadRequest, ErrorRequiredHeaderNotInHeaderList
case strings.HasPrefix(errString, ErrorDateHeaderIsMissingForClockSkewComparison):
return http.StatusBadRequest, ErrorDateHeaderIsMissingForClockSkewComparison
case strings.HasPrefix(errString, ErrorAlgorithmNotAllowed):
return http.StatusBadRequest, ErrorAlgorithmNotAllowed
default:
return http.StatusInternalServerError, errString
}
}