zig/lib/std/crypto/errors.zig
Frank Denis 10f2d62789
std/crypto: use finer-grained error sets in function signatures (#8558)
std/crypto: use finer-grained error sets in function signatures

Returning the `crypto.Error` error set for all crypto operations
was very convenient to ensure that errors were used consistently,
and to avoid having multiple error names for the same thing.

The flipside is that callers were forced to always handle all
possible errors, even those that could never be returned by a
function.

This PR makes all functions return union sets of the actual errors
they can return.

The error sets themselves are all limited to a single error.

Larger sets are useful for platform-specific APIs, but we don't have
any of these in `std/crypto`, and I couldn't find any meaningful way
to build larger sets.
2021-04-20 19:57:27 +02:00

36 lines
1.5 KiB
Zig

/// MAC verification failed - The tag doesn't verify for the given ciphertext and secret key
pub const AuthenticationError = error{AuthenticationFailed};
/// The requested output length is too long for the chosen algorithm
pub const OutputTooLongError = error{OutputTooLong};
/// Finite field operation returned the identity element
pub const IdentityElementError = error{IdentityElement};
/// Encoded input cannot be decoded
pub const EncodingError = error{InvalidEncoding};
/// The signature does't verify for the given message and public key
pub const SignatureVerificationError = error{SignatureVerificationFailed};
/// Both a public and secret key have been provided, but they are incompatible
pub const KeyMismatchError = error{KeyMismatch};
/// Encoded input is not in canonical form
pub const NonCanonicalError = error{NonCanonical};
/// Square root has no solutions
pub const NotSquareError = error{NotSquare};
/// Verification string doesn't match the provided password and parameters
pub const PasswordVerificationError = error{PasswordVerificationFailed};
/// Parameters would be insecure to use
pub const WeakParametersError = error{WeakParameters};
/// Public key would be insecure to use
pub const WeakPublicKeyError = error{WeakPublicKey};
/// Any error related to cryptography operations
pub const Error = AuthenticationError || OutputTooLongError || IdentityElementError || EncodingError || SignatureVerificationError || KeyMismatchError || NonCanonicalError || NotSquareError || PasswordVerificationError || WeakParametersError || WeakPublicKeyError;