From fc99c32c3d6e379ccbc9de8d52dde8efb3bcbb10 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 21 Jun 2021 17:28:55 +0200 Subject: [PATCH] signatures: Upgrade pkcs8 --- crates/ruma-signatures/Cargo.toml | 2 +- crates/ruma-signatures/src/keys.rs | 12 ++++++------ crates/ruma-signatures/src/lib.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/ruma-signatures/Cargo.toml b/crates/ruma-signatures/Cargo.toml index 6e973a45..87a5d89d 100644 --- a/crates/ruma-signatures/Cargo.toml +++ b/crates/ruma-signatures/Cargo.toml @@ -21,7 +21,7 @@ unstable-exhaustive-types = [] [dependencies] base64 = "0.13.0" ed25519-dalek = "1.0.1" -pkcs8 = { version = "0.6.1", features = ["alloc"] } +pkcs8 = { version = "0.7.0", features = ["alloc"] } # because dalek uses an older version of rand_core rand = { version = "0.7", features = ["getrandom"] } ruma-identifiers = { version = "0.19.3", path = "../ruma-identifiers" } diff --git a/crates/ruma-signatures/src/keys.rs b/crates/ruma-signatures/src/keys.rs index cfba7034..8dbe14da 100644 --- a/crates/ruma-signatures/src/keys.rs +++ b/crates/ruma-signatures/src/keys.rs @@ -9,7 +9,7 @@ use ed25519_dalek::{ExpandedSecretKey, PublicKey, SecretKey}; use pkcs8::{ der::{Decodable, Encodable}, - AlgorithmIdentifier, ObjectIdentifier, OneAsymmetricKey, PrivateKeyInfo, + AlgorithmIdentifier, ObjectIdentifier, PrivateKeyInfo, }; use crate::{signatures::Signature, Algorithm, Error, ParseError}; @@ -90,13 +90,13 @@ impl Ed25519KeyPair { /// generated from the private key. This is a fallback and extra validation against /// corruption or pub fn from_der(document: &[u8], version: String) -> Result { - let oak = OneAsymmetricKey::from_der(document).map_err(Error::DerParse)?; + let oak = PrivateKeyInfo::from_der(document).map_err(Error::DerParse)?; Self::from_pkcs8_oak(oak, version) } - /// Constructs a key pair from [`pkcs8::OneAsymmetricKey`]. - pub fn from_pkcs8_oak(oak: OneAsymmetricKey<'_>, version: String) -> Result { + /// Constructs a key pair from [`pkcs8::PrivateKeyInfo`]. + pub fn from_pkcs8_oak(oak: PrivateKeyInfo<'_>, version: String) -> Result { Self::new(oak.algorithm.oid, oak.private_key, oak.public_key, version) } @@ -136,14 +136,14 @@ impl Ed25519KeyPair { let mut private: Vec = vec![0x04, 0x20]; private.extend_from_slice(secret.as_bytes()); - let oak = OneAsymmetricKey { + let pkinfo = PrivateKeyInfo { algorithm: AlgorithmIdentifier { oid: ED25519_OID, parameters: None }, private_key: private.as_ref(), attributes: None, public_key: Some(public.as_bytes()), }; - oak.to_vec().map_err(Error::DerParse) + pkinfo.to_vec().map_err(Error::DerParse) } /// Returns the version string for this keypair. diff --git a/crates/ruma-signatures/src/lib.rs b/crates/ruma-signatures/src/lib.rs index 5b015651..08281beb 100644 --- a/crates/ruma-signatures/src/lib.rs +++ b/crates/ruma-signatures/src/lib.rs @@ -105,7 +105,7 @@ mod tests { use std::collections::BTreeMap; use base64::{decode_config, encode_config, STANDARD_NO_PAD}; - use pkcs8::{der::Decodable, OneAsymmetricKey}; + use pkcs8::{der::Decodable, PrivateKeyInfo}; use ruma_identifiers::RoomVersionId; use serde_json::{from_str as from_json_str, to_string as to_json_string}; @@ -121,7 +121,7 @@ mod tests { /// Convenience method for getting the public key as a string fn public_key_string() -> String { encode_config( - &OneAsymmetricKey::from_der(&decode_config(PKCS8, STANDARD_NO_PAD).unwrap()) + &PrivateKeyInfo::from_der(&decode_config(PKCS8, STANDARD_NO_PAD).unwrap()) .unwrap() .public_key .unwrap(),