Skip to content

Commit ea86cb5

Browse files
committed
replace other Unprintable check with upstream impl
1 parent e4e7ffe commit ea86cb5

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/descriptor/checksum.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use core::fmt;
99
use core::iter::FromIterator;
1010

11+
use bitcoin_miniscript::expression::check_valid_chars;
12+
1113
use crate::Error;
1214

1315
const INPUT_CHARSET: &str = "0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
@@ -51,11 +53,7 @@ pub fn desc_checksum(desc: &str) -> Result<String, Error> {
5153
/// if it is present and returns the descriptor string
5254
/// without the checksum
5355
pub(crate) fn verify_checksum(s: &str) -> Result<&str, Error> {
54-
for ch in s.as_bytes() {
55-
if *ch < 20 || *ch > 127 {
56-
return Err(Error::Unprintable(*ch));
57-
}
58-
}
56+
check_valid_chars(s)?;
5957

6058
let mut parts = s.splitn(2, '#');
6159
let desc_str = parts.next().unwrap();

src/policy/concrete.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::collections::HashSet;
88
use std::{error, fmt, str};
99

10+
use bitcoin_miniscript::expression::check_valid_chars;
1011
use elements::{LockTime, Sequence};
1112
#[cfg(feature = "compiler")]
1213
use {
@@ -1098,11 +1099,7 @@ impl_from_str!(
10981099
Policy<Pk>,
10991100
type Err = Error;,
11001101
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
1101-
for ch in s.as_bytes() {
1102-
if *ch < 20 || *ch > 127 {
1103-
return Err(Error::Unprintable(*ch));
1104-
}
1105-
}
1102+
check_valid_chars(s)?;
11061103

11071104
let tree = expression::Tree::from_str(s)?;
11081105
let policy: Policy<Pk> = FromTree::from_tree(&tree)?;

src/policy/semantic.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use std::str::FromStr;
77
use std::{fmt, str};
88

9+
use bitcoin_miniscript::expression::check_valid_chars;
910
use elements::{LockTime, Sequence};
1011

1112
use super::concrete::PolicyError;
@@ -287,11 +288,7 @@ impl_from_str!(
287288
Policy<Pk>,
288289
type Err = Error;,
289290
fn from_str(s: &str) -> Result<Policy<Pk>, Error> {
290-
for ch in s.as_bytes() {
291-
if *ch < 20 || *ch > 127 {
292-
return Err(Error::Unprintable(*ch));
293-
}
294-
}
291+
check_valid_chars(s)?;
295292

296293
let tree = expression::Tree::from_str(s)?;
297294
expression::FromTree::from_tree(&tree)

0 commit comments

Comments
 (0)