Skip to content

Commit ed91a4b

Browse files
committed
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`.
1 parent 179cfef commit ed91a4b

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

crates/bdk/src/descriptor/checksum.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,16 @@ fn poly_mod(mut c: u64, val: u64) -> u64 {
4242
c
4343
}
4444

45-
/// Computes the checksum bytes of a descriptor.
46-
/// `exclude_hash = true` ignores all data after the first '#' (inclusive).
47-
pub(crate) fn calc_checksum_bytes_internal(
48-
mut desc: &str,
49-
exclude_hash: bool,
50-
) -> Result<[u8; 8], DescriptorError> {
45+
/// Compute the checksum bytes of a descriptor, excludes any existing checksum in the descriptor string from the calculation
46+
pub fn calc_checksum_bytes(mut desc: &str) -> Result<[u8; 8], DescriptorError> {
5147
let mut c = 1;
5248
let mut cls = 0;
5349
let mut clscount = 0;
5450

5551
let mut original_checksum = None;
56-
if exclude_hash {
57-
if let Some(split) = desc.split_once('#') {
58-
desc = split.0;
59-
original_checksum = Some(split.1);
60-
}
52+
if let Some(split) = desc.split_once('#') {
53+
desc = split.0;
54+
original_checksum = Some(split.1);
6155
}
6256

6357
for ch in desc.as_bytes() {
@@ -95,20 +89,12 @@ pub(crate) fn calc_checksum_bytes_internal(
9589
Ok(checksum)
9690
}
9791

98-
/// Compute the checksum bytes of a descriptor, excludes any existing checksum in the descriptor string from the calculation
99-
pub fn calc_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> {
100-
calc_checksum_bytes_internal(desc, true)
101-
}
102-
10392
/// Compute the checksum of a descriptor, excludes any existing checksum in the descriptor string from the calculation
10493
pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
10594
// unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET`
106-
calc_checksum_bytes_internal(desc, true)
107-
.map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) })
95+
calc_checksum_bytes(desc).map(|b| unsafe { String::from_utf8_unchecked(b.to_vec()) })
10896
}
10997

110-
// TODO in release 0.25.0, consolidate calc_checksum_bytes_internal into calc_checksum_bytes
111-
11298
#[cfg(test)]
11399
mod test {
114100
use super::*;

0 commit comments

Comments
 (0)