Skip to content

Commit

Permalink
cipher: block cipher trait blanket impls for refs (#441)
Browse files Browse the repository at this point in the history
Previously `cipher` contained blanket impls of block cipher traits for
reference types, which was leveraged in e.g. `aes-gcm` and
`aes-gcm-siv`. However, somewhere in the course of refactoring they were
removed.

This commit adds them back.
  • Loading branch information
tarcieri committed Dec 30, 2020
1 parent 5aa64b2 commit f40e698
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cipher/src/block.rs
Expand Up @@ -156,3 +156,44 @@ impl<Alg: BlockDecrypt> BlockDecryptMut for Alg {
self.decrypt_block(block);
}
}

// Impls of block cipher traits for reference types

impl<Alg: BlockCipher> BlockCipher for &Alg {
type BlockSize = Alg::BlockSize;
type ParBlocks = Alg::ParBlocks;
}

impl<Alg: BlockEncrypt> BlockEncrypt for &Alg {
#[inline]
fn encrypt_block(&self, block: &mut Block<Self>) {
Alg::encrypt_block(self, block);
}

#[inline]
fn encrypt_par_blocks(&self, blocks: &mut ParBlocks<Self>) {
Alg::encrypt_par_blocks(self, blocks);
}

#[inline]
fn encrypt_blocks(&self, blocks: &mut [Block<Self>]) {
Alg::encrypt_blocks(self, blocks);
}
}

impl<Alg: BlockDecrypt> BlockDecrypt for &Alg {
#[inline]
fn decrypt_block(&self, block: &mut Block<Self>) {
Alg::decrypt_block(self, block);
}

#[inline]
fn decrypt_par_blocks(&self, blocks: &mut ParBlocks<Self>) {
Alg::decrypt_par_blocks(self, blocks);
}

#[inline]
fn decrypt_blocks(&self, blocks: &mut [Block<Self>]) {
Alg::decrypt_blocks(self, blocks);
}
}

0 comments on commit f40e698

Please sign in to comment.