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>

source

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>().

source

pub fn hrp(&self) -> Hrp

Returns the human-readable part.

source

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.

source

pub fn validate_segwit( self ) -> Result<SegwitHrpstring<'s>, SegwitHrpstringError>

Converts this type to a SegwitHrpstring after validating the witness and HRP.

Trait Implementations§

source§

impl<'s> Debug for CheckedHrpstring<'s>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s> RefUnwindSafe for CheckedHrpstring<'s>

§

impl<'s> Send for CheckedHrpstring<'s>

§

impl<'s> Sync for CheckedHrpstring<'s>

§

impl<'s> Unpin for CheckedHrpstring<'s>

§

impl<'s> UnwindSafe for CheckedHrpstring<'s>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.