Struct bech32::primitives::decode::CheckedHrpstring
source · pub struct CheckedHrpstring<'s> { /* private fields */ }
Expand description
An HRP string that has been parsed and had the checksum validated.
This type does not treat the first byte of the data in any special way i.e., as the witness
version byte. If you are parsing Bitcoin segwit addresses you likely want to use SegwitHrpstring
.
We first describe the general checksummed base32 format called Bech32 and then define Segregated Witness addresses using it.
This type abstracts over the general checksummed base32 format called Bech32.
Examples
use bech32::{Bech32m, primitives::decode::CheckedHrpstring};
// Parse a general checksummed bech32 encoded string.
let s = "abcd14g08d6qejxtdg4y5r3zarvary0c5xw7knqc5r8";
let checked = CheckedHrpstring::new::<Bech32m>(s)
.expect("valid bech32 string with a valid checksum according to the bech32m algorithm");
// Do something with the encoded data.
let _ = checked.byte_iter();
Implementations§
source§impl<'s> CheckedHrpstring<'s>
impl<'s> CheckedHrpstring<'s>
sourcepub fn new<Ck: Checksum>(s: &'s str) -> Result<Self, CheckedHrpstringError>
pub fn new<Ck: Checksum>(s: &'s str) -> Result<Self, CheckedHrpstringError>
Parses and validates an HRP string, without treating the first data character specially.
If you are validating the checksum multiple times consider using UncheckedHrpstring
.
This is equivalent to UncheckedHrpstring::new().validate_and_remove_checksum::<CK>()
.
sourcepub fn byte_iter(&self) -> ByteIter<'_> ⓘ
pub fn byte_iter(&self) -> ByteIter<'_> ⓘ
Returns an iterator that yields the data part of the parsed bech32 encoded string.
Converts the ASCII bytes representing field elements to the respective field elements, then converts the stream of field elements to a stream of bytes.
sourcepub fn validate_segwit(
self
) -> Result<SegwitHrpstring<'s>, SegwitHrpstringError>
pub fn validate_segwit( self ) -> Result<SegwitHrpstring<'s>, SegwitHrpstringError>
Converts this type to a SegwitHrpstring
after validating the witness and HRP.