pub trait ToBech32 {
// Required methods
fn try_to_bech32(&self, hrp: &str) -> Result<String, Bech32Error>;
fn try_to_bech32_zeroizing(
&self,
hrp: &str,
) -> Result<EncodedSecret, Bech32Error>;
}Expand description
Extension trait for encoding byte data as Bech32 (BIP-173) strings.
Requires feature encoding-bech32.
Blanket-implemented for all AsRef<[u8]> types. Use try_to_bech32
with the protocol’s HRP. Test empty and invalid HRP inputs in security-critical code.
Required Methods§
Sourcefn try_to_bech32(&self, hrp: &str) -> Result<String, Bech32Error>
fn try_to_bech32(&self, hrp: &str) -> Result<String, Bech32Error>
Fallibly encodes bytes as a Bech32 (BIP-173) string with the given HRP.
§Errors
Bech32Error::InvalidHrp—hrpcontains invalid characters.Bech32Error::OperationFailed— encoding failure.
§Examples
use secure_gate::ToBech32;
let encoded = b"hello".try_to_bech32("test")?;
assert!(encoded.starts_with("test1"));Sourcefn try_to_bech32_zeroizing(
&self,
hrp: &str,
) -> Result<EncodedSecret, Bech32Error>
fn try_to_bech32_zeroizing( &self, hrp: &str, ) -> Result<EncodedSecret, Bech32Error>
Fallibly encodes bytes as Bech32 and wraps the result in crate::EncodedSecret.