Ensure backward compatibility of the "checksum inception" bug

`Wallet` stores the descriptors' checksum in the database for safety.
Previously, the checksum used was a checksum of a descriptor that
already had a checksum.

This PR allows for backward-compatibility of databases created with this
bug.
This commit is contained in:
志宇
2022-09-29 14:24:28 +08:00
parent fd34956c29
commit e2a4a5884b
3 changed files with 51 additions and 9 deletions

View File

@@ -83,7 +83,7 @@ pub fn get_checksum_bytes(mut desc: &str, exclude_hash: bool) -> Result<[u8; 8],
// if input data already had a checksum, check calculated checksum against original checksum
if let Some(original_checksum) = original_checksum {
if original_checksum.as_bytes() != &checksum {
if original_checksum.as_bytes() != checksum {
return Err(DescriptorError::InvalidDescriptorChecksum);
}
}

View File

@@ -88,7 +88,7 @@ impl IntoWalletDescriptor for &str {
let descriptor = match self.split_once('#') {
Some((desc, original_checksum)) => {
let checksum = get_checksum_bytes(desc, false)?;
if original_checksum.as_bytes() != &checksum {
if original_checksum.as_bytes() != checksum {
return Err(DescriptorError::InvalidDescriptorChecksum);
}
desc