Skip to content

Commit

Permalink
adds Seek trait requirement to KemReader
Browse files Browse the repository at this point in the history
  • Loading branch information
seanwatters committed Mar 14, 2024
1 parent cc45f06 commit 0a11e65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[package]
authors = ["sean watters <sean@watters.io>"]
description = "Enabling E2EE for a broad range of applications."
description = "Enabling E2EE for a range of applications."
categories = ["cryptography"]
edition = "2021"
homepage = "https://github.com/seanwatters/rgp"
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Licensed under the MIT license <LICENSE or https://opensource.org/licenses/MIT>.
This file may not be copied, modified, or distributed except according to those terms.
*/

use std::{fs::File, io::Read};
use std::fs::File;
use std::io::{Read, Seek};

use super::{dh_encrypt, hmac_encrypt, kem_encrypt, session_encrypt, KemKeyReader, KEY_SIZE};

/// encapsulates the parameters and mode for encryption.
pub enum Encrypt<'a, R: Read = File> {
pub enum Encrypt<'a, R: Read + Seek = File> {
/// generates random content key and encrypts for all
/// recipients with their respective Diffie-Hellman shared secret.
Dh(
Expand Down
10 changes: 5 additions & 5 deletions src/crypto/modes/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::super::{
base_decrypt, base_encrypt, bytes_to_usize, usize_to_bytes, KEY_SIZE, NONCE_SIZE,
};

use std::io::{BufReader, Read};
use std::io::{BufReader, Read, Seek};
#[cfg(feature = "multi-thread")]
use std::sync::mpsc::channel;

Expand Down Expand Up @@ -108,14 +108,14 @@ pub fn generate_kem_keys() -> ([u8; KEM_SECRET_KEY_SIZE], [u8; KEM_PUB_KEY_SIZE]
}

/// for reading a large volume of Classic McEliece public keys
pub struct KemKeyReader<R: Read> {
pub struct KemKeyReader<R: Read + Seek> {
pub reader: BufReader<R>,

/// for Kem + Dh hybrid
pub dh_priv_key: Option<[u8; KEY_SIZE]>,
}

impl<R: Read> KemKeyReader<R> {
impl<R: Read + Seek> KemKeyReader<R> {
/// public key reader with a buffer size of 261120.
///
/// for files that contain only McEliece public keys all in one line.
Expand All @@ -140,7 +140,7 @@ impl<R: Read> KemKeyReader<R> {

/// per-recipient content key encryption.
#[inline(always)]
fn kem_encrypt_keys<R: Read>(
fn kem_encrypt_keys<R: Read + Seek>(
key_reader: &mut KemKeyReader<R>,
nonce: &GenericArray<u8, typenum::U24>,
content_key: &GenericArray<u8, typenum::U32>,
Expand Down Expand Up @@ -222,7 +222,7 @@ fn kem_encrypt_keys<R: Read>(

/// kem encryption.
#[inline(always)]
pub fn kem_encrypt<'a, R: Read>(
pub fn kem_encrypt<'a, R: Read + Seek>(
fingerprint: [u8; 32],
mut content: Vec<u8>,
key_reader: &mut KemKeyReader<R>,
Expand Down

0 comments on commit 0a11e65

Please sign in to comment.