Skip to content

Commit

Permalink
Fix cfg's
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed Aug 25, 2023
1 parent 0ecf610 commit 56a1ee0
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions crates/bitwarden/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
use std::{collections::HashMap, fmt::Display, hash::Hash, str::FromStr};

use aes::{
cipher::{
block_padding::{Padding, Pkcs7},
generic_array::GenericArray,
typenum::U64,
BlockDecryptMut, BlockSizeUser, KeyIvInit, Unsigned,
},
Aes128, Aes256,
cipher::{generic_array::GenericArray, typenum::U64, Unsigned},
Aes256,
};
use base64::Engine;
use cbc::Decryptor;
use hmac::{
digest::{CtOutput, OutputSizeUser},
Hmac, Mac,
};
use hmac::{digest::OutputSizeUser, Hmac, Mac};
use serde::{de::Visitor, Deserialize, Serialize};
use uuid::Uuid;

use crate::{
client::encryption_settings::{EncryptionSettings, SymmetricCryptoKey},
error::{CSParseError, CryptoError, Error, Result},
error::{CSParseError, Error, Result},
util::BASE64_ENGINE,
};

Expand All @@ -32,6 +24,19 @@ use {
num_traits::cast::ToPrimitive,
};

#[cfg(feature = "mobile")]
use {
crate::error::CryptoError,
aes::{
cipher::{
block_padding::{Padding, Pkcs7},
BlockDecryptMut, BlockSizeUser, KeyIvInit,
},
Aes128,
},
hmac::digest::CtOutput,
};

#[cfg(any(feature = "internal", feature = "mobile"))]
use {crate::client::auth_settings::Kdf, sha2::Digest};

Expand Down Expand Up @@ -522,7 +527,10 @@ pub(crate) enum EncryptionType {
}

// To avoid issues, we need to make sure this is bigger or equal than all the ciphers block sizes
#[cfg(feature = "mobile")]
const MAX_BLOCK_SIZE: usize = 16;

#[cfg(feature = "mobile")]
pub(crate) struct ChunkedDecryptor {
enc_type: EncryptionType,

Expand All @@ -534,6 +542,7 @@ pub(crate) struct ChunkedDecryptor {
buf_len: usize,
}

#[cfg(feature = "mobile")]
impl ChunkedDecryptor {
/// Creates a new decryptor for a chunked cipher string
/// Important: The first chunk must contain the encryption type, MAC and IV (which are contained in the first bytes
Expand Down Expand Up @@ -718,6 +727,7 @@ impl ChunkedDecryptor {
}
}

#[cfg(feature = "mobile")]
pub(crate) fn decrypt_file(
key: SymmetricCryptoKey,
encrypted_file_path: &std::path::Path,
Expand Down

0 comments on commit 56a1ee0

Please sign in to comment.