Skip to content

Commit

Permalink
Fix clippy and add covector changefile
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-rufi committed Nov 14, 2022
1 parent eb27efc commit 0a2331a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changes/mobile-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iota-stronghold": patch
---

Disable frag module for android and ios targets
24 changes: 12 additions & 12 deletions client/src/procedures/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,17 @@ impl UseSecret<1> for Hmac {
match self.hash_type {
Sha2Hash::Sha256 => {
let mut mac = [0; SHA256_LEN];
HMAC_SHA256(&self.msg, &*guards[0].borrow(), &mut mac);
HMAC_SHA256(&self.msg, &guards[0].borrow(), &mut mac);
Ok(mac.to_vec())
}
Sha2Hash::Sha384 => {
let mut mac = [0; SHA384_LEN];
HMAC_SHA384(&self.msg, &*guards[0].borrow(), &mut mac);
HMAC_SHA384(&self.msg, &guards[0].borrow(), &mut mac);
Ok(mac.to_vec())
}
Sha2Hash::Sha512 => {
let mut mac = [0; SHA512_LEN];
HMAC_SHA512(&self.msg, &*guards[0].borrow(), &mut mac);
HMAC_SHA512(&self.msg, &guards[0].borrow(), &mut mac);
Ok(mac.to_vec())
}
}
Expand All @@ -696,21 +696,21 @@ impl DeriveSecret<1> for Hkdf {
let secret = match self.hash_type {
Sha2Hash::Sha256 => {
let mut okm = [0; SHA256_LEN];
hkdf::Hkdf::<Sha256>::new(Some(&self.salt), &*guards[0].borrow())
hkdf::Hkdf::<Sha256>::new(Some(&self.salt), &guards[0].borrow())
.expand(&self.label, &mut okm)
.expect("okm is the correct length");
okm.to_vec()
}
Sha2Hash::Sha384 => {
let mut okm = [0; SHA384_LEN];
hkdf::Hkdf::<Sha384>::new(Some(&self.salt), &*guards[0].borrow())
hkdf::Hkdf::<Sha384>::new(Some(&self.salt), &guards[0].borrow())
.expand(&self.label, &mut okm)
.expect("okm is the correct length");
okm.to_vec()
}
Sha2Hash::Sha512 => {
let mut okm = [0; SHA512_LEN];
hkdf::Hkdf::<Sha512>::new(Some(&self.salt), &*guards[0].borrow())
hkdf::Hkdf::<Sha512>::new(Some(&self.salt), &guards[0].borrow())
.expand(&self.label, &mut okm)
.expect("okm is the correct length");
okm.to_vec()
Expand Down Expand Up @@ -807,7 +807,7 @@ impl UseSecret<1> for AeadEncrypt {
AeadCipher::XChaCha20Poly1305 => Tag::<XChaCha20Poly1305>::default(),
};
f(
&*guards[0].borrow(),
&guards[0].borrow(),
&self.nonce,
&self.associated_data,
&self.plaintext,
Expand Down Expand Up @@ -851,7 +851,7 @@ impl UseSecret<1> for AeadDecrypt {
AeadCipher::XChaCha20Poly1305 => XChaCha20Poly1305::try_decrypt,
};
f(
&*guards[0].borrow(),
&guards[0].borrow(),
&self.nonce,
&self.associated_data,
&mut ptx,
Expand Down Expand Up @@ -942,21 +942,21 @@ impl ConcatKdf {

for count in 0..rounds {
// Iteration Count
Digest::update(&mut digest, &(count as u32 + 1).to_be_bytes());
Digest::update(&mut digest, (count as u32 + 1).to_be_bytes());

// Derived Secret
Digest::update(&mut digest, z);

// AlgorithmId
Digest::update(&mut digest, &(alg.len() as u32).to_be_bytes());
Digest::update(&mut digest, (alg.len() as u32).to_be_bytes());
Digest::update(&mut digest, alg.as_bytes());

// PartyUInfo
Digest::update(&mut digest, &(apu.len() as u32).to_be_bytes());
Digest::update(&mut digest, (apu.len() as u32).to_be_bytes());
Digest::update(&mut digest, apu);

// PartyVInfo
Digest::update(&mut digest, &(apv.len() as u32).to_be_bytes());
Digest::update(&mut digest, (apv.len() as u32).to_be_bytes());
Digest::update(&mut digest, apv);

// SuppPubInfo
Expand Down
4 changes: 2 additions & 2 deletions client/src/types/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Snapshot {
let mut data = Vec::new();
self.db.get_guard::<Infallible, _>(&pkey, vid, rid, |guarded_data| {
let guarded_data = guarded_data.borrow();
data.extend_from_slice(&*guarded_data);
data.extend_from_slice(&guarded_data);
Ok(())
})?;
data.try_into().map_err(|_| SnapshotError::SnapshotKey(vid, rid))?
Expand Down Expand Up @@ -340,7 +340,7 @@ impl Snapshot {

let decrypted = &mut Vec::new();
self.db.get_guard::<SnapshotError, _>(&vault_key, vid, rid, |guard| {
let sk = x25519::SecretKey::try_from_slice(&*guard.borrow())?;
let sk = x25519::SecretKey::try_from_slice(&guard.borrow())?;
let shared_key = sk.diffie_hellman(&remote_pk);
let pt = engine::snapshot::read(&mut bytes.as_slice(), shared_key.as_bytes(), &[])?;
*decrypted = pt;
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ClientVault {

self.client.get_guard(&location, |guarded_data| {
let guarded_data = guarded_data.borrow();
data.extend_from_slice(&*guarded_data);
data.extend_from_slice(&guarded_data);
Ok(())
})?;

Expand Down
4 changes: 2 additions & 2 deletions engine/benches/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl BoxProvider for Provider {

let key = &key.key;

XChaCha20Poly1305::try_encrypt(&*key.borrow(), &nonce, ad, data, &mut cipher, &mut tag)?;
XChaCha20Poly1305::try_encrypt(&key.borrow(), &nonce, ad, data, &mut cipher, &mut tag)?;

let r#box = [tag.to_vec(), nonce.to_vec(), cipher].concat();

Expand All @@ -51,7 +51,7 @@ impl BoxProvider for Provider {

let key = &key.key;

XChaCha20Poly1305::try_decrypt(&*key.borrow(), nonce, ad, &mut plain, cipher, tag)?;
XChaCha20Poly1305::try_decrypt(&key.borrow(), nonce, ad, &mut plain, cipher, tag)?;

Ok(plain)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/src/memories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pub mod buffer;
pub mod file_memory;
#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub mod frag;
pub mod noncontiguous_memory;
pub mod ram_memory;
20 changes: 8 additions & 12 deletions engine/runtime/src/memories/noncontiguous_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
// TODO:
// - replace thread based shard refresh with guard type return and functional refresh

#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::memories::frag::{Frag, FragStrategy};
use crate::{
locked_memory::LockedMemory,
memories::{
buffer::Buffer,
file_memory::FileMemory,
ram_memory::RamMemory,
},
memories::{buffer::Buffer, file_memory::FileMemory, ram_memory::RamMemory},
utils::*,
MemoryError::*,
*,
};
#[cfg(not(any(target_os="android", target_os="ios")))]
use crate::memories::frag::{Frag, FragStrategy};

use core::{
fmt::{self, Debug, Formatter},
Expand Down Expand Up @@ -49,7 +45,7 @@ pub enum NCConfig {
FullFile,
FullRam,
RamAndFile,
#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
FragAllocation(FragStrategy),
}
use NCConfig::*;
Expand All @@ -60,7 +56,7 @@ use NCConfig::*;
enum MemoryShard {
File(FileMemory),
Ram(RamMemory),
#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Frag(Frag<[u8; NC_DATA_SIZE]>),
}
use MemoryShard::*;
Expand Down Expand Up @@ -207,7 +203,7 @@ impl MemoryShard {
Ok((File(fmem1), File(fmem2)))
}

#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
FragAllocation(strat) => {
let (frag1, frag2) = Frag::alloc_initialized(
*strat,
Expand All @@ -231,7 +227,7 @@ impl MemoryShard {
let v = buf.borrow().to_vec();
Ok(v)
}
#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Frag(frag) => {
if frag.is_live() {
Ok(frag.get()?.to_vec())
Expand All @@ -255,7 +251,7 @@ impl Zeroize for MemoryShard {
match self {
File(fm) => fm.zeroize(),
Ram(buf) => buf.zeroize(),
#[cfg(not(any(target_os="android", target_os="ios")))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Frag(frag) => frag.zeroize(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/snapshot/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ mod test {

for tv in &tvs {
let mut key = [0; KEY_SIZE];
hex::decode_to_slice(&tv.key, &mut key).unwrap();
hex::decode_to_slice(tv.key, &mut key).unwrap();
let ad = hex::decode(tv.ad).unwrap();
let data = hex::decode(tv.data).unwrap();
let snapshot = hex::decode(tv.snapshot).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion engine/src/vault/crypto_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<T: BoxProvider> NCKey<T> {
key: self.key.unlock().unwrap_or_else(|e| panic!("{}", e)),
_box_provider: PhantomData,
};
T::box_seal(&key, ad.as_ref(), &*data.key.borrow())
T::box_seal(&key, ad.as_ref(), &data.key.borrow())
}

pub fn decrypt_key<AD: AsRef<[u8]>>(&self, data: Vec<u8>, ad: AD) -> Result<Key<T>, DecryptError<T::Error>> {
Expand Down
4 changes: 2 additions & 2 deletions engine/tests/utils/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl BoxProvider for Provider {

let key = &key.key;

XChaCha20Poly1305::try_encrypt(&*key.borrow(), &nonce, ad, data, &mut cipher, &mut tag)?;
XChaCha20Poly1305::try_encrypt(&key.borrow(), &nonce, ad, data, &mut cipher, &mut tag)?;

let r#box = [tag.to_vec(), nonce.to_vec(), cipher].concat();

Expand All @@ -53,7 +53,7 @@ impl BoxProvider for Provider {

let key = &key.key;

XChaCha20Poly1305::try_decrypt(&*key.borrow(), nonce, ad, &mut plain, cipher, tag)?;
XChaCha20Poly1305::try_decrypt(&key.borrow(), nonce, ad, &mut plain, cipher, tag)?;

Ok(plain)
}
Expand Down

0 comments on commit 0a2331a

Please sign in to comment.