New returns an error that contains an error code and message derived from the given category, reason. Currently, to avoid confusion, it is not allowed to create an error of category Success
(category Category, reason Reason)
| 226 | // the given category, reason. Currently, to avoid confusion, it is not |
| 227 | // allowed to create an error of category Success |
| 228 | func New(category Category, reason Reason) *Error { |
| 229 | errorCode := int(category) + int(reason) |
| 230 | var msg string |
| 231 | switch category { |
| 232 | case OCSPError: |
| 233 | switch reason { |
| 234 | case ReadFailed: |
| 235 | msg = "No certificate provided" |
| 236 | case IssuerMismatch: |
| 237 | msg = "Certificate not issued by this issuer" |
| 238 | case InvalidStatus: |
| 239 | msg = "Invalid revocation status" |
| 240 | } |
| 241 | case CertificateError: |
| 242 | switch reason { |
| 243 | case Unknown: |
| 244 | msg = "Unknown certificate error" |
| 245 | case ReadFailed: |
| 246 | msg = "Failed to read certificate" |
| 247 | case DecodeFailed: |
| 248 | msg = "Failed to decode certificate" |
| 249 | case ParseFailed: |
| 250 | msg = "Failed to parse certificate" |
| 251 | case SelfSigned: |
| 252 | msg = "Certificate is self signed" |
| 253 | case VerifyFailed: |
| 254 | msg = "Unable to verify certificate" |
| 255 | case BadRequest: |
| 256 | msg = "Invalid certificate request" |
| 257 | case MissingSerial: |
| 258 | msg = "Missing serial number in request" |
| 259 | default: |
| 260 | panic(fmt.Sprintf("Unsupported CFSSL error reason %d under category CertificateError.", |
| 261 | reason)) |
| 262 | |
| 263 | } |
| 264 | case PrivateKeyError: |
| 265 | switch reason { |
| 266 | case Unknown: |
| 267 | msg = "Unknown private key error" |
| 268 | case ReadFailed: |
| 269 | msg = "Failed to read private key" |
| 270 | case DecodeFailed: |
| 271 | msg = "Failed to decode private key" |
| 272 | case ParseFailed: |
| 273 | msg = "Failed to parse private key" |
| 274 | case Encrypted: |
| 275 | msg = "Private key is encrypted." |
| 276 | case NotRSAOrECCOrEd25519: |
| 277 | msg = "Private key algorithm is not RSA or ECC or Ed25519" |
| 278 | case KeyMismatch: |
| 279 | msg = "Private key does not match public key" |
| 280 | case GenerationFailed: |
| 281 | msg = "Failed to new private key" |
| 282 | case Unavailable: |
| 283 | msg = "Private key is unavailable" |
| 284 | default: |
| 285 | panic(fmt.Sprintf("Unsupported CFSSL error reason %d under category PrivateKeyError.", |
no outgoing calls