Keystore 2.0: Clean up lints
Bug: 184833962
Test: m
Change-Id: Iff862198960003cd780844b0cd6620da941d48bc
diff --git a/keystore2/src/key_parameter.rs b/keystore2/src/key_parameter.rs
index 74a9b23..549f574 100644
--- a/keystore2/src/key_parameter.rs
+++ b/keystore2/src/key_parameter.rs
@@ -90,8 +90,6 @@
//! * The termination condition which has an empty in list.
//! * The public interface, which does not have @marker and calls itself with an empty out list.
-#![allow(clippy::from_over_into, clippy::needless_question_mark)]
-
use std::convert::TryInto;
use crate::db_utils::SqlField;
@@ -601,9 +599,9 @@
], [$($in)*]
}};
(@into $enum_name:ident, [$($out:tt)*], []) => {
- impl Into<KmKeyParameter> for $enum_name {
- fn into(self) -> KmKeyParameter {
- match self {
+ impl From<$enum_name> for KmKeyParameter {
+ fn from(x: $enum_name) -> Self {
+ match x {
$($out)*
}
}
@@ -1389,11 +1387,11 @@
db.prepare("SELECT tag, data, security_level FROM persistent.keyparameter")?;
let mut rows = stmt.query(NO_PARAMS)?;
let row = rows.next()?.unwrap();
- Ok(KeyParameter::new_from_sql(
+ KeyParameter::new_from_sql(
Tag(row.get(0)?),
&SqlField::new(1, row),
SecurityLevel(row.get(2)?),
- )?)
+ )
}
}
diff --git a/keystore2/src/legacy_blob.rs b/keystore2/src/legacy_blob.rs
index 29d46ad..9eebb36 100644
--- a/keystore2/src/legacy_blob.rs
+++ b/keystore2/src/legacy_blob.rs
@@ -14,8 +14,6 @@
//! This module implements methods to load legacy keystore key blob files.
-#![allow(clippy::redundant_slicing)]
-
use crate::{
error::{Error as KsError, ResponseCode},
key_parameter::{KeyParameter, KeyParameterValue},
@@ -484,7 +482,7 @@
let element_size =
read_ne_u32(stream).context("In read_key_parameters: While reading element size.")?;
- let elements_buffer = stream
+ let mut element_stream = stream
.get(0..element_size as usize)
.ok_or(KsError::Rc(ResponseCode::VALUE_CORRUPTED))
.context("In read_key_parameters: While reading elements buffer.")?;
@@ -492,8 +490,6 @@
// update the stream position.
*stream = &stream[element_size as usize..];
- let mut element_stream = &elements_buffer[..];
-
let mut params: Vec<KeyParameterValue> = Vec::new();
for _ in 0..element_count {
let tag = Tag(read_ne_i32(&mut element_stream).context("In read_key_parameters.")?);
diff --git a/keystore2/src/permission.rs b/keystore2/src/permission.rs
index 726c2ec..e7999bc 100644
--- a/keystore2/src/permission.rs
+++ b/keystore2/src/permission.rs
@@ -18,8 +18,6 @@
//! It also provides KeystorePerm and KeyPerm as convenience wrappers for the SELinux permission
//! defined by keystore2 and keystore2_key respectively.
-#![allow(clippy::from_over_into)]
-
use android_system_keystore2::aidl::android::system::keystore2::{
Domain::Domain, KeyDescriptor::KeyDescriptor, KeyPermission::KeyPermission,
};
@@ -151,9 +149,9 @@
}
}
- impl Into<$aidl_name> for $name {
- fn into(self) -> $aidl_name {
- self.0
+ impl From<$name> for $aidl_name {
+ fn from(p: $name) -> $aidl_name {
+ p.0
}
}
@@ -259,9 +257,9 @@
}
}
- impl Into<i32> for $name {
- fn into(self) -> i32 {
- self as i32
+ impl From<$name> for i32 {
+ fn from(p: $name) -> i32 {
+ p as i32
}
}
diff --git a/keystore2/src/remote_provisioning.rs b/keystore2/src/remote_provisioning.rs
index fc1a6ad..1f3f8e8 100644
--- a/keystore2/src/remote_provisioning.rs
+++ b/keystore2/src/remote_provisioning.rs
@@ -19,8 +19,6 @@
//! certificate chains signed by some root authority and stored in a keystore SQLite
//! DB.
-#![allow(clippy::from_over_into, clippy::needless_question_mark, clippy::vec_init_then_push)]
-
use std::collections::HashMap;
use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
@@ -252,7 +250,7 @@
// attestation keys unless the pool status is checked first, so this call should be
// enough to routinely clean out expired keys.
db.delete_expired_attestation_keys()?;
- Ok(db.get_attestation_pool_status(expired_by, &uuid)?)
+ db.get_attestation_pool_status(expired_by, &uuid)
})
}
@@ -294,14 +292,15 @@
protected_data,
))
.context("In generate_csr: Failed to generate csr")?;
- let mut cose_mac_0 = Vec::<u8>::new();
// TODO(b/180392379): Replace this manual CBOR generation with the cbor-serde crate as well.
// This generates an array consisting of the mac and the public key Maps.
// Just generate the actual MacedPublicKeys structure when the crate is
// available.
- cose_mac_0.push((0b100_00000 | (keys_to_sign.len() + 1)) as u8);
- cose_mac_0.push(0b010_11000); //push mac
- cose_mac_0.push(mac.len() as u8);
+ let mut cose_mac_0: Vec<u8> = vec![
+ (0b100_00000 | (keys_to_sign.len() + 1)) as u8,
+ 0b010_11000, // mac
+ (mac.len() as u8),
+ ];
cose_mac_0.append(&mut mac);
for maced_public_key in keys_to_sign {
if maced_public_key.macedKey.len() > 83 + 8 {
@@ -327,13 +326,13 @@
DB.with::<_, Result<()>>(|db| {
let mut db = db.borrow_mut();
let (_, _, uuid) = get_keymint_device(&sec_level)?;
- Ok(db.store_signed_attestation_certificate_chain(
+ db.store_signed_attestation_certificate_chain(
public_key,
batch_cert,
certs, /* DER encoded certificate chain */
expiration_date,
&uuid,
- )?)
+ )
})
}
@@ -362,7 +361,7 @@
raw_key[32..64].clone_from_slice(&data[53..53 + 32]);
DB.with::<_, Result<()>>(|db| {
let mut db = db.borrow_mut();
- Ok(db.create_attestation_key_entry(&maced_key.macedKey, &raw_key, &priv_key, &uuid)?)
+ db.create_attestation_key_entry(&maced_key.macedKey, &raw_key, &priv_key, &uuid)
})
}
@@ -377,7 +376,7 @@
pub fn delete_all_keys(&self) -> Result<i64> {
DB.with::<_, Result<i64>>(|db| {
let mut db = db.borrow_mut();
- Ok(db.delete_all_attestation_keys()?)
+ db.delete_all_attestation_keys()
})
}
}
diff --git a/keystore2/src/utils.rs b/keystore2/src/utils.rs
index 9852aad..10865ae 100644
--- a/keystore2/src/utils.rs
+++ b/keystore2/src/utils.rs
@@ -36,7 +36,6 @@
APC_COMPAT_ERROR_IGNORED, APC_COMPAT_ERROR_OK, APC_COMPAT_ERROR_OPERATION_PENDING,
APC_COMPAT_ERROR_SYSTEM_ERROR,
};
-use std::convert::TryFrom;
use std::sync::Mutex;
/// This function uses its namesake in the permission module and in
@@ -197,8 +196,7 @@
// defined to be an error that can never happen (i.e. the result is always ok).
// This suppresses the compiler's complaint about converting tv_sec to i64 in method
// get_current_time_in_seconds.
- #[allow(clippy::useless_conversion)]
- i64::try_from(current_time.tv_sec).unwrap()
+ current_time.tv_sec as i64
}
/// Converts a response code as returned by the Android Protected Confirmation HIDL compatibility