Skip to content

Commit

Permalink
In #945fcd09 we forgot to update the following:
Browse files Browse the repository at this point in the history
impl fmt::Display trait for ParsePublicKeyError
impl std::error::Error for ParsePublicKeyError
  • Loading branch information
rockcoolsaint committed Jan 7, 2025
1 parent 70a8792 commit aa9b602
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bitcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,14 @@ impl fmt::Display for ParsePublicKeyError {
use ParsePublicKeyError::*;
match self {
Encoding(e) => write_err!(f, "string error"; e),
InvalidChar(char) => write!(f, "hex error {}", char),
InvalidChar(err) => {
let printable = (b' '..=b'~').contains(&err.invalid_char());
if printable {
write!(f, "hex error: invalid character {} at position {}", char::from(err.invalid_char()), err.pos())
} else {
write!(f, "hex error: invalid byte 0x{:02x} at position {}", err.invalid_char(), err.pos())
}
},
InvalidHexLength(got) =>
write!(f, "pubkey string should be 66 or 130 digits long, got: {}", got),
}
Expand All @@ -1050,7 +1057,8 @@ impl std::error::Error for ParsePublicKeyError {

match self {
Encoding(e) => Some(e),
InvalidChar(_) | InvalidHexLength(_) => None,
InvalidChar(err) => Some(err),
InvalidHexLength(_) => None,
}
}
}
Expand Down

0 comments on commit aa9b602

Please sign in to comment.