@@ -123,7 +123,8 @@ impl Alphabet {
123
123
// decodable, treat the string as invalid.
124
124
return Err ( ( ) ) ;
125
125
}
126
- let mut ret = Self :: decode_data ( ( data. len ( ) + 7 ) / 8 * 5 , data, & ZBASE_INV_ALPHABET ) ?;
126
+ let cap = ( data. len ( ) + 7 ) / 8 * 5 ;
127
+ let mut ret = Self :: decode_data ( cap, data, & ZBASE_INV_ALPHABET ) ?;
127
128
for c in ret. drain ( output_length..) {
128
129
if c != 0 {
129
130
// If the original string had any bits set at positions outside of the encoded data,
@@ -133,7 +134,7 @@ impl Alphabet {
133
134
}
134
135
// Check that our capacity calculation doesn't under-shoot in fuzzing
135
136
#[ cfg( fuzzing) ]
136
- assert_eq ! ( ret. capacity( ) , ( data . len ( ) + 7 ) / 8 * 5 ) ;
137
+ assert_eq ! ( ret. capacity( ) , cap ) ;
137
138
Ok ( ret)
138
139
}
139
140
@@ -183,34 +184,6 @@ impl Alphabet {
183
184
}
184
185
}
185
186
186
-
187
- // /// Encode a byte slice into a base32 string.
188
- // pub fn encode(alphabet: Alphabet, data: &[u8]) -> String {
189
- // let ret = match alphabet {
190
- // Alphabet::RFC4648 { padding } =>{
191
- // rfc4648_encode(data, padding)
192
- // },
193
- // Alphabet::ZBase32 => {
194
- // zbase32_encode(data)
195
- // }
196
- // };
197
- // String::from_utf8(ret).unwrap()
198
- // }
199
-
200
- // /// Decode a base32 string into a byte vector.
201
- // pub fn decode(alphabet: Alphabet, data: &str) -> Result<Vec<u8>, ()> {
202
- // let data = data.as_bytes();
203
- // match alphabet {
204
- // Alphabet::RFC4648 { .. } => {
205
- // rfc4648_decode(data)
206
- // },
207
- // Alphabet::ZBase32 => {
208
- // zbase32_decode(data)
209
- // },
210
- // }
211
- // }
212
-
213
-
214
187
#[ cfg( test) ]
215
188
mod tests {
216
189
use std:: fmt:: { Debug , Error , Formatter } ;
0 commit comments