@@ -5,7 +5,7 @@ use alloc::{boxed::Box, vec::Vec};
55use core:: fmt;
66
77#[ cfg( feature = "bigint" ) ]
8- use crate :: { NonZeroUint , OddUint , Uint } ;
8+ use crate :: Uint ;
99
1010#[ cfg( feature = "subtle" ) ]
1111use subtle:: { Choice , ConstantTimeEq } ;
@@ -207,42 +207,6 @@ impl fmt::UpperHex for Mpint {
207207 }
208208}
209209
210- #[ cfg( feature = "bigint" ) ]
211- impl TryFrom < NonZeroUint > for Mpint {
212- type Error = Error ;
213-
214- fn try_from ( uint : NonZeroUint ) -> Result < Mpint > {
215- Mpint :: try_from ( & uint)
216- }
217- }
218-
219- #[ cfg( feature = "bigint" ) ]
220- impl TryFrom < & NonZeroUint > for Mpint {
221- type Error = Error ;
222-
223- fn try_from ( uint : & NonZeroUint ) -> Result < Mpint > {
224- Self :: try_from ( uint. as_ref ( ) )
225- }
226- }
227-
228- #[ cfg( feature = "bigint" ) ]
229- impl TryFrom < OddUint > for Mpint {
230- type Error = Error ;
231-
232- fn try_from ( uint : OddUint ) -> Result < Mpint > {
233- Mpint :: try_from ( & uint)
234- }
235- }
236-
237- #[ cfg( feature = "bigint" ) ]
238- impl TryFrom < & OddUint > for Mpint {
239- type Error = Error ;
240-
241- fn try_from ( uint : & OddUint ) -> Result < Mpint > {
242- Self :: try_from ( uint. as_ref ( ) )
243- }
244- }
245-
246210#[ cfg( feature = "bigint" ) ]
247211impl TryFrom < Uint > for Mpint {
248212 type Error = Error ;
@@ -262,46 +226,6 @@ impl TryFrom<&Uint> for Mpint {
262226 }
263227}
264228
265- #[ cfg( feature = "bigint" ) ]
266- impl TryFrom < Mpint > for NonZeroUint {
267- type Error = Error ;
268-
269- fn try_from ( mpint : Mpint ) -> Result < NonZeroUint > {
270- NonZeroUint :: try_from ( & mpint)
271- }
272- }
273-
274- #[ cfg( feature = "bigint" ) ]
275- impl TryFrom < & Mpint > for NonZeroUint {
276- type Error = Error ;
277-
278- fn try_from ( mpint : & Mpint ) -> Result < NonZeroUint > {
279- let uint = Uint :: try_from ( mpint) ?;
280- NonZeroUint :: new ( uint)
281- . into_option ( )
282- . ok_or ( Error :: MpintEncoding )
283- }
284- }
285-
286- #[ cfg( feature = "bigint" ) ]
287- impl TryFrom < Mpint > for OddUint {
288- type Error = Error ;
289-
290- fn try_from ( mpint : Mpint ) -> Result < OddUint > {
291- OddUint :: try_from ( & mpint)
292- }
293- }
294-
295- #[ cfg( feature = "bigint" ) ]
296- impl TryFrom < & Mpint > for OddUint {
297- type Error = Error ;
298-
299- fn try_from ( mpint : & Mpint ) -> Result < OddUint > {
300- let uint = Uint :: try_from ( mpint) ?;
301- OddUint :: new ( uint) . into_option ( ) . ok_or ( Error :: MpintEncoding )
302- }
303- }
304-
305229#[ cfg( feature = "bigint" ) ]
306230impl TryFrom < Mpint > for Uint {
307231 type Error = Error ;
@@ -316,14 +240,9 @@ impl TryFrom<&Mpint> for Uint {
316240 type Error = Error ;
317241
318242 fn try_from ( mpint : & Mpint ) -> Result < Uint > {
243+ // TODO(tarcieri): enforce a maximum size?
319244 let bytes = mpint. as_positive_bytes ( ) . ok_or ( Error :: MpintEncoding ) ?;
320- let bits_precision = bytes
321- . len ( )
322- . checked_mul ( 8 )
323- . and_then ( |n| u32:: try_from ( n) . ok ( ) )
324- . ok_or ( Error :: MpintEncoding ) ?;
325-
326- Ok ( Uint :: from_be_slice ( bytes, bits_precision) ?)
245+ Ok ( Uint :: from_be_slice_vartime ( bytes) )
327246 }
328247}
329248
0 commit comments