Skip to content

Commit

Permalink
refactor: use BlockBytes for sequential buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGw committed May 25, 2024
1 parent d90e626 commit f267fae
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ctr::Aes256Ctr32;
use error::Error;
use gcm::{setup as setup_gcm, GcmGhash};
use subtle::ConstantTimeEq;
use types::{Bytes, Key, Nonce, Result};
use types::{BlockBytes, Bytes, Key, Nonce, Result};

pub struct Aes256Gcm {
ctr: Aes256Ctr32,
Expand All @@ -26,14 +26,14 @@ impl Aes256Gcm {
Ok(Self { ctr, ghash })
}

pub fn finalize(self) -> [u8; TAG_SIZE] {
pub fn finalize(self) -> BlockBytes {
self.ghash.finalize()
}
}

pub trait Encrypt {
fn encrypt(&mut self, buf: &mut Bytes);
fn compute_tag(self) -> [u8; TAG_SIZE];
fn compute_tag(self) -> BlockBytes;
}

pub trait Decrypt {
Expand All @@ -47,7 +47,7 @@ impl Encrypt for Aes256Gcm {
self.ghash.update(buf);
}

fn compute_tag(self) -> [u8; TAG_SIZE] {
fn compute_tag(self) -> BlockBytes {
self.finalize()
}
}
Expand Down Expand Up @@ -103,7 +103,6 @@ mod tests {

#[test]
fn test_aes256_ctr32_encryption_decryption() {
// Test data
let key = [0u8; 32];
let nonce = [0u8; 12];
let init_ctr = 0;
Expand Down

0 comments on commit f267fae

Please sign in to comment.