use crate::error::SignatureParseError;
use crate::hex;
#[derive(PartialEq, Eq)]
pub struct Signature(Vec<u8>);
impl Signature {
pub fn new(sig_bytes: Vec<u8>) -> Self {
Self(sig_bytes)
}
pub fn from_hex(sig_hex: &str) -> Result<Self, SignatureParseError> {
hex::hex_str_to_bytes(sig_hex)
.map(Self)
.map_err(|e| SignatureParseError(e.to_string()))
}
pub fn take_bytes(self) -> Vec<u8> {
self.0
}
pub fn as_slice(&self) -> &[u8] {
&self.0
}
pub fn as_hex(&self) -> String {
hex::bytes_to_hex_str(&self.0)
}
}
impl std::fmt::Debug for Signature {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple("Signature").field(&self.as_hex()).finish()
}
}
impl std::fmt::Display for Signature {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&self.as_hex())
}
}