falcon_det/error.rs
1// Copyright (c) Jeeyong Um <conr2d@proton.me>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10#[derive(Debug)]
11pub enum Error {
12 /// [`Error::Random`] is returned when the library tries to use an
13 /// OS-provided RNG, but either none is supported, or that RNG fails.
14 Random,
15 /// [`Error::Size`] is returned when a buffer has been provided to
16 /// the library but is too small to receive the intended value.
17 Size,
18 /// [`Error::Format`] is returned when decoding of an external object
19 /// (public key, private key, signature) fails.
20 Format,
21 /// [`Error::BadSig`] is returned when verifying a signature, the signature
22 /// is validly encoded, but its value does not match the provided message
23 /// and public key.
24 BadSig,
25 /// [`Error::BadArg`] is returned when a provided parameter is not in
26 /// a valid range.
27 BadArg,
28 /// [`Error::Internal`] is returned when some internal computation failed.
29 Internal,
30 Unknown(i32),
31}
32
33impl From<i32> for Error {
34 fn from(e: i32) -> Self {
35 match e {
36 sys::FALCON_ERR_RANDOM => Error::Random,
37 sys::FALCON_ERR_SIZE => Error::Size,
38 sys::FALCON_ERR_FORMAT => Error::Format,
39 sys::FALCON_ERR_BADSIG => Error::BadSig,
40 sys::FALCON_ERR_BADARG => Error::BadArg,
41 sys::FALCON_ERR_INTERNAL => Error::Internal,
42 _ => Error::Unknown(e),
43 }
44 }
45}