Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
82 lines (66 loc) · 3.13 KB
/
Copy patherrors.go
File metadata and controls
82 lines (66 loc) · 3.13 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
package saml
import (
"errors"
"fmt"
)
// Sentinel errors identifying why ParseResponse, ParseXMLResponse and
// ParseXMLArtifactResponse rejected a response. They are reachable with
// errors.Is on the returned *InvalidResponseError (which unwraps to its
// PrivateErr), so callers can classify failures without matching on message
// text. The human-readable messages are unchanged.
var (
// ErrSignatureMissing means the Response or the Assertion that had to be
// signed carries no Signature element.
ErrSignatureMissing = errors.New("signature element not present")
// ErrSignatureInvalid means a Signature element is present but could not
// be validated: bad digest or signature value, a certificate that is not
// one of the IDP's signing certificates, a malformed or ambiguous
// Signature, or no usable signing certificate in the IDP metadata.
ErrSignatureInvalid = errors.New("signature validation failed")
// ErrExpired means the Response, the Assertion, its SubjectConfirmationData
// or its Conditions are past their validity window.
ErrExpired = errors.New("expired")
// ErrNotYetValid means Conditions/@NotBefore lies in the future (beyond
// MaxClockSkew).
ErrNotYetValid = errors.New("not yet valid")
// ErrAudienceMismatch means the Assertion's AudienceRestriction does not
// contain this service provider (or the ValidateAudienceRestriction hook
// rejected it).
ErrAudienceMismatch = errors.New("audience restriction mismatch")
// ErrInResponseToMismatch means the InResponseTo of the Response (or of an
// Assertion's SubjectConfirmationData) is not one of the possible request
// IDs (or the ValidateRequestID hook rejected it).
ErrInResponseToMismatch = errors.New("InResponseTo mismatch")
// ErrDestinationMismatch means the Response's Destination is neither the
// request URL nor the ACS URL.
ErrDestinationMismatch = errors.New("destination mismatch")
// ErrRecipientMismatch means an Assertion's SubjectConfirmationData
// Recipient is not the ACS URL.
ErrRecipientMismatch = errors.New("recipient mismatch")
// ErrIssuerMismatch means the Issuer of the Response or the Assertion is not
// the IDP entity ID from the metadata.
ErrIssuerMismatch = errors.New("issuer mismatch")
)
// classifiedError carries a diagnostic message together with the sentinel
// (kind) it falls under and, optionally, the underlying cause.
type classifiedError struct {
msg string
kind error
cause error
}
func (e *classifiedError) Error() string { return e.msg }
func (e *classifiedError) Unwrap() []error {
if e.cause == nil {
return []error{e.kind}
}
return []error{e.kind, e.cause}
}
// classify returns an error with the formatted message that matches kind with
// errors.Is. Use %v, not %w, in format; pass a wrapped cause via classifyCause.
func classify(kind error, format string, args ...interface{}) error {
return &classifiedError{msg: fmt.Sprintf(format, args...), kind: kind}
}
// classifyCause is like classify and also exposes cause to errors.Is/As.
func classifyCause(kind, cause error, format string, args ...interface{}) error {
return &classifiedError{msg: fmt.Sprintf(format, args...), kind: kind, cause: cause}
}