Commit 67feadc9 authored by Tony Finn's avatar Tony Finn

Clippy fixes

parent 02529af1
......@@ -178,11 +178,11 @@ where
let len = if major_version >= 4 {
let mut len_buffer = [0u8; 4];
self.reader.read_exact(&mut len_buffer)?;
u32::from_le_bytes(len_buffer.clone())
u32::from_le_bytes(len_buffer)
} else {
let mut len_buffer = [0u8; 2];
self.reader.read_exact(&mut len_buffer)?;
u16::from_le_bytes(len_buffer.clone()) as u32
u16::from_le_bytes(len_buffer) as u32
};
let mut header_buffer = utils::buffer(len as usize);
self.reader.read_exact(&mut header_buffer)?;
......@@ -500,7 +500,7 @@ impl KdbxInnerHeader {
Ok(KdbxInnerHeader {
inner_stream_cipher: cipher_id.into(),
inner_stream_key: key.into(),
inner_stream_key: key,
other_headers: Vec::new(),
})
}
......
......@@ -196,7 +196,7 @@ impl TryFrom<VariantDict> for KdfParams {
)
})?;
let kdf_algorithm = KdfAlgorithm::from(uuid.clone());
let kdf_algorithm = KdfAlgorithm::from(uuid);
match kdf_algorithm {
KdfAlgorithm::Argon2 => {
......@@ -221,7 +221,7 @@ impl TryFrom<VariantDict> for KdfParams {
Ok(KdfParams::Aes { rounds, salt })
}
_ => Ok(KdfParams::Unknown {
uuid: uuid.clone(),
uuid: uuid,
params: vdict,
}),
}
......@@ -244,9 +244,7 @@ impl Into<VariantDict> for KdfParams {
variant_dict::Value::Array(
uuid::Uuid::from(KdfAlgorithm::Argon2)
.as_bytes()
.iter()
.cloned()
.collect(),
.to_vec()
),
);
vdict.insert("M".into(), variant_dict::Value::Uint64(memory_bytes));
......@@ -261,9 +259,7 @@ impl Into<VariantDict> for KdfParams {
variant_dict::Value::Array(
uuid::Uuid::from(KdfAlgorithm::Aes256_Kdbx4)
.as_bytes()
.iter()
.cloned()
.collect(),
.to_vec(),
),
);
vdict.insert("R".into(), variant_dict::Value::Uint64(rounds));
......@@ -272,7 +268,7 @@ impl Into<VariantDict> for KdfParams {
KdfParams::Unknown { uuid, params } => {
vdict.insert(
"$UUID".into(),
variant_dict::Value::Array(uuid.as_bytes().iter().cloned().collect()),
variant_dict::Value::Array(uuid.as_bytes().to_vec()),
);
vdict.extend(params.into_iter())
}
......
......@@ -74,12 +74,12 @@ impl Value {
pub(crate) fn data(&self) -> Vec<u8> {
match self {
Value::Uint32(val) => val.to_le_bytes().iter().cloned().collect(),
Value::Uint64(val) => val.to_le_bytes().iter().cloned().collect(),
Value::Uint32(val) => val.to_le_bytes().to_vec(),
Value::Uint64(val) => val.to_le_bytes().to_vec(),
Value::Boolean(val) => vec![if *val { 1 } else { 0 }],
Value::Int32(val) => val.to_le_bytes().iter().cloned().collect(),
Value::Int64(val) => val.to_le_bytes().iter().cloned().collect(),
Value::String(val) => val.as_bytes().iter().cloned().collect(),
Value::Int32(val) => val.to_le_bytes().to_vec(),
Value::Int64(val) => val.to_le_bytes().to_vec(),
Value::String(val) => val.as_bytes().to_vec(),
Value::Array(val) => val.clone(),
Value::Unknown(_, val) => val.clone(),
}
......@@ -151,7 +151,7 @@ fn parse_variant_dict_entry<T: Read>(ty: u8, input: &mut T) -> Result<(String, V
let mut length_buffer = [0u8; 4];
input.read_exact(&mut length_buffer)?;
let key_length = i32::from_le_bytes(length_buffer.clone());
let key_length = i32::from_le_bytes(length_buffer);
let mut key_buffer: Vec<u8> = buffer(key_length as usize);
input.read_exact(&mut key_buffer)?;
let key = String::from_utf8(key_buffer)?;
......
......@@ -92,7 +92,7 @@ impl ComposedKey {
let chunked: Vec<GenericArray<u8, _>> = self
.0
.chunks_exact(16)
.map(|chunk| GenericArray::from_slice(chunk).clone())
.map(|chunk| *GenericArray::from_slice(chunk))
.collect();
let mut blocks = [chunked[0], chunked[1]];
for _ in 0..*rounds {
......@@ -161,10 +161,7 @@ impl HmacBlockKey {
calc_hmac.input(&self.0.to_le_bytes());
calc_hmac.input(&(data.len() as u32).to_le_bytes());
calc_hmac.input(data);
match calc_hmac.verify(hmac) {
Ok(_) => true,
Err(_) => false,
}
calc_hmac.verify(hmac).is_ok()
}
/// Calculate a HMAC for a block in the data section
......@@ -193,10 +190,7 @@ impl HmacBlockKey {
pub(crate) fn verify_header_block(&self, hmac: &[u8], data: &[u8]) -> bool {
let mut calc_hmac = HmacSha256::new_varkey(&self.1).unwrap();
calc_hmac.input(data);
match calc_hmac.verify(hmac) {
Ok(_) => true,
Err(_) => false,
}
calc_hmac.verify(hmac).is_ok()
}
}
......
......@@ -50,7 +50,9 @@
//!
//! ```
//! # let mut database = kdbx_rs::database::doc_sample_db();
//! let uuid = database.find_entry_mut(|f| f.title() == Some("Foo")).unwrap().uuid();
//! let uuid = database.find_entry_mut(|f| f.title() == Some("Foo"))
//! .unwrap()
//! .uuid();
//! # let mut source_group = database.root_mut().unwrap();
//! let entry = source_group.remove_entry(uuid).unwrap();
//!
......@@ -160,6 +162,11 @@ impl History {
self.entries.len()
}
/// Count of entries in this history
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Remove a historical version by index
pub fn remove(&mut self, idx: usize) -> Entry {
self.entries.remove(idx)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment