Skip to content

Commit

Permalink
client: Expose native_crypto API generate_iv() and encrypt()
Browse files Browse the repository at this point in the history
This change expose native_crypto API generate_iv() and encrypt() under
unstable feature.
We need this change for server side.

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed May 5, 2024
1 parent 145f964 commit e694e2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
mod native;
#[cfg(feature = "native_crypto")]
pub(crate) use native::*;
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
pub use native::*;

#[cfg(feature = "openssl_crypto")]
mod openssl;
Expand Down
4 changes: 2 additions & 2 deletions client/src/crypto/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type EncAlg = cbc::Encryptor<aes::Aes128>;
type DecAlg = cbc::Decryptor<aes::Aes128>;
type MacAlg = hmac::Hmac<sha2::Sha256>;

pub(crate) fn encrypt(data: impl AsRef<[u8]>, key: &Key, iv: impl AsRef<[u8]>) -> Vec<u8> {
pub fn encrypt(data: impl AsRef<[u8]>, key: &Key, iv: impl AsRef<[u8]>) -> Vec<u8> {
let mut blob = vec![0; data.as_ref().len() + EncAlg::block_size()];

// Unwrapping since adding `CIPHER_BLOCK_SIZE` to array is enough space for
Expand Down Expand Up @@ -117,7 +117,7 @@ pub(crate) fn generate_aes_key(
okm
}

pub(crate) fn generate_iv() -> Vec<u8> {
pub fn generate_iv() -> Vec<u8> {
EncAlg::generate_iv(cipher::rand_core::OsRng).to_vec()
}

Expand Down

0 comments on commit e694e2e

Please sign in to comment.