-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsigerrors.go
More file actions
89 lines (74 loc) · 2.83 KB
/
Copy pathsigerrors.go
File metadata and controls
89 lines (74 loc) · 2.83 KB
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
81
82
83
84
85
86
87
88
89
package httpsig
import (
"errors"
"fmt"
)
// ErrCode enumerates the reasons a signing or verification can fail
type ErrCode string
const (
// Error Codes
// Errors related to not being able to extract a valid signature.
ErrNoSigInvalidHeader ErrCode = "nosig_invalid_header"
ErrNoSigUnsupportedDigest ErrCode = "nosig_unsupported_digest"
ErrNoSigWrongDigest ErrCode = "nosig_wrong_digest"
ErrNoSigMissingSignature ErrCode = "nosig_missing_signature"
ErrNoSigInvalidSignature ErrCode = "nosig_invalid_signature"
ErrNoSigMessageBody ErrCode = "nosig_message_body" // Could not read message body
// Errors related to an individual signature.
ErrSigInvalidSignature ErrCode = "sig_invalid_signature" // The signature is unparseable or in the wrong format.
ErrSigKeyFetch ErrCode = "sig_key_fetch" // Failed to the key for a signature
ErrSigVerification ErrCode = "sig_failed_algo_verification" // The signature did not verify according to the algorithm.
ErrSigPublicKey ErrCode = "sig_public_key" // The public key for the signature is invalid or missing.
ErrSigSecretKey ErrCode = "sig_secret_key" // The secret key for the signature is invalid or missing.
ErrSigUnsupportedAlgorithm ErrCode = "sig_unsupported_algorithm" // unsupported or invalid algorithm.
ErrSigProfile ErrCode = "sig_failed_profile" // The signature was valid but failed the verify profile check
// Signing
ErrInvalidSignatureOptions ErrCode = "invalid_signature_options"
ErrInvalidComponent ErrCode = "invalid_component"
ErrInvalidMetadata ErrCode = "invalid_metadata"
// Accept Signature
ErrInvalidAcceptSignature ErrCode = "invalid_accept_signature"
ErrMissingAcceptSignature ErrCode = "missing_accept_signature" // The Accept-Signature field was present but had an empty value.
// General
ErrInternal ErrCode = "internal_error"
ErrUnsupported ErrCode = "unsupported" // A particular feature of the spec is not supported
)
type SignatureError struct {
Cause error // may be nil
Code ErrCode
Message string
}
func (se *SignatureError) Error() string {
return se.Message
}
func (se *SignatureError) Unwrap() error {
return se.Cause
}
func (se *SignatureError) GoString() string {
cause := ""
if se.Cause != nil {
cause = fmt.Sprintf("Cause: %s\n", se.Cause)
}
return fmt.Sprintf("Code: %s\nMessage: %s\n%s", se.Code, se.Message, cause)
}
func newError(code ErrCode, msg string, cause ...error) *SignatureError {
var rootErr error
if len(cause) > 0 {
rootErr = cause[0]
}
return &SignatureError{
Cause: rootErr,
Code: code,
Message: msg,
}
}
func errCode(err error) (ec ErrCode) {
if err == nil {
return ""
}
var se *SignatureError
if errors.As(err, &se) {
return se.Code
}
return ""
}