-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
43 lines (35 loc) · 1.45 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
package tls
import (
"errors"
"fmt"
)
var (
// ErrInvalidPublicPrivateKeyPair is returned if the users provided public/private keys do not match.
ErrInvalidPublicPrivateKeyPair = errors.New("private key does not match public key")
// ErrInvalidPasswordInputDataOrKey is a broader version of the 'ParseCertKeyError' which is used as more of a
// catchall to indicate something is wrong with the provided public/private key.
ErrInvalidPasswordInputDataOrKey = errors.New("invalid password, input data or an unsupported public/private key " +
"format/type")
// ErrPasswordProvidedButUnused is returned if the user has provided a password, but we've got to a point where it
// would no longer be used.
ErrPasswordProvidedButUnused = errors.New("a cert/key password was provided but hasn't been used, either the " +
"cert/key is unencrypted, or is an unsupported format")
)
// ParseCertKeyError is a more useful variation of 'ErrInvalidPasswordInputDataOrKey' which contains hints as to the
// next steps the user may be able to take to resolve the issue.
type ParseCertKeyError struct {
what string
password bool
}
func (p ParseCertKeyError) Error() string {
var (
withPassword = "no password provided"
encPrefix = ""
)
if p.password {
withPassword = "password provided"
encPrefix = "un"
}
return fmt.Sprintf("failed to parse %s (with %s), perhaps the type/format is invalid, unsupported or %sencrypted",
p.what, withPassword, encPrefix)
}