Skip to content

Commit

Permalink
Update load_key.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
mm9942 authored Jan 22, 2024
1 parent 0ed6373 commit 0c446a9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/load_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ pub struct Decapsulation {
}

impl Encapsulation {
pub async fn load(path: &str) -> Result<Self, KeychainError> {
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<Self, KeychainError> {
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 {
Expand Down

0 comments on commit 0c446a9

Please sign in to comment.