From 179cfeff51cefda80c16fa4558ba039143a2ad2c Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 2 Jan 2024 03:55:43 +0100 Subject: [PATCH 1/2] Remove deprecated `get_checksum{,_bytes}` routines There are deprecated since 0.24.0, i.e. they can be removed now. --- crates/bdk/src/descriptor/checksum.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/crates/bdk/src/descriptor/checksum.rs b/crates/bdk/src/descriptor/checksum.rs index 07120ab7..bce27ef9 100644 --- a/crates/bdk/src/descriptor/checksum.rs +++ b/crates/bdk/src/descriptor/checksum.rs @@ -107,29 +107,8 @@ pub fn calc_checksum(desc: &str) -> Result { .map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) }) } -// TODO in release 0.25.0, remove get_checksum_bytes and get_checksum // TODO in release 0.25.0, consolidate calc_checksum_bytes_internal into calc_checksum_bytes -/// Compute the checksum bytes of a descriptor -#[deprecated( - since = "0.24.0", - note = "Use new `calc_checksum_bytes` function which excludes any existing checksum in the descriptor string before calculating the checksum hash bytes. See https://github.com/bitcoindevkit/bdk/pull/765." -)] -pub fn get_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> { - calc_checksum_bytes_internal(desc, false) -} - -/// Compute the checksum of a descriptor -#[deprecated( - since = "0.24.0", - note = "Use new `calc_checksum` function which excludes any existing checksum in the descriptor string before calculating the checksum hash. See https://github.com/bitcoindevkit/bdk/pull/765." -)] -pub fn get_checksum(desc: &str) -> Result { - // unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET` - calc_checksum_bytes_internal(desc, false) - .map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) }) -} - #[cfg(test)] mod test { use super::*; From ed91a4bdb49276057eb7458e1a94653553be24e7 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 2 Jan 2024 04:09:45 +0100 Subject: [PATCH 2/2] Consolidate `calc_checksum_bytes_internal` routine Now that the deprecated `get_checksum{,_bytes}` routines are removed, the checksum is always computed with ignored data after the first '#', i.e. the boolean parameter `exclude_hash` is not needed anymore and the functionality can be consolidated into `calc_checksum_bytes`. --- crates/bdk/src/descriptor/checksum.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/crates/bdk/src/descriptor/checksum.rs b/crates/bdk/src/descriptor/checksum.rs index bce27ef9..243376bc 100644 --- a/crates/bdk/src/descriptor/checksum.rs +++ b/crates/bdk/src/descriptor/checksum.rs @@ -42,22 +42,16 @@ fn poly_mod(mut c: u64, val: u64) -> u64 { c } -/// Computes the checksum bytes of a descriptor. -/// `exclude_hash = true` ignores all data after the first '#' (inclusive). -pub(crate) fn calc_checksum_bytes_internal( - mut desc: &str, - exclude_hash: bool, -) -> Result<[u8; 8], DescriptorError> { +/// Compute the checksum bytes of a descriptor, excludes any existing checksum in the descriptor string from the calculation +pub fn calc_checksum_bytes(mut desc: &str) -> Result<[u8; 8], DescriptorError> { let mut c = 1; let mut cls = 0; let mut clscount = 0; let mut original_checksum = None; - if exclude_hash { - if let Some(split) = desc.split_once('#') { - desc = split.0; - original_checksum = Some(split.1); - } + if let Some(split) = desc.split_once('#') { + desc = split.0; + original_checksum = Some(split.1); } for ch in desc.as_bytes() { @@ -95,20 +89,12 @@ pub(crate) fn calc_checksum_bytes_internal( Ok(checksum) } -/// Compute the checksum bytes of a descriptor, excludes any existing checksum in the descriptor string from the calculation -pub fn calc_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> { - calc_checksum_bytes_internal(desc, true) -} - /// Compute the checksum of a descriptor, excludes any existing checksum in the descriptor string from the calculation pub fn calc_checksum(desc: &str) -> Result { // unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET` - calc_checksum_bytes_internal(desc, true) - .map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) }) + calc_checksum_bytes(desc).map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) }) } -// TODO in release 0.25.0, consolidate calc_checksum_bytes_internal into calc_checksum_bytes - #[cfg(test)] mod test { use super::*;