From 0c446a9c0584badf5f8e43416ada964f7ad1cf34 Mon Sep 17 00:00:00 2001 From: M <149858635+mm9942@users.noreply.github.com> Date: Tue, 23 Jan 2024 00:20:45 +0100 Subject: [PATCH] Update load_key.rs --- src/load_key.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/load_key.rs b/src/load_key.rs index 2448f49..829cf0c 100644 --- a/src/load_key.rs +++ b/src/load_key.rs @@ -58,11 +58,16 @@ pub struct Decapsulation { } impl Encapsulation { - pub async fn load(path: &str) -> Result { - let public_key_bytes = File::load(path, FileType::PublicKey).await; - let public_key = PublicKey::from_bytes(&public_key_bytes) - .map_err(|_| KeychainError::EncapsulationError)?; - Ok(Self::new(public_key).await) + pub async fn load(sec_path: &str, cipher_path: &str) -> Result { + let secret_key_bytes = File::load(sec_path, FileType::SecretKey).await?; + let secret_key = SecretKey::from_bytes(&secret_key_bytes) + .map_err(|_| KeychainError::DecapsulationError)?; + + let ciphertext_bytes = File::load(cipher_path, FileType::Ciphertext).await?; + let ciphertext = Ciphertext::from_bytes(&ciphertext_bytes) + .map_err(|_| KeychainError::DecapsulationError)?; + + Ok(Self::new(secret_key, ciphertext).await) } pub async fn new(public_key: kyber1024::PublicKey) -> Self {