Skip to content

Commit

Permalink
Let encoding types be generic over lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jan 5, 2024
1 parent 69006c3 commit 9521468
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions aws-lc-rs/src/agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,14 @@ impl PrivateKey {
}
}

impl AsDer<EcPrivateKeyRfc5915Der> for PrivateKey {
impl AsDer<EcPrivateKeyRfc5915Der<'static>> for PrivateKey {
/// Serializes the key as a DER-encoded `ECPrivateKey` (RFC 5915) structure.
///
/// X25519 is not supported.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der, Unspecified> {
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der<'static>, Unspecified> {
if AlgorithmID::X25519 == self.inner_key.algorithm().id {
return Err(Unspecified);
}
Expand All @@ -461,14 +461,14 @@ impl AsDer<EcPrivateKeyRfc5915Der> for PrivateKey {
}
}

impl AsBigEndian<EcPrivateKeyBin> for PrivateKey {
impl AsBigEndian<EcPrivateKeyBin<'static>> for PrivateKey {
/// Exposes the private key encoded as a big-endian fixed-length integer.
///
/// X25519 is not supported.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin, Unspecified> {
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin<'static>, Unspecified> {
if AlgorithmID::X25519 == self.inner_key.algorithm().id {
return Err(Unspecified);
}
Expand All @@ -482,14 +482,14 @@ impl AsBigEndian<EcPrivateKeyBin> for PrivateKey {
}
}

impl AsBigEndian<Curve25519SeedBin> for PrivateKey {
impl AsBigEndian<Curve25519SeedBin<'static>> for PrivateKey {
/// Exposes the seed encoded as a big-endian fixed-length integer.
///
/// Only X25519 is supported.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_be_bytes(&self) -> Result<Curve25519SeedBin, Unspecified> {
fn as_be_bytes(&self) -> Result<Curve25519SeedBin<'static>, Unspecified> {
if AlgorithmID::X25519 != self.inner_key.algorithm().id {
return Err(Unspecified);
}
Expand Down
4 changes: 2 additions & 2 deletions aws-lc-rs/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ pub struct PublicKey {
octets: Box<[u8]>,
}

impl AsDer<EcPublicKeyX509Der> for PublicKey {
impl AsDer<EcPublicKeyX509Der<'static>> for PublicKey {
/// Provides the public key as a DER-encoded (X.509) `SubjectPublicKeyInfo` structure.
/// # Errors
/// Returns an error if the underlying implementation is unable to marshal the point.
fn as_der(&self) -> Result<EcPublicKeyX509Der, Unspecified> {
fn as_der(&self) -> Result<EcPublicKeyX509Der<'static>, Unspecified> {
let ec_group = unsafe { LcPtr::new(EC_GROUP_new_by_curve_name(self.algorithm.id.nid()))? };
let ec_point = unsafe { ec_point_from_bytes(&ec_group, self.as_ref())? };
let ec_key = unsafe { LcPtr::new(EC_KEY_new())? };
Expand Down
8 changes: 4 additions & 4 deletions aws-lc-rs/src/ec/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ impl Debug for PrivateKey<'_> {
}
}

impl AsBigEndian<EcPrivateKeyBin> for PrivateKey<'_> {
impl AsBigEndian<EcPrivateKeyBin<'static>> for PrivateKey<'_> {
/// Exposes the private key encoded as a big-endian fixed-length integer.
///
/// For most use-cases, `EcdsaKeyPair::to_pkcs8()` should be preferred.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin, Unspecified> {
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin<'static>, Unspecified> {
unsafe {
let buffer = ec::marshal_private_key_to_buffer(
self.0.algorithm.id.private_key_size(),
Expand All @@ -303,12 +303,12 @@ impl AsBigEndian<EcPrivateKeyBin> for PrivateKey<'_> {
}
}

impl AsDer<EcPrivateKeyRfc5915Der> for PrivateKey<'_> {
impl AsDer<EcPrivateKeyRfc5915Der<'static>> for PrivateKey<'_> {
/// Serializes the key as a DER-encoded `ECPrivateKey` (RFC 5915) structure.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der, Unspecified> {
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der<'static>, Unspecified> {
unsafe {
let mut outp = null_mut::<u8>();
let ec_key = ConstPointer::new(EVP_PKEY_get0_EC_KEY(*self.0.evp_pkey))?;
Expand Down
4 changes: 2 additions & 2 deletions aws-lc-rs/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ impl Drop for Ed25519KeyPair {
/// The seed value for the `EdDSA` signature scheme using Curve25519
pub struct Seed<'a>(&'a Ed25519KeyPair);

impl AsBigEndian<Curve25519SeedBin> for Seed<'_> {
impl AsBigEndian<Curve25519SeedBin<'static>> for Seed<'_> {
/// Exposes the seed encoded as a big-endian fixed-length integer.
///
/// For most use-cases, `EcdsaKeyPair::to_pkcs8()` should be preferred.
///
/// # Errors
/// `error::Unspecified` if serialization failed.
fn as_be_bytes(&self) -> Result<Curve25519SeedBin, Unspecified> {
fn as_be_bytes(&self) -> Result<Curve25519SeedBin<'static>, Unspecified> {
let buffer = Vec::from(&self.0.private_key[..ED25519_PRIVATE_KEY_SEED_LEN]);
Ok(Curve25519SeedBin::new(buffer))
}
Expand Down
8 changes: 4 additions & 4 deletions aws-lc-rs/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ pub trait AsBigEndian<T> {
}

/// Elliptic curve private key data encoded as a big-endian fixed-length integer.
pub type EcPrivateKeyBin = Buffer<'static, EcPrivateKeyBinType>;
pub type EcPrivateKeyBin<'a> = Buffer<'a, EcPrivateKeyBinType>;

/// Elliptic curve private key as a DER-encoded `ECPrivateKey` (RFC 5915) structure.
pub type EcPrivateKeyRfc5915Der = Buffer<'static, EcPrivateKeyRfc5915DerType>;
pub type EcPrivateKeyRfc5915Der<'a> = Buffer<'a, EcPrivateKeyRfc5915DerType>;

/// An elliptic curve public key as a DER-encoded (X509) `SubjectPublicKeyInfo` structure
pub type EcPublicKeyX509Der = Buffer<'static, EcPublicKeyX509DerType>;
pub type EcPublicKeyX509Der<'a> = Buffer<'a, EcPublicKeyX509DerType>;

/// Elliptic curve private key data encoded as a big-endian fixed-length integer.
pub type Curve25519SeedBin = Buffer<'static, Curve25519SeedBufferType>;
pub type Curve25519SeedBin<'a> = Buffer<'a, Curve25519SeedBufferType>;

0 comments on commit 9521468

Please sign in to comment.