Upgrade hex dependency
Upgrade to the new `hex v0.2.0` release.
This commit is contained in:
parent
f0558e8eb9
commit
4bfb466bb9
|
@ -8,6 +8,12 @@ version = "1.0.57"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base58check"
|
name = "base58check"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -159,9 +165,12 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hex-conservative"
|
name = "hex-conservative"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2"
|
checksum = "e1aa273bf451e37ed35ced41c71a5e2a4e29064afb104158f2514bcd71c2c986"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hex_lit"
|
name = "hex_lit"
|
||||||
|
|
|
@ -8,6 +8,12 @@ version = "1.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base58check"
|
name = "base58check"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -158,9 +164,12 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hex-conservative"
|
name = "hex-conservative"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2"
|
checksum = "e1aa273bf451e37ed35ced41c71a5e2a4e29064afb104158f2514bcd71c2c986"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hex_lit"
|
name = "hex_lit"
|
||||||
|
|
|
@ -25,4 +25,4 @@ hashes = { package = "bitcoin_hashes", version = "0.13.0", default-features = fa
|
||||||
internals = { package = "bitcoin-internals", version = "0.2.0" }
|
internals = { package = "bitcoin-internals", version = "0.2.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex = { package = "hex-conservative", version = "0.1.1", default-features = false, features = ["alloc"] }
|
hex = { package = "hex-conservative", version = "0.2.0", default-features = false, features = ["alloc"] }
|
||||||
|
|
|
@ -31,7 +31,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
||||||
base58 = { package = "base58check", version = "0.1.0", default-features = false }
|
base58 = { package = "base58check", version = "0.1.0", default-features = false }
|
||||||
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
|
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
|
||||||
hashes = { package = "bitcoin_hashes", version = "0.13.0", default-features = false, features = ["alloc", "io"] }
|
hashes = { package = "bitcoin_hashes", version = "0.13.0", default-features = false, features = ["alloc", "io"] }
|
||||||
hex = { package = "hex-conservative", version = "0.1.1", default-features = false, features = ["alloc"] }
|
hex = { package = "hex-conservative", version = "0.2.0", default-features = false, features = ["alloc"] }
|
||||||
hex_lit = "0.1.1"
|
hex_lit = "0.1.1"
|
||||||
internals = { package = "bitcoin-internals", version = "0.2.0" }
|
internals = { package = "bitcoin-internals", version = "0.2.0" }
|
||||||
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
|
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
|
||||||
|
|
|
@ -506,18 +506,19 @@ impl<'de> serde::Deserialize<'de> for Witness {
|
||||||
|
|
||||||
while let Some(elem) = a.next_element::<String>()? {
|
while let Some(elem) = a.next_element::<String>()? {
|
||||||
let vec = Vec::<u8>::from_hex(&elem).map_err(|e| match e {
|
let vec = Vec::<u8>::from_hex(&elem).map_err(|e| match e {
|
||||||
InvalidChar(b) => match core::char::from_u32(b.into()) {
|
InvalidChar(ref e) => match core::char::from_u32(e.invalid_char(
|
||||||
|
).into()) {
|
||||||
Some(c) => de::Error::invalid_value(
|
Some(c) => de::Error::invalid_value(
|
||||||
Unexpected::Char(c),
|
Unexpected::Char(c),
|
||||||
&"a valid hex character",
|
&"a valid hex character",
|
||||||
),
|
),
|
||||||
None => de::Error::invalid_value(
|
None => de::Error::invalid_value(
|
||||||
Unexpected::Unsigned(b.into()),
|
Unexpected::Unsigned(e.invalid_char().into()),
|
||||||
&"a valid hex character",
|
&"a valid hex character",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
OddLengthString(len) =>
|
OddLengthString(ref e) =>
|
||||||
de::Error::invalid_length(len, &"an even length string"),
|
de::Error::invalid_length(e.length(), &"an even length string"),
|
||||||
})?;
|
})?;
|
||||||
ret.push(vec);
|
ret.push(vec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,11 @@ pub mod hex {
|
||||||
|
|
||||||
/// Hex byte encoder.
|
/// Hex byte encoder.
|
||||||
// We wrap `BufEncoder` to not leak internal representation.
|
// We wrap `BufEncoder` to not leak internal representation.
|
||||||
pub struct Encoder<C: Case>(BufEncoder<[u8; HEX_BUF_SIZE]>, PhantomData<C>);
|
pub struct Encoder<C: Case>(BufEncoder<{ HEX_BUF_SIZE }>, PhantomData<C>);
|
||||||
|
|
||||||
impl<C: Case> From<super::Hex<C>> for Encoder<C> {
|
impl<C: Case> From<super::Hex<C>> for Encoder<C> {
|
||||||
fn from(_: super::Hex<C>) -> Self {
|
fn from(_: super::Hex<C>) -> Self {
|
||||||
Encoder(BufEncoder::new([0; HEX_BUF_SIZE]), Default::default())
|
Encoder(BufEncoder::new(), Default::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,15 +100,15 @@ pub mod hex {
|
||||||
// Newtypes to hide internal details.
|
// Newtypes to hide internal details.
|
||||||
|
|
||||||
/// Error returned when a hex string decoder can't be created.
|
/// Error returned when a hex string decoder can't be created.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct DecodeInitError(hex::HexToBytesError);
|
pub struct DecodeInitError(hex::OddLengthStringError);
|
||||||
|
|
||||||
/// Error returned when a hex string contains invalid characters.
|
/// Error returned when a hex string contains invalid characters.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct DecodeError(hex::HexToBytesError);
|
pub struct DecodeError(hex::InvalidCharError);
|
||||||
|
|
||||||
/// Hex decoder state.
|
/// Hex decoder state.
|
||||||
pub struct Decoder<'a>(hex::HexToBytesIter<'a>);
|
pub struct Decoder<'a>(hex::HexSliceToBytesIter<'a>);
|
||||||
|
|
||||||
impl<'a> Decoder<'a> {
|
impl<'a> Decoder<'a> {
|
||||||
fn new(s: &'a str) -> Result<Self, DecodeInitError> {
|
fn new(s: &'a str) -> Result<Self, DecodeInitError> {
|
||||||
|
@ -137,29 +137,19 @@ pub mod hex {
|
||||||
|
|
||||||
impl super::IntoDeError for DecodeInitError {
|
impl super::IntoDeError for DecodeInitError {
|
||||||
fn into_de_error<E: serde::de::Error>(self) -> E {
|
fn into_de_error<E: serde::de::Error>(self) -> E {
|
||||||
use hex::HexToBytesError;
|
E::invalid_length(self.0.length(), &"an even number of ASCII-encoded hex digits")
|
||||||
|
|
||||||
match self.0 {
|
|
||||||
HexToBytesError::OddLengthString(len) =>
|
|
||||||
E::invalid_length(len, &"an even number of ASCII-encoded hex digits"),
|
|
||||||
error => panic!("unexpected error: {:?}", error),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::IntoDeError for DecodeError {
|
impl super::IntoDeError for DecodeError {
|
||||||
fn into_de_error<E: serde::de::Error>(self) -> E {
|
fn into_de_error<E: serde::de::Error>(self) -> E {
|
||||||
use hex::HexToBytesError;
|
|
||||||
use serde::de::Unexpected;
|
use serde::de::Unexpected;
|
||||||
|
|
||||||
const EXPECTED_CHAR: &str = "an ASCII-encoded hex digit";
|
const EXPECTED_CHAR: &str = "an ASCII-encoded hex digit";
|
||||||
|
|
||||||
match self.0 {
|
match self.0.invalid_char() {
|
||||||
HexToBytesError::InvalidChar(c) if c.is_ascii() =>
|
c if c.is_ascii() => E::invalid_value(Unexpected::Char(c as _), &EXPECTED_CHAR),
|
||||||
E::invalid_value(Unexpected::Char(c as _), &EXPECTED_CHAR),
|
c => E::invalid_value(Unexpected::Unsigned(c.into()), &EXPECTED_CHAR),
|
||||||
HexToBytesError::InvalidChar(c) =>
|
|
||||||
E::invalid_value(Unexpected::Unsigned(c.into()), &EXPECTED_CHAR),
|
|
||||||
error => panic!("unexpected error: {:?}", error),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use core::ops;
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
|
|
||||||
use hashes::{hash160, Hash};
|
use hashes::{hash160, Hash};
|
||||||
use hex::{FromHex, HexToArrayError, HexToBytesError};
|
use hex::{FromHex, HexToArrayError};
|
||||||
use internals::array_vec::ArrayVec;
|
use internals::array_vec::ArrayVec;
|
||||||
use internals::write_err;
|
use internals::write_err;
|
||||||
use io::{Read, Write};
|
use io::{Read, Write};
|
||||||
|
@ -233,22 +233,22 @@ impl fmt::Display for PublicKey {
|
||||||
impl FromStr for PublicKey {
|
impl FromStr for PublicKey {
|
||||||
type Err = ParsePublicKeyError;
|
type Err = ParsePublicKeyError;
|
||||||
fn from_str(s: &str) -> Result<PublicKey, ParsePublicKeyError> {
|
fn from_str(s: &str) -> Result<PublicKey, ParsePublicKeyError> {
|
||||||
|
use HexToArrayError::*;
|
||||||
|
|
||||||
match s.len() {
|
match s.len() {
|
||||||
66 => {
|
66 => {
|
||||||
PublicKey::from_slice(&<[u8; 33]>::from_hex(s).map_err(|op| {
|
let bytes = <[u8; 33]>::from_hex(s).map_err(|e| match e {
|
||||||
match op {
|
InvalidChar(e) => ParsePublicKeyError::InvalidChar(e.invalid_char()),
|
||||||
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) => ParsePublicKeyError::InvalidChar(char),
|
InvalidLength(_) => unreachable!("length checked already")
|
||||||
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_)) | HexToArrayError::InvalidLength(_,_) => unreachable!("invalid length"),
|
})?;
|
||||||
}
|
Ok(PublicKey::from_slice(&bytes).expect("length checked already"))
|
||||||
})?).map_err(From::from)
|
|
||||||
},
|
},
|
||||||
130 => {
|
130 => {
|
||||||
PublicKey::from_slice(&<[u8; 65]>::from_hex(s).map_err(|op| {
|
let bytes = <[u8; 65]>::from_hex(s).map_err(|e| match e {
|
||||||
match op {
|
InvalidChar(e) => ParsePublicKeyError::InvalidChar(e.invalid_char()),
|
||||||
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) => ParsePublicKeyError::InvalidChar(char),
|
InvalidLength(_) => unreachable!("length checked already")
|
||||||
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_)) | HexToArrayError::InvalidLength(_,_) => unreachable!("invalid length"),
|
})?;
|
||||||
}
|
Ok(PublicKey::from_slice(&bytes).expect("length checked already"))
|
||||||
})?).map_err(From::from)
|
|
||||||
}
|
}
|
||||||
len => Err(ParsePublicKeyError::InvalidHexLength(len)),
|
len => Err(ParsePublicKeyError::InvalidHexLength(len)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1035,7 +1035,7 @@ mod tests {
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn hex_psbt(s: &str) -> Result<Psbt, crate::psbt::error::Error> {
|
pub fn hex_psbt(s: &str) -> Result<Psbt, crate::psbt::error::Error> {
|
||||||
let r: Result<Vec<u8>, hex::HexToBytesError> = Vec::from_hex(s);
|
let r = Vec::from_hex(s);
|
||||||
match r {
|
match r {
|
||||||
Err(_e) => panic!("unable to parse hex string {}", s),
|
Err(_e) => panic!("unable to parse hex string {}", s),
|
||||||
Ok(v) => Psbt::deserialize(&v),
|
Ok(v) => Psbt::deserialize(&v),
|
||||||
|
|
|
@ -28,10 +28,7 @@ impl fmt::Debug for SerializedSignature {
|
||||||
|
|
||||||
impl fmt::Display for SerializedSignature {
|
impl fmt::Display for SerializedSignature {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let mut buf = [0u8; MAX_LEN * 2];
|
hex::fmt_hex_exact!(f, MAX_LEN, self, hex::Case::Lower)
|
||||||
let mut encoder = hex::buf_encoder::BufEncoder::new(&mut buf);
|
|
||||||
encoder.put_bytes(self, hex::Case::Lower);
|
|
||||||
f.pad_integral(true, "0x", encoder.as_str())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
|
hex = { package = "hex-conservative", version = "0.2.0", default-features = false }
|
||||||
|
|
||||||
bitcoin-io = { version = "0.1.1", default-features = false, optional = true }
|
bitcoin-io = { version = "0.1.1", default-features = false, optional = true }
|
||||||
schemars = { version = "0.8.3", default-features = false, optional = true }
|
schemars = { version = "0.8.3", default-features = false, optional = true }
|
||||||
|
|
|
@ -89,15 +89,13 @@ macro_rules! hash_trait_impls {
|
||||||
impl<$($gen: $gent),*> str::FromStr for Hash<$($gen),*> {
|
impl<$($gen: $gent),*> str::FromStr for Hash<$($gen),*> {
|
||||||
type Err = $crate::hex::HexToArrayError;
|
type Err = $crate::hex::HexToArrayError;
|
||||||
fn from_str(s: &str) -> $crate::_export::_core::result::Result<Self, Self::Err> {
|
fn from_str(s: &str) -> $crate::_export::_core::result::Result<Self, Self::Err> {
|
||||||
use $crate::hex::{FromHex, HexToBytesIter};
|
use $crate::{Hash, hex::{FromHex}};
|
||||||
use $crate::Hash;
|
|
||||||
|
|
||||||
let inner: [u8; $bits / 8] = if $reverse {
|
let mut bytes = <[u8; $bits / 8]>::from_hex(s)?;
|
||||||
FromHex::from_byte_iter(HexToBytesIter::new(s)?.rev())?
|
if $reverse {
|
||||||
} else {
|
bytes.reverse();
|
||||||
FromHex::from_byte_iter(HexToBytesIter::new(s)?)?
|
}
|
||||||
};
|
Ok(Self::from_byte_array(bytes))
|
||||||
Ok(Self::from_byte_array(inner))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,15 +176,13 @@ impl Midstate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl hex::FromHex for Midstate {
|
impl hex::FromHex for Midstate {
|
||||||
type Err = hex::HexToArrayError;
|
type Error = hex::HexToArrayError;
|
||||||
fn from_byte_iter<I>(iter: I) -> Result<Self, Self::Err>
|
|
||||||
where
|
fn from_hex(s: &str) -> Result<Self, Self::Error> {
|
||||||
I: Iterator<Item = Result<u8, hex::HexToBytesError>>
|
|
||||||
+ ExactSizeIterator
|
|
||||||
+ DoubleEndedIterator,
|
|
||||||
{
|
|
||||||
// DISPLAY_BACKWARD is true
|
// DISPLAY_BACKWARD is true
|
||||||
Ok(Midstate::from_byte_array(hex::FromHex::from_byte_iter(iter.rev())?))
|
let mut bytes = <[u8; 32]>::from_hex(s)?;
|
||||||
|
bytes.reverse();
|
||||||
|
Ok(Midstate(bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,15 +270,13 @@ macro_rules! hash_newtype {
|
||||||
impl $crate::_export::_core::str::FromStr for $newtype {
|
impl $crate::_export::_core::str::FromStr for $newtype {
|
||||||
type Err = $crate::hex::HexToArrayError;
|
type Err = $crate::hex::HexToArrayError;
|
||||||
fn from_str(s: &str) -> $crate::_export::_core::result::Result<$newtype, Self::Err> {
|
fn from_str(s: &str) -> $crate::_export::_core::result::Result<$newtype, Self::Err> {
|
||||||
use $crate::hex::{FromHex, HexToBytesIter};
|
use $crate::{Hash, hex::FromHex};
|
||||||
use $crate::Hash;
|
|
||||||
|
|
||||||
let inner: <$hash as Hash>::Bytes = if <Self as $crate::Hash>::DISPLAY_BACKWARD {
|
let mut bytes = <[u8; <Self as $crate::Hash>::LEN]>::from_hex(s)?;
|
||||||
FromHex::from_byte_iter(HexToBytesIter::new(s)?.rev())?
|
if <Self as $crate::Hash>::DISPLAY_BACKWARD {
|
||||||
} else {
|
bytes.reverse();
|
||||||
FromHex::from_byte_iter(HexToBytesIter::new(s)?)?
|
|
||||||
};
|
};
|
||||||
Ok($newtype(<$hash>::from_byte_array(inner)))
|
Ok($newtype(<$hash>::from_byte_array(bytes)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue