pub enum Err {
InvalidLen(usize),
InvalidChar(usize),
MixedCase(usize, usize),
MissingSeparator,
InvalidHrpLen(usize),
InvalidChecksum,
}Expand description
String parse error.
§Examples
Try to parse an empty string:
use pbech32::{Bech32, Err};
let s = ""; // empty string
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidLen(0)));Try to parse a string with an invalid character:
use pbech32::{Bech32, Err};
let s = "a 1xxxxxx"; // string with invalid bech32 character
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChar(1)));Variants§
InvalidLen(usize)
Invalid string length.
The length of a Bech32 string must be in the range 8...
The error field contains the invalid length.
Note: BIP173 limits the maximum string length to 90 characters; this library does not have a maximum string length.
§Example
Try to parse an empty string:
use pbech32::{Bech32, Err};
let s = ""; // empty string
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidLen(0)));InvalidChar(usize)
String contains an invalid character at the given position.
A Bech32 string must only contain alphanumeric ASCII characters.
The error field indicates the first invalid character position in the string.
§Example
Try to parse a string with an invalid character at position 1:
use pbech32::{Bech32, Err};
let s = "a 1xxxxxx"; // string with invalid bech32 character
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChar(1)));MixedCase(usize, usize)
String contains both uppercase and lowercase characters.
A Bech32 string must not contain both uppercase and lowercase characters.
The error fields indicate the first lowercase character position and in the string the first uppercase character position in the string, respectively.
§Example
Try to parse a string with an lowercase character at position 0 and an uppercase character at position 1:
use pbech32::{Bech32, Err};
let s = "Ab1xxxxxx"; // string with mixed-case characters
assert_eq!(s.parse::<Bech32>(), Err(Err::MixedCase(1, 0)));MissingSeparator
String is missing a separator character.
A Bech32 string must contain a 1 character between the
the human-readable part and the data part.
§Example
Try to parse a string which does not have a separator between the human-readable part and the data part:
use pbech32::{Bech32, Err};
let s = "avxxxxxx"; // string without separator
assert_eq!(s.parse::<Bech32>(), Err(Err::MissingSeparator));InvalidHrpLen(usize)
Length of Human-readable part (HRP) of string is invalid.
The length of the human-readable part of a Bech32 string must
be in the range [1..84].
The error field contains the invalid human-readable part length.
§Examples
Try to parse a string with an empty human-readable part:
use pbech32::{Bech32, Err};
let s = "1axxxxxx"; // string with empty HRP
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidHrpLen(0)));Try to parse a string with a human-readable part that is too long:
use pbech32::{Bech32, Err};
let s = str::repeat("a", 84) + "1xxxxxx"; // string with long HRP
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidHrpLen(84)));InvalidChecksum
Invalid checksum.
§Example
Try to parse a string with an invalid checksum:
use pbech32::{Bech32, Err};
let s = "a1xxxxxx"; // string with invalid checksum
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChecksum));