-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
87 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
use thiserror::Error; | ||
use alloc::string::String; | ||
|
||
pub type Result<T> = ::std::result::Result<T, Error>; | ||
pub type Result<T> = core::result::Result<T, Error>; | ||
|
||
/// Error types | ||
#[derive(Debug, Error)] | ||
#[derive(Debug)] | ||
pub enum Error { | ||
#[error("invalid padding scheme")] | ||
InvalidPaddingScheme, | ||
#[error("decryption error")] | ||
Decryption, | ||
#[error("verification error")] | ||
Verification, | ||
#[error("message too long")] | ||
MessageTooLong, | ||
#[error("input must be hashed")] | ||
InputNotHashed, | ||
#[error("nprimes must be >= 2")] | ||
NprimesTooSmall, | ||
#[error("too few primes of given length to generate an RSA key")] | ||
TooFewPrimes, | ||
#[error("invalid prime value")] | ||
InvalidPrime, | ||
#[error("invalid modulus")] | ||
InvalidModulus, | ||
#[error("invalid exponent")] | ||
InvalidExponent, | ||
#[error("invalid coefficient")] | ||
InvalidCoefficient, | ||
#[error("public exponent too small")] | ||
PublicExponentTooSmall, | ||
#[error("public exponent too large")] | ||
PublicExponentTooLarge, | ||
#[error("parse error: {}", reason)] | ||
ParseError { reason: String }, | ||
#[error("internal error")] | ||
Internal, | ||
#[error("label too long")] | ||
LabelTooLong, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for Error {} | ||
impl core::fmt::Display for Error { | ||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { | ||
match self { | ||
Error::InvalidPaddingScheme => write!(f, "invalid padding scheme"), | ||
Error::Decryption => write!(f, "decryption error"), | ||
Error::Verification => write!(f, "verification error"), | ||
Error::MessageTooLong => write!(f, "message too long"), | ||
Error::InputNotHashed => write!(f, "input must be hashed"), | ||
Error::NprimesTooSmall => write!(f, "nprimes must be >= 2"), | ||
Error::TooFewPrimes => write!(f, "too few primes of given length to generate an RSA key"), | ||
Error::InvalidPrime => write!(f, "invalid prime value"), | ||
Error::InvalidModulus => write!(f, "invalid modulus"), | ||
Error::InvalidExponent => write!(f, "invalid exponent"), | ||
Error::InvalidCoefficient => write!(f, "invalid coefficient"), | ||
Error::PublicExponentTooSmall => write!(f, "public exponent too small"), | ||
Error::PublicExponentTooLarge => write!(f, "public exponent too large"), | ||
Error::ParseError { reason } => write!(f, "parse error: {}", reason), | ||
Error::Internal => write!(f, "internal error"), | ||
Error::LabelTooLong => write!(f, "label too long"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use std::vec::Vec; | ||
use alloc::vec; | ||
use alloc::vec::Vec; | ||
|
||
use digest::DynDigest; | ||
use rand::{Rng, RngCore}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters