@@ -14,10 +14,7 @@ use core::{
1414 ops:: { Add , Sub } ,
1515 str,
1616} ;
17- use hybrid_array:: {
18- typenum:: { U1 , U24 , U28 , U32 , U48 , U66 } ,
19- Array , ArraySize ,
20- } ;
17+ use hybrid_array:: { typenum:: U1 , Array , ArraySize } ;
2118
2219#[ cfg( feature = "alloc" ) ]
2320use alloc:: boxed:: Box ;
@@ -34,7 +31,9 @@ use zeroize::Zeroize;
3431/// Trait for supported modulus sizes which precomputes the typenums for various point encodings so
3532/// they don't need to be included as bounds.
3633// TODO(tarcieri): replace this all with const generic expressions.
37- pub trait ModulusSize : ' static + ArraySize + Copy + Debug {
34+ pub trait ModulusSize :
35+ ' static + ArraySize + Copy + Debug + Add < U1 , Output = Self :: CompressedPointSize >
36+ {
3837 /// Size of a compressed point for the given elliptic curve when encoded using the SEC1
3938 /// `Elliptic-Curve-Point-to-Octet-String` algorithm (including leading `0x02` or `0x03`
4039 /// tag byte).
@@ -50,27 +49,21 @@ pub trait ModulusSize: 'static + ArraySize + Copy + Debug {
5049
5150 /// Size of an untagged point for given elliptic curve, i.e. size of two serialized base field
5251 /// elements when concatenated.
53- type UntaggedPointSize : ' static
54- + ArraySize
55- + Copy
56- + Debug
57- + Add < U1 , Output = Self :: UncompressedPointSize >
58- + Sub < Self , Output = Self > ;
52+ type UntaggedPointSize : ' static + ArraySize + Copy + Debug + Sub < Self , Output = Self > ;
5953}
6054
61- macro_rules! impl_modulus_size {
62- ( $( $size: ty) ,+) => {
63- $( impl ModulusSize for $size {
64- type CompressedPointSize = <$size as Add <U1 >>:: Output ;
65- type UncompressedPointSize = <Self :: UntaggedPointSize as Add <U1 >>:: Output ;
66- type UntaggedPointSize = <$size as Add >:: Output ;
67- } ) +
68- }
55+ impl < T > ModulusSize for T
56+ where
57+ T : ' static + ArraySize + Copy + Debug ,
58+ T : Add < U1 , Output : ' static + ArraySize + Copy + Debug > ,
59+ T : Add < T , Output : ' static + ArraySize + Copy + Debug + Sub < T , Output = T > > ,
60+ <T as Add < U1 > >:: Output : Add < T , Output : ' static + ArraySize + Copy + Debug > ,
61+ {
62+ type CompressedPointSize = <T as Add < U1 > >:: Output ;
63+ type UncompressedPointSize = <Self :: CompressedPointSize as Add < T > >:: Output ;
64+ type UntaggedPointSize = <T as Add < T > >:: Output ;
6965}
7066
71- // Support for 192-bit, 224-bit, 256-bit, 384-bit, and 521-bit modulus sizes
72- impl_modulus_size ! ( U24 , U28 , U32 , U48 , U66 ) ;
73-
7467/// SEC1 encoded curve point.
7568///
7669/// This type is an enum over the compressed and uncompressed encodings,
0 commit comments