2121#[ cfg( feature = "std" ) ]
2222extern crate std;
2323
24- pub mod encoding;
2524pub mod error;
2625pub mod ops;
2726pub mod point;
@@ -51,11 +50,14 @@ use core::{
5150 ops:: { Add , Mul } ,
5251} ;
5352use generic_array:: { typenum:: Unsigned , ArrayLength , GenericArray } ;
54- use subtle:: { ConditionallySelectable , ConstantTimeEq } ;
53+ use subtle:: { ConditionallySelectable , ConstantTimeEq , CtOption } ;
5554
5655#[ cfg( feature = "rand_core" ) ]
5756use rand_core:: { CryptoRng , RngCore } ;
5857
58+ /// Byte array containing a serialized scalar value (i.e. an integer)
59+ pub type ElementBytes < C > = GenericArray < u8 , <C as Curve >:: ElementSize > ;
60+
5961/// Elliptic curve.
6062///
6163/// This trait is intended to be impl'd by a ZST which represents a concrete
@@ -78,18 +80,19 @@ pub trait Arithmetic: Curve {
7880 type Scalar : ConditionallySelectable
7981 + ConstantTimeEq
8082 + Default
81- + encoding :: FromBytes < Size = Self :: ElementSize > ;
83+ + FromBytes < Size = Self :: ElementSize > ;
8284
8385 /// Affine point type for a given curve
8486 type AffinePoint : ConditionallySelectable + Mul < scalar:: NonZeroScalar < Self > > + point:: Generator ;
8587}
8688
87- /// Associate an object identifier (OID) with a curve
88- #[ cfg( feature = "oid" ) ]
89- #[ cfg_attr( docsrs, doc( cfg( feature = "oid" ) ) ) ]
90- pub trait Identifier : Curve {
91- /// Object Identifier (OID) for this curve
92- const OID : oid:: ObjectIdentifier ;
89+ /// Try to decode the given bytes into a curve element
90+ pub trait FromBytes : ConditionallySelectable + Sized {
91+ /// Size of the serialized byte array
92+ type Size : ArrayLength < u8 > ;
93+
94+ /// Try to decode this object from bytes
95+ fn from_bytes ( bytes : & GenericArray < u8 , Self :: Size > ) -> CtOption < Self > ;
9396}
9497
9598/// Randomly generate a value.
@@ -102,5 +105,10 @@ pub trait Generate {
102105 fn generate ( rng : impl CryptoRng + RngCore ) -> Self ;
103106}
104107
105- /// Byte array containing a serialized scalar value (i.e. an integer)
106- pub type ElementBytes < C > = GenericArray < u8 , <C as Curve >:: ElementSize > ;
108+ /// Associate an object identifier (OID) with a curve
109+ #[ cfg( feature = "oid" ) ]
110+ #[ cfg_attr( docsrs, doc( cfg( feature = "oid" ) ) ) ]
111+ pub trait Identifier : Curve {
112+ /// Object Identifier (OID) for this curve
113+ const OID : oid:: ObjectIdentifier ;
114+ }
0 commit comments