11use super :: * ;
22
3- pub ( crate ) struct Bech32mDecoder < ' a > {
3+ pub ( crate ) struct Bech32Decoder < ' a > {
44 data : & ' a [ u8 ] ,
55 i : usize ,
6- ty : Bech32mType ,
6+ ty : Bech32Type ,
77}
88
9- impl < ' a > Bech32mDecoder < ' a > {
10- pub ( crate ) fn byte_array < const LEN : usize > ( & mut self ) -> Result < [ u8 ; LEN ] , Bech32mError > {
9+ impl < ' a > Bech32Decoder < ' a > {
10+ pub ( crate ) fn byte_array < const LEN : usize > ( & mut self ) -> Result < [ u8 ; LEN ] , Bech32Error > {
1111 let mut array = [ 0 ; LEN ] ;
1212
1313 for ( slot, byte) in array. iter_mut ( ) . zip ( self . bytes ( LEN ) ?) {
@@ -17,7 +17,7 @@ impl<'a> Bech32mDecoder<'a> {
1717 Ok ( array)
1818 }
1919
20- fn bytes ( & mut self , len : usize ) -> Result < impl Iterator < Item = u8 > , Bech32mError > {
20+ fn bytes ( & mut self , len : usize ) -> Result < impl Iterator < Item = u8 > , Bech32Error > {
2121 let fe_len = ( len * 8 ) . div_ceil ( 5 ) ;
2222
2323 let fes = self . fes ( fe_len) ?;
@@ -26,14 +26,14 @@ impl<'a> Bech32mDecoder<'a> {
2626 let padding_len = ( i + 1 ) * 5 % 8 ;
2727
2828 if padding_len > 4 {
29- return Err ( Bech32mError :: Padding {
29+ return Err ( Bech32Error :: Padding {
3030 source : PaddingError :: TooMuch ,
3131 ty : self . ty ,
3232 } ) ;
3333 }
3434
3535 if u64:: from ( last. to_u8 ( ) . trailing_zeros ( ) ) < padding_len. into_u64 ( ) {
36- return Err ( Bech32mError :: Padding {
36+ return Err ( Bech32Error :: Padding {
3737 source : PaddingError :: NonZero ,
3838 ty : self . ty ,
3939 } ) ;
@@ -43,30 +43,30 @@ impl<'a> Bech32mDecoder<'a> {
4343 Ok ( fes. fes_to_bytes ( ) )
4444 }
4545
46- pub ( crate ) fn done ( self ) -> Result < ( ) , Bech32mError > {
46+ pub ( crate ) fn done ( self ) -> Result < ( ) , Bech32Error > {
4747 let excess = self . data . len ( ) - self . i ;
4848
4949 ensure ! {
5050 excess == 0 ,
51- bech32m_error :: Overlong { excess, ty: self . ty } ,
51+ bech32_error :: Overlong { excess, ty: self . ty } ,
5252 }
5353
5454 Ok ( ( ) )
5555 }
5656
57- pub ( crate ) fn fe ( & mut self ) -> Result < Fe32 , Bech32mError > {
57+ pub ( crate ) fn fe ( & mut self ) -> Result < Fe32 , Bech32Error > {
5858 let next = self
5959 . data
6060 . get ( self . i )
6161 . map ( |c| Fe32 :: from_char_unchecked ( * c) )
62- . context ( bech32m_error :: Truncated { ty : self . ty } ) ?;
62+ . context ( bech32_error :: Truncated { ty : self . ty } ) ?;
6363
6464 self . i += 1 ;
6565
6666 Ok ( next)
6767 }
6868
69- pub ( crate ) fn fe_array < const LEN : usize > ( & mut self ) -> Result < [ Fe32 ; LEN ] , Bech32mError > {
69+ pub ( crate ) fn fe_array < const LEN : usize > ( & mut self ) -> Result < [ Fe32 ; LEN ] , Bech32Error > {
7070 let mut array = [ Fe32 :: Q ; LEN ] ;
7171
7272 for slot in & mut array {
@@ -79,11 +79,11 @@ impl<'a> Bech32mDecoder<'a> {
7979 fn fes (
8080 & mut self ,
8181 len : usize ,
82- ) -> Result < impl Iterator < Item = Fe32 > + Clone + use < ' a > , Bech32mError > {
82+ ) -> Result < impl Iterator < Item = Fe32 > + Clone + use < ' a > , Bech32Error > {
8383 let end = self . i + len;
8484
8585 if end > self . data . len ( ) {
86- return Err ( Bech32mError :: Truncated { ty : self . ty } ) ;
86+ return Err ( Bech32Error :: Truncated { ty : self . ty } ) ;
8787 }
8888
8989 let fes = & self . data [ self . i ..end] ;
@@ -93,29 +93,29 @@ impl<'a> Bech32mDecoder<'a> {
9393 Ok ( fes. iter ( ) . map ( |c| Fe32 :: from_char_unchecked ( * c) ) )
9494 }
9595
96- pub ( crate ) fn into_bytes ( mut self ) -> Result < Vec < u8 > , Bech32mError > {
96+ pub ( crate ) fn into_bytes ( mut self ) -> Result < Vec < u8 > , Bech32Error > {
9797 let fes = self . data . len ( ) - self . i ;
9898 Ok ( self . bytes ( fes * 5 / 8 ) ?. collect ( ) )
9999 }
100100
101- pub ( crate ) fn new ( ty : Bech32mType , s : & ' a str ) -> Result < Self , Bech32mError > {
101+ pub ( crate ) fn new ( ty : Bech32Type , s : & ' a str ) -> Result < Self , Bech32Error > {
102102 let hrp_string =
103- CheckedHrpstring :: new :: < bech32:: Bech32m > ( s) . context ( bech32m_error :: Decode { ty } ) ?;
103+ CheckedHrpstring :: new :: < bech32:: Bech32m > ( s) . context ( bech32_error :: Decode { ty } ) ?;
104104
105105 let actual = hrp_string. hrp ( ) ;
106106
107107 ensure ! {
108108 actual == * ty. hrp( ) ,
109- bech32m_error :: Hrp { ty, actual } ,
109+ bech32_error :: Hrp { ty, actual } ,
110110 }
111111
112112 let mut fes = hrp_string. fe32_iter :: < std:: vec:: IntoIter < u8 > > ( ) ;
113113
114- let version = fes. next ( ) . context ( bech32m_error :: Truncated { ty } ) ?;
114+ let version = fes. next ( ) . context ( bech32_error :: Truncated { ty } ) ?;
115115
116116 ensure ! {
117- version == BECH32M_VERSION ,
118- bech32m_error :: UnsupportedVersion { ty, version } ,
117+ version == BECH32_VERSION ,
118+ bech32_error :: UnsupportedVersion { ty, version } ,
119119 }
120120
121121 Ok ( Self {
0 commit comments