Use new bech32 methods that expect a Variant enum variant

This commit is contained in:
Deirdre Connolly 2021-02-16 10:50:55 -05:00 committed by Deirdre Connolly
parent dd940f7dbf
commit 1fa41ff199
2 changed files with 14 additions and 14 deletions

View File

@ -5,7 +5,7 @@ use std::{
io::{self, Read, Write},
};
use bech32::{self, FromBase32, ToBase32};
use bech32::{self, FromBase32, ToBase32, Variant};
#[cfg(test)]
use proptest::prelude::*;
@ -58,7 +58,7 @@ impl fmt::Display for Address {
_ => human_readable_parts::TESTNET,
};
bech32::encode_to_fmt(f, hrp, bytes.get_ref().to_base32()).unwrap()
bech32::encode_to_fmt(f, hrp, bytes.get_ref().to_base32(), Variant::Bech32).unwrap()
}
}
@ -67,7 +67,7 @@ impl std::str::FromStr for Address {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match bech32::decode(s) {
Ok((hrp, bytes)) => {
Ok((hrp, bytes, Variant::Bech32)) => {
let mut decoded_bytes = io::Cursor::new(Vec::<u8>::from_base32(&bytes).unwrap());
let mut diversifier_bytes = [0; 11];
@ -84,7 +84,7 @@ impl std::str::FromStr for Address {
transmission_key: keys::TransmissionKey::from(transmission_key_bytes),
})
}
Err(_) => Err(SerializationError::Parse("bech32 decoding error")),
_ => Err(SerializationError::Parse("bech32 decoding error")),
}
}
}

View File

@ -21,7 +21,7 @@ use std::{
str::FromStr,
};
use bech32::{self, FromBase32, ToBase32};
use bech32::{self, FromBase32, ToBase32, Variant};
use rand_core::{CryptoRng, RngCore};
use crate::{
@ -206,7 +206,7 @@ impl fmt::Display for SpendingKey {
_ => sk_hrp::TESTNET,
};
bech32::encode_to_fmt(f, hrp, &self.bytes.to_base32()).unwrap()
bech32::encode_to_fmt(f, hrp, &self.bytes.to_base32(), Variant::Bech32).unwrap()
}
}
@ -215,7 +215,7 @@ impl FromStr for SpendingKey {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match bech32::decode(s) {
Ok((hrp, bytes)) => {
Ok((hrp, bytes, Variant::Bech32)) => {
let decoded = Vec::<u8>::from_base32(&bytes).unwrap();
let mut decoded_bytes = [0u8; 32];
@ -229,7 +229,7 @@ impl FromStr for SpendingKey {
bytes: decoded_bytes,
})
}
Err(_) => Err(SerializationError::Parse("bech32 decoding error")),
_ => Err(SerializationError::Parse("bech32 decoding error")),
}
}
}
@ -527,7 +527,7 @@ impl fmt::Display for IncomingViewingKey {
_ => ivk_hrp::TESTNET,
};
bech32::encode_to_fmt(f, hrp, &self.scalar.to_bytes().to_base32()).unwrap()
bech32::encode_to_fmt(f, hrp, &self.scalar.to_bytes().to_base32(), Variant::Bech32).unwrap()
}
}
@ -576,7 +576,7 @@ impl FromStr for IncomingViewingKey {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match bech32::decode(s) {
Ok((hrp, bytes)) => {
Ok((hrp, bytes, Variant::Bech32)) => {
let decoded = Vec::<u8>::from_base32(&bytes).unwrap();
let mut scalar_bytes = [0u8; 32];
@ -590,7 +590,7 @@ impl FromStr for IncomingViewingKey {
scalar: Scalar::from_bytes(&scalar_bytes).unwrap(),
})
}
Err(_) => Err(SerializationError::Parse("bech32 decoding error")),
_ => Err(SerializationError::Parse("bech32 decoding error")),
}
}
}
@ -833,7 +833,7 @@ impl fmt::Display for FullViewingKey {
_ => fvk_hrp::TESTNET,
};
bech32::encode_to_fmt(f, hrp, bytes.get_ref().to_base32()).unwrap()
bech32::encode_to_fmt(f, hrp, bytes.get_ref().to_base32(), Variant::Bech32).unwrap()
}
}
@ -842,7 +842,7 @@ impl FromStr for FullViewingKey {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match bech32::decode(s) {
Ok((hrp, bytes)) => {
Ok((hrp, bytes, Variant::Bech32)) => {
let mut decoded_bytes = io::Cursor::new(Vec::<u8>::from_base32(&bytes).unwrap());
let authorizing_key_bytes = decoded_bytes.read_32_bytes()?;
@ -861,7 +861,7 @@ impl FromStr for FullViewingKey {
outgoing_viewing_key: OutgoingViewingKey::from(outgoing_key_bytes),
})
}
Err(_) => Err(SerializationError::Parse("bech32 decoding error")),
_ => Err(SerializationError::Parse("bech32 decoding error")),
}
}
}