Skip to content

Commit 9bab4e8

Browse files
authored
elliptic-curve: remove ToBytes trait (#249)
We're using Into bounds for this in places right now, which suffice for existing use cases, and makes a bit redundant.
1 parent 1b3dffb commit 9bab4e8

3 files changed

Lines changed: 20 additions & 37 deletions

File tree

elliptic-curve/src/encoding.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

elliptic-curve/src/lib.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#[cfg(feature = "std")]
2222
extern crate std;
2323

24-
pub mod encoding;
2524
pub mod error;
2625
pub mod ops;
2726
pub mod point;
@@ -51,11 +50,14 @@ use core::{
5150
ops::{Add, Mul},
5251
};
5352
use generic_array::{typenum::Unsigned, ArrayLength, GenericArray};
54-
use subtle::{ConditionallySelectable, ConstantTimeEq};
53+
use subtle::{ConditionallySelectable, ConstantTimeEq, CtOption};
5554

5655
#[cfg(feature = "rand_core")]
5756
use 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+
}

elliptic-curve/src/weierstrass/public_key.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use super::{
55
point::{CompressedPoint, CompressedPointSize, UncompressedPoint, UncompressedPointSize},
66
Curve,
77
};
8-
use crate::{
9-
encoding::FromBytes, point::Generator, scalar::NonZeroScalar, Arithmetic, Error, SecretKey,
10-
};
8+
use crate::{point::Generator, scalar::NonZeroScalar, Arithmetic, Error, FromBytes, SecretKey};
119
use core::{
1210
fmt::{self, Debug},
1311
ops::{Add, Mul},

0 commit comments

Comments
 (0)