-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(crypto): impl FromStr instead of TryFrom<&str> for near_cryp…
…to::Signature and CryptoHash (#4151) I keep refactoring traits usage in near-crypto. `FromStr` is what is used whenever someone wants to parse strings into a structure. I need `near_crypto::Signature` to be parsable in order to use it with clap (CLI parsing).
- Loading branch information
Showing
9 changed files
with
144 additions
and
95 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
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,18 +1,45 @@ | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct TryFromSliceError(pub(crate) ()); | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ParseSignatureError { | ||
#[error("invalid signature data: {0}")] | ||
InvalidData(String), | ||
pub enum ParseKeyTypeError { | ||
#[error("unknown key type '{unknown_key_type}'")] | ||
UnknownKeyType { unknown_key_type: String }, | ||
} | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ParseKeyError { | ||
#[error("unknown curve kind: {0}")] | ||
UnknownCurve(String), | ||
#[error("invalid key length: {0}")] | ||
InvalidLength(usize), | ||
#[error("invalid key data: {0}")] | ||
InvalidData(String), | ||
#[error("unknown key type '{unknown_key_type}'")] | ||
UnknownKeyType { unknown_key_type: String }, | ||
#[error("invalid key length: expected the input of {expected_length} bytes, but {received_length} was given")] | ||
InvalidLength { expected_length: usize, received_length: usize }, | ||
#[error("invalid key data: {error_message}")] | ||
InvalidData { error_message: String }, | ||
} | ||
|
||
impl From<ParseKeyTypeError> for ParseKeyError { | ||
fn from(err: ParseKeyTypeError) -> Self { | ||
match err { | ||
ParseKeyTypeError::UnknownKeyType { unknown_key_type } => { | ||
Self::UnknownKeyType { unknown_key_type } | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, thiserror::Error)] | ||
pub enum ParseSignatureError { | ||
#[error("unknown key type '{unknown_key_type}'")] | ||
UnknownKeyType { unknown_key_type: String }, | ||
#[error("invalid signature length: expected the input of {expected_length} bytes, but {received_length} was given")] | ||
InvalidLength { expected_length: usize, received_length: usize }, | ||
#[error("invalid signature data: {error_message}")] | ||
InvalidData { error_message: String }, | ||
} | ||
|
||
impl From<ParseKeyTypeError> for ParseSignatureError { | ||
fn from(err: ParseKeyTypeError) -> Self { | ||
match err { | ||
ParseKeyTypeError::UnknownKeyType { unknown_key_type } => { | ||
Self::UnknownKeyType { unknown_key_type } | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.