secure_gate/encoding/
bech32_random_ext.rs

1#[cfg(feature = "rand")]
2use crate::traits::SecureEncoding;
3#[cfg(feature = "rand")]
4use crate::traits::expose_secret::ExposeSecret;
5#[cfg(feature = "rand")]
6use crate::Bech32EncodingError;
7
8#[cfg(feature = "rand")]
9impl crate::DynamicRandom {
10    /// Borrowing encode (original random remains usable).
11    pub fn try_to_bech32(
12        &self,
13        hrp: &str,
14    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
15        self.expose_secret().try_to_bech32(hrp)
16    }
17
18    pub fn try_to_bech32m(
19        &self,
20        hrp: &str,
21    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
22        self.expose_secret().try_to_bech32m(hrp)
23    }
24
25    /// Consuming encode (raw random bytes zeroized immediately).
26    pub fn try_into_bech32(
27        self,
28        hrp: &str,
29    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
30        self.expose_secret().try_to_bech32(hrp)
31    }
32
33    pub fn try_into_bech32m(
34        self,
35        hrp: &str,
36    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
37        self.expose_secret().try_to_bech32m(hrp)
38    }
39}
40
41#[cfg(feature = "rand")]
42impl<const N: usize> crate::FixedRandom<N> {
43    /// Borrowing encode (original random remains usable).
44    pub fn try_to_bech32(
45        &self,
46        hrp: &str,
47    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
48        self.expose_secret().try_to_bech32(hrp)
49    }
50
51    pub fn try_to_bech32m(
52        &self,
53        hrp: &str,
54    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
55        self.expose_secret().try_to_bech32m(hrp)
56    }
57
58    /// Consuming encode (raw random bytes zeroized immediately).
59    pub fn try_into_bech32(
60        self,
61        hrp: &str,
62    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
63        self.expose_secret().try_to_bech32(hrp)
64    }
65
66    pub fn try_into_bech32m(
67        self,
68        hrp: &str,
69    ) -> Result<crate::encoding::bech32::Bech32String, Bech32EncodingError> {
70        self.expose_secret().try_to_bech32m(hrp)
71    }
72}