Update base64 usage to 0.21.3
This commit is contained in:
parent
c06c9beb01
commit
18e2854a42
|
@ -10,9 +10,9 @@ checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
|||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53"
|
||||
|
||||
[[package]]
|
||||
name = "bech32"
|
||||
|
|
|
@ -10,9 +10,9 @@ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
|||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53"
|
||||
|
||||
[[package]]
|
||||
name = "bech32"
|
||||
|
|
|
@ -41,7 +41,7 @@ hashes = { package = "bitcoin_hashes", version = "0.13.0", default-features = fa
|
|||
secp256k1 = { version = "0.27.0", default-features = false, features = ["bitcoin_hashes"] }
|
||||
hex_lit = "0.1.1"
|
||||
|
||||
base64 = { version = "0.13.0", optional = true }
|
||||
base64 = { version = "0.21.3", optional = true }
|
||||
# Only use this feature for no-std builds, otherwise use bitcoinconsensus-std.
|
||||
bitcoinconsensus = { version = "0.20.2-0.5.0", default-features = false, optional = true }
|
||||
|
||||
|
|
|
@ -818,6 +818,7 @@ mod display_from_str {
|
|||
use core::str::FromStr;
|
||||
|
||||
use base64::display::Base64Display;
|
||||
use base64::prelude::{Engine as _, BASE64_STANDARD};
|
||||
use internals::write_err;
|
||||
|
||||
use super::{Error, Psbt};
|
||||
|
@ -857,7 +858,7 @@ mod display_from_str {
|
|||
|
||||
impl Display for Psbt {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Base64Display::with_config(&self.serialize(), base64::STANDARD))
|
||||
write!(f, "{}", Base64Display::new(&self.serialize(), &BASE64_STANDARD))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -865,7 +866,7 @@ mod display_from_str {
|
|||
type Err = PsbtParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let data = base64::decode(s).map_err(PsbtParseError::Base64Encoding)?;
|
||||
let data = BASE64_STANDARD.decode(s).map_err(PsbtParseError::Base64Encoding)?;
|
||||
Psbt::deserialize(&data).map_err(PsbtParseError::PsbtEncoding)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ mod message_signing {
|
|||
|
||||
use crate::address::{Address, AddressType};
|
||||
use crate::crypto::key::PublicKey;
|
||||
#[cfg(feature = "base64")]
|
||||
use crate::prelude::*;
|
||||
|
||||
/// An error used for dealing with Bitcoin Signed Messages.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -159,33 +157,35 @@ mod message_signing {
|
|||
None => Ok(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a signature from base64 encoding.
|
||||
#[cfg(feature = "base64")]
|
||||
mod base64_impls {
|
||||
use base64::prelude::{Engine as _, BASE64_STANDARD};
|
||||
|
||||
use super::*;
|
||||
use crate::prelude::String;
|
||||
|
||||
impl MessageSignature {
|
||||
/// Convert a signature from base64 encoding.
|
||||
pub fn from_base64(s: &str) -> Result<MessageSignature, MessageSignatureError> {
|
||||
let bytes = base64::decode(s).map_err(|_| MessageSignatureError::InvalidBase64)?;
|
||||
let bytes =
|
||||
BASE64_STANDARD.decode(s).map_err(|_| MessageSignatureError::InvalidBase64)?;
|
||||
MessageSignature::from_slice(&bytes)
|
||||
}
|
||||
|
||||
/// Convert to base64 encoding.
|
||||
#[cfg(feature = "base64")]
|
||||
pub fn to_base64(self) -> String { base64::encode(&self.serialize()[..]) }
|
||||
pub fn to_base64(self) -> String { BASE64_STANDARD.encode(self.serialize()) }
|
||||
}
|
||||
|
||||
#[cfg(feature = "base64")]
|
||||
impl fmt::Display for MessageSignature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let bytes = self.serialize();
|
||||
// This avoids the allocation of a String.
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
base64::display::Base64Display::with_config(&bytes[..], base64::STANDARD)
|
||||
)
|
||||
write!(f, "{}", base64::display::Base64Display::new(&bytes, &BASE64_STANDARD))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "base64")]
|
||||
impl core::str::FromStr for MessageSignature {
|
||||
type Err = MessageSignatureError;
|
||||
fn from_str(s: &str) -> Result<MessageSignature, MessageSignatureError> {
|
||||
|
@ -193,6 +193,7 @@ mod message_signing {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash message for signature using Bitcoin's message signing format.
|
||||
pub fn signed_msg_hash(msg: &str) -> sha256d::Hash {
|
||||
|
@ -260,6 +261,7 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(all(feature = "secp-recovery", feature = "base64"))]
|
||||
fn test_incorrect_message_signature() {
|
||||
use base64::prelude::{Engine as _, BASE64_STANDARD};
|
||||
use secp256k1;
|
||||
|
||||
use crate::crypto::key::PublicKey;
|
||||
|
@ -276,7 +278,8 @@ mod tests {
|
|||
let signature =
|
||||
super::MessageSignature::from_base64(signature_base64).expect("message signature");
|
||||
|
||||
let pubkey = PublicKey::from_slice(&base64::decode(pubkey_base64).expect("base64 string"))
|
||||
let pubkey =
|
||||
PublicKey::from_slice(&BASE64_STANDARD.decode(pubkey_base64).expect("base64 string"))
|
||||
.expect("pubkey slice");
|
||||
|
||||
let p2pkh = Address::p2pkh(&pubkey, Network::Bitcoin);
|
||||
|
|
Loading…
Reference in New Issue