Skip to content

Commit

Permalink
Apply Clippy to tests and fix some lints (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Nov 15, 2023
1 parent 03ace39 commit 7ea12d3
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.71.0
toolchain: 1.73.0
components: clippy
- run: cargo clippy --all-features
- run: cargo clippy --all --all-features --tests

doc:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn test_build_pkcs7_scep_pkcsreq() {
values: message_type_value,
};
let mut sender_nonce_value: SetOfVec<AttributeValue> = Default::default();
let nonce = OctetString::new(*&[42; 32]).unwrap();
let nonce = OctetString::new([42; 32]).unwrap();
sender_nonce_value
.insert(Any::new(Tag::OctetString, nonce.as_bytes()).unwrap())
.unwrap();
Expand Down
5 changes: 1 addition & 4 deletions cms/tests/compressed_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ fn reencode_compressed_data_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_inci = ci2.to_der().unwrap();

Expand Down
5 changes: 1 addition & 4 deletions cms/tests/digested_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ fn reencode_digested_data_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_inci = ci2.to_der().unwrap();

Expand Down
5 changes: 1 addition & 4 deletions cms/tests/encrypted_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ fn reencode_encrypted_data_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_inci = ci2.to_der().unwrap();

Expand Down
25 changes: 5 additions & 20 deletions cms/tests/enveloped_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ fn reencode_enveloped_data_ktri_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -180,10 +177,7 @@ fn reencode_enveloped_data_kari_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -270,10 +264,7 @@ fn reencode_enveloped_data_pwri_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -336,10 +327,7 @@ fn reencode_enveloped_data_kek_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -498,10 +486,7 @@ fn reencode_enveloped_data_multi_test() {
// assemble a new ContentInfo and encode it
let ci2 = ContentInfo {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
content: AnyRef::try_from(reencoded_data.as_slice()).unwrap().into(),
};
let reencoded_data_in_ci = ci2.to_der().unwrap();

Expand Down
6 changes: 2 additions & 4 deletions cms/tests/signed_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ fn trust_list_test() {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_signed_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
.into(),
};
let reencoded_der_signed_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -62,8 +61,7 @@ fn reencode_signed_data_test() {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_signed_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
.into(),
};
let reencoded_der_signed_data_in_ci = ci2.to_der().unwrap();

Expand Down
9 changes: 3 additions & 6 deletions cms/tests/tests_from_pkcs7_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ fn cms_decode_signed_mdm_example() {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_signed_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
.into(),
};
let reencoded_der_signed_data_in_ci = ci2.to_der().unwrap();

Expand All @@ -99,8 +98,7 @@ fn cms_decode_signed_scep_example() {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_signed_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
.into(),
};
let reencoded_der_signed_data_in_ci = ci2.to_der().unwrap();

Expand Down Expand Up @@ -137,8 +135,7 @@ fn cms_decode_signed_der() {
content_type: ci.content_type,
content: AnyRef::try_from(reencoded_signed_data.as_slice())
.unwrap()
.try_into()
.unwrap(),
.into(),
};
let reencoded_der_signed_data_in_ci = ci2.to_der().unwrap();

Expand Down
8 changes: 4 additions & 4 deletions pkcs12/tests/cert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn decode_sample_pfx() {
let auth_safes = AuthenticatedSafe::from_der(auth_safes_os.as_bytes()).unwrap();

// Process first auth safe (from offset 34)
let auth_safe0 = auth_safes.get(0).unwrap();
let auth_safe0 = auth_safes.first().unwrap();
assert_eq!(ID_ENCRYPTED_DATA, auth_safe0.content_type);
let enc_data_os = &auth_safe0.content.to_der().unwrap();
let enc_data = EncryptedData::from_der(enc_data_os.as_slice()).unwrap();
Expand All @@ -183,11 +183,11 @@ fn decode_sample_pfx() {

let params = pkcs8::pkcs5::pbes2::Parameters::from_der(&enc_params).unwrap();

let scheme = pkcs5::EncryptionScheme::try_from(params.clone()).unwrap();
let scheme = pkcs5::EncryptionScheme::from(params.clone());
let ciphertext_os = enc_data.enc_content_info.encrypted_content.clone().unwrap();
let mut ciphertext = ciphertext_os.as_bytes().to_vec();
let plaintext = scheme.decrypt_in_place("", &mut ciphertext).unwrap();
let cert_bags = SafeContents::from_der(&plaintext).unwrap();
let cert_bags = SafeContents::from_der(plaintext).unwrap();
for cert_bag in cert_bags {
match cert_bag.bag_id {
pkcs12::PKCS_12_CERT_BAG_OID => {
Expand Down Expand Up @@ -589,7 +589,7 @@ fn decode_sample_pfx2() {
let auth_safes = AuthenticatedSafe::from_der(auth_safes_os.as_bytes()).unwrap();

// Process first auth safe (from offset 34)
let auth_safe0 = auth_safes.get(0).unwrap();
let auth_safe0 = auth_safes.first().unwrap();
assert_eq!(ID_DATA, auth_safe0.content_type);

let auth_safe0_auth_safes_os =
Expand Down
4 changes: 2 additions & 2 deletions pkcs5/src/pbes2/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ impl<'a> From<Pbkdf2Prf> for AlgorithmIdentifierRef<'a> {

impl Encode for Pbkdf2Prf {
fn encoded_len(&self) -> der::Result<Length> {
AlgorithmIdentifierRef::try_from(*self)?.encoded_len()
AlgorithmIdentifierRef::from(*self).encoded_len()
}

fn encode(&self, writer: &mut impl Writer) -> der::Result<()> {
AlgorithmIdentifierRef::try_from(*self)?.encode(writer)
AlgorithmIdentifierRef::from(*self).encode(writer)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tls_codec/derive/tests/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ mod conditional_deserialization {
let undeserializable_struct = UndeserializableExampleStruct { a: 1, b: 2 };
let serialized = undeserializable_struct.tls_serialize_detached().unwrap();
let deserializable_struct =
DeserializableExampleStruct::tls_deserialize_exact(&mut &*serialized).unwrap();
DeserializableExampleStruct::tls_deserialize_exact(&*serialized).unwrap();
assert_eq!(deserializable_struct.a, undeserializable_struct.a);
assert_eq!(deserializable_struct.b, undeserializable_struct.b);
}
Expand Down
8 changes: 4 additions & 4 deletions x509-cert/tests/pkix_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ fn decode_cert() {
0 => match dpn {
DistributionPointName::FullName(gns) => {
assert_eq!(1, gns.len());
let gn = gns.get(0).unwrap();
let gn = gns.first().unwrap();
match gn {
GeneralName::UniformResourceIdentifier(uri) => {
assert_eq!(
Expand All @@ -422,7 +422,7 @@ fn decode_cert() {
1 => match dpn {
DistributionPointName::FullName(gns) => {
assert_eq!(1, gns.len());
let gn = gns.get(0).unwrap();
let gn = gns.first().unwrap();
match gn {
GeneralName::UniformResourceIdentifier(uri) => {
assert_eq!("ldap://ldap-pte.identrust.com.test/cn%3DIGC%20Root%20CA1%2Co%3DIdenTrust%2Cc%3DUS%3FcertificateRevocationList%3Bbinary", uri.to_string());
Expand Down Expand Up @@ -869,7 +869,7 @@ fn decode_idp() {
let gns =
GeneralNames::from_der(&hex!("305EA45C305A310B3009060355040613025553311F301D060355040A131654657374204365727469666963617465732032303137311C301A060355040B13136F6E6C79536F6D65526561736F6E7320434133310C300A0603550403130343524C")).unwrap();
assert_eq!(1, gns.len());
if let GeneralName::DirectoryName(gn) = gns.get(0).unwrap() {
if let GeneralName::DirectoryName(gn) = gns.first().unwrap() {
assert_eq!(4, gn.0.len());
}

Expand All @@ -894,7 +894,7 @@ fn decode_idp() {
DistributionPoint::from_der(&hex!("3062A060A05EA45C305A310B3009060355040613025553311F301D060355040A131654657374204365727469666963617465732032303137311C301A060355040B13136F6E6C79536F6D65526561736F6E7320434133310C300A0603550403130343524C")).unwrap();
if let DistributionPointName::FullName(dpn) = dp.distribution_point.unwrap() {
assert_eq!(1, dpn.len());
if let GeneralName::DirectoryName(gn) = dpn.get(0).unwrap() {
if let GeneralName::DirectoryName(gn) = dpn.first().unwrap() {
assert_eq!(4, gn.0.len());
}
}
Expand Down

0 comments on commit 7ea12d3

Please sign in to comment.