Skip to content

Commit

Permalink
Replace FromStr with TryFrom impl trait in ecdsa.rs crypto module
Browse files Browse the repository at this point in the history
Any type that has a FromStr should have TryFrom<{&str, String, Box<str>, Rc<str>, Arc<str>}>
This changes are for the crypto ecdsa.rs lib
  • Loading branch information
rockcoolsaint committed Dec 23, 2024
1 parent 8d508e0 commit fec1879
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions bitcoin/src/crypto/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
use core::str::FromStr;
use core::{fmt, iter};
use core::convert::TryFrom;
use alloc::boxed::Box;

#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use hex::FromHex;
use internals::{impl_to_hex_from_lower_hex, write_err};
use io::Write;
use alloc::rc::Rc;
use alloc::sync::Arc;
use alloc::string::String;

use crate::prelude::{DisplayHex, Vec};
use crate::script::PushBytes;
Expand Down Expand Up @@ -94,6 +99,46 @@ impl FromStr for Signature {
}
}

impl TryFrom<&str> for Signature {
type Error = ParseSignatureError;

fn try_from(s: &str) -> Result<Self, Self::Error> {
Self::from_str(s)
}
}

impl TryFrom<String> for Signature {
type Error = ParseSignatureError;

fn try_from(s: String) -> Result<Self, Self::Error> {
Self::from_str(&s)
}
}

impl TryFrom<Box<str>> for Signature {
type Error = ParseSignatureError;

fn try_from(s: Box<str>) -> Result<Self, Self::Error> {
Self::from_str(&s)
}
}

impl TryFrom<Arc<str>> for Signature {
type Error = ParseSignatureError;

fn try_from(s: Arc<str>) -> Result<Self, Self::Error> {
Self::from_str(&s)
}
}

impl TryFrom<Rc<str>> for Signature {
type Error = ParseSignatureError;

fn try_from(s: Rc<str>) -> Result<Self, Self::Error> {
Self::from_str(&s)
}
}

/// Holds signature serialized in-line (not in `Vec`).
///
/// This avoids allocation and allows proving maximum size of the signature (73 bytes).
Expand Down

0 comments on commit fec1879

Please sign in to comment.