@@ -14,10 +14,7 @@ use core::{
14
14
ops:: { Add , Sub } ,
15
15
str,
16
16
} ;
17
- use hybrid_array:: {
18
- typenum:: { U1 , U24 , U28 , U32 , U48 , U66 } ,
19
- Array , ArraySize ,
20
- } ;
17
+ use hybrid_array:: { typenum:: U1 , Array , ArraySize } ;
21
18
22
19
#[ cfg( feature = "alloc" ) ]
23
20
use alloc:: boxed:: Box ;
@@ -34,7 +31,9 @@ use zeroize::Zeroize;
34
31
/// Trait for supported modulus sizes which precomputes the typenums for various point encodings so
35
32
/// they don't need to be included as bounds.
36
33
// 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
+ {
38
37
/// Size of a compressed point for the given elliptic curve when encoded using the SEC1
39
38
/// `Elliptic-Curve-Point-to-Octet-String` algorithm (including leading `0x02` or `0x03`
40
39
/// tag byte).
@@ -50,27 +49,21 @@ pub trait ModulusSize: 'static + ArraySize + Copy + Debug {
50
49
51
50
/// Size of an untagged point for given elliptic curve, i.e. size of two serialized base field
52
51
/// 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 > ;
59
53
}
60
54
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 ;
69
65
}
70
66
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
-
74
67
/// SEC1 encoded curve point.
75
68
///
76
69
/// This type is an enum over the compressed and uncompressed encodings,
0 commit comments