Skip to content

Commit fbd1d65

Browse files
Merge #1253: Remove deprecated checksum routines
ed91a4b Consolidate `calc_checksum_bytes_internal` routine (Sebastian Falbesoner) 179cfef Remove deprecated `get_checksum{,_bytes}` routines (Sebastian Falbesoner) Pull request description: ### Description This PR removes the routines `get_checksum` and `get_checksum_bytes` (in the bdk crate, descriptor/checksum.rs), which have been deprecated in 0.24.0. Consequently, the routine `calc_checksum_bytes_internal` is consolidated into `calc_checksum_bytes`, as the boolean parameter `exclude_hash` is not needed anymore. See also the two TODOs in the touched file. ### Notes to the reviewers In the second commit, the signature of the function `calc_checksum_bytes` slightly changes, as the `desc` parameter now is declared as `mut`, in order to change the local variable within the function. My rust experience is rather limited, so I'm not sure if this is a problem for users. IIUC, this is comparable to changing a pass-by-value parameter in C++ from `const std::string desc` to `std::string desc`, which is relevant only for the function implementation, but doesn't change the interface. ### Changelog notice - Remove deprecated `get_checksum` and `get_checksum_bytes` routines ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: danielabrozzoni: ACK ed91a4b Tree-SHA512: a29ead57d0369b67e7e79734d7ddc26f42e7ee78b3a6a336cbf9dfa5579f55e7ddbc20b1662d4bedddd7b40a49511dc21c2652911f56d84c9663099b383e1084
2 parents 52c77b8 + ed91a4b commit fbd1d65

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

crates/bdk/src/descriptor/checksum.rs

Lines changed: 6 additions & 41 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,39 +89,10 @@ 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()) })
108-
}
109-
110-
// TODO in release 0.25.0, remove get_checksum_bytes and get_checksum
111-
// TODO in release 0.25.0, consolidate calc_checksum_bytes_internal into calc_checksum_bytes
112-
113-
/// Compute the checksum bytes of a descriptor
114-
#[deprecated(
115-
since = "0.24.0",
116-
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."
117-
)]
118-
pub fn get_checksum_bytes(desc: &str) -> Result<[u8; 8], DescriptorError> {
119-
calc_checksum_bytes_internal(desc, false)
120-
}
121-
122-
/// Compute the checksum of a descriptor
123-
#[deprecated(
124-
since = "0.24.0",
125-
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."
126-
)]
127-
pub fn get_checksum(desc: &str) -> Result<String, DescriptorError> {
128-
// unsafe is okay here as the checksum only uses bytes in `CHECKSUM_CHARSET`
129-
calc_checksum_bytes_internal(desc, false)
130-
.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()) })
13196
}
13297

13398
#[cfg(test)]

0 commit comments

Comments
 (0)