From 8f451601e2311cb0544c8e190d624bf0d7909964 Mon Sep 17 00:00:00 2001 From: Erin Power Date: Mon, 28 Feb 2022 10:18:08 +0100 Subject: [PATCH] fmt --- macros/src/asn_type.rs | 8 +++++--- macros/src/config.rs | 9 +++++---- macros/src/decode.rs | 7 ++++++- macros/src/encode.rs | 10 +++++++--- macros/src/tag.rs | 10 +++++++--- src/ber/de.rs | 10 ++++++++-- src/types/tag.rs | 6 +++--- standards/kerberos/tests/as_req.rs | 13 ++++++------- standards/pkix/tests/digicert.rs | 4 ++-- tests/explicit_delegate.rs | 9 +++++++-- 10 files changed, 56 insertions(+), 30 deletions(-) diff --git a/macros/src/asn_type.rs b/macros/src/asn_type.rs index d82ace0b..c6b97b93 100644 --- a/macros/src/asn_type.rs +++ b/macros/src/asn_type.rs @@ -35,10 +35,11 @@ pub fn derive_struct_impl( .filter_map(|(key, fields)| key.then(|| fields)) .map(|fields| { let tag_tree = fields.map(|(i, f)| f.tag_tree(i)); - let error_message = format!("{}'s fields is not a valid \ + let error_message = format!( + "{}'s fields is not a valid \ order of ASN.1 tags, ensure that your field's tags and \ OPTIONALs are correct.", - name + name ); quote!({ @@ -80,7 +81,8 @@ pub fn derive_enum_impl( .unwrap_or(quote!(#crate_root::Tag::EOC)) }); - let error_message = format!("{}'s variants is not unique, ensure that your variants's tags are correct.", + let error_message = format!( + "{}'s variants is not unique, ensure that your variants's tags are correct.", name ); diff --git a/macros/src/config.rs b/macros/src/config.rs index eca47fe0..fe3c40d3 100644 --- a/macros/src/config.rs +++ b/macros/src/config.rs @@ -325,11 +325,12 @@ impl<'a> VariantConfig<'a> { quote!(#crate_root::TagTree::Leaf(<() as #crate_root::AsnType>::TAG),) } syn::Fields::Named(_) => { - let error_message = format!("{}'s fields is not a valid \ + let error_message = format!( + "{}'s fields is not a valid \ order of ASN.1 tags, ensure that your field's tags and \ OPTIONALs are correct.", - self.variant.ident - ); + self.variant.ident + ); quote!({ const FIELD_LIST: &'static [#crate_root::TagTree] = &[#(#field_tags,)*]; @@ -451,7 +452,7 @@ impl<'a> FieldConfig<'a> { let or_else = match self.default { Some(Some(ref path)) => quote! { .unwrap_or_else(|_| #path ()) }, Some(None) => quote! { .unwrap_or_default() }, - None if self.is_option_type() => quote!{ .ok() }, + None if self.is_option_type() => quote! { .ok() }, None => { let ident = format!( "{}.{}", diff --git a/macros/src/decode.rs b/macros/src/decode.rs index e55a79b7..7525df57 100644 --- a/macros/src/decode.rs +++ b/macros/src/decode.rs @@ -42,7 +42,12 @@ pub fn derive_struct_impl( let decode_impl = if config.delegate { let ty = &container.fields.iter().next().unwrap().ty; - if config.tag.as_ref().map(|tag| tag.explicit).unwrap_or_default() { + if config + .tag + .as_ref() + .map(|tag| tag.explicit) + .unwrap_or_default() + { quote! { decoder.decode_explicit_prefix::<#ty>(tag).map(Self) } diff --git a/macros/src/encode.rs b/macros/src/encode.rs index 1ae0a72d..807e5973 100644 --- a/macros/src/encode.rs +++ b/macros/src/encode.rs @@ -43,9 +43,13 @@ pub fn derive_struct_impl( let encode_impl = if config.delegate { let ty = &container.fields.iter().next().unwrap().ty; - if config.tag.as_ref().map(|tag| tag.explicit).unwrap_or_default() { - let encode = - quote!(encoder.encode_explicit_prefix(tag, &self.0).map(drop)); + if config + .tag + .as_ref() + .map(|tag| tag.explicit) + .unwrap_or_default() + { + let encode = quote!(encoder.encode_explicit_prefix(tag, &self.0).map(drop)); if config.option_type.is_option_type(&ty) { let none_variant = &config.option_type.none_variant; quote! { diff --git a/macros/src/tag.rs b/macros/src/tag.rs index 34b1cfc8..351d5263 100644 --- a/macros/src/tag.rs +++ b/macros/src/tag.rs @@ -66,8 +66,13 @@ impl Tag { let second = iter.next(); match (first, second) { - (Some(syn::NestedMeta::Meta(syn::Meta::Path(path))), Some(syn::NestedMeta::Lit(lit))) => { - let class = Class::from_ident(path.get_ident().expect("Path must be a valid ident.")); + ( + Some(syn::NestedMeta::Meta(syn::Meta::Path(path))), + Some(syn::NestedMeta::Lit(lit)), + ) => { + let class = Class::from_ident( + path.get_ident().expect("Path must be a valid ident."), + ); let value = lit.clone(); explicit = true; tag = Some((class, value)); @@ -125,7 +130,6 @@ impl Tag { let class = &self.class; let value = &self.value; - quote!(#crate_root::Tag::new(#class, #value)) } } diff --git a/src/ber/de.rs b/src/ber/de.rs index ea9214e3..53e0f129 100644 --- a/src/ber/de.rs +++ b/src/ber/de.rs @@ -409,7 +409,10 @@ mod tests { #[test] fn integer() { - assert_eq!(32768, decode::(&[0x02, 0x03, 0x00, 0x80, 0x00,]).unwrap()); + assert_eq!( + 32768, + decode::(&[0x02, 0x03, 0x00, 0x80, 0x00,]).unwrap() + ); assert_eq!(32767, decode::(&[0x02, 0x02, 0x7f, 0xff]).unwrap()); assert_eq!(256, decode::(&[0x02, 0x02, 0x01, 0x00]).unwrap()); assert_eq!(255, decode::(&[0x02, 0x02, 0x00, 0xff]).unwrap()); @@ -422,7 +425,10 @@ mod tests { assert_eq!(-129i16, decode::(&[0x02, 0x02, 0xff, 0x7f]).unwrap()); assert_eq!(-256i16, decode::(&[0x02, 0x02, 0xff, 0x00]).unwrap()); assert_eq!(-32768i32, decode::(&[0x02, 0x02, 0x80, 0x00]).unwrap()); - assert_eq!(-32769i32, decode::(&[0x02, 0x03, 0xff, 0x7f, 0xff]).unwrap()); + assert_eq!( + -32769i32, + decode::(&[0x02, 0x03, 0xff, 0x7f, 0xff]).unwrap() + ); let mut data = [0u8; 261]; data[0] = 0x02; diff --git a/src/types/tag.rs b/src/types/tag.rs index 84522edd..dfbba093 100644 --- a/src/types/tag.rs +++ b/src/types/tag.rs @@ -291,9 +291,9 @@ mod tests { #[test] fn is_unique() { - const _ : () = assert!(_EXPECTED.is_unique()); - const _ : () = assert!(!_INVALID_FLAT.is_unique()); - const _ : () = assert!(!_INVALID_NESTED.is_unique()); + const _: () = assert!(_EXPECTED.is_unique()); + const _: () = assert!(!_INVALID_FLAT.is_unique()); + const _: () = assert!(!_INVALID_NESTED.is_unique()); } #[test] diff --git a/standards/kerberos/tests/as_req.rs b/standards/kerberos/tests/as_req.rs index 7f6d2364..48f9d33c 100644 --- a/standards/kerberos/tests/as_req.rs +++ b/standards/kerberos/tests/as_req.rs @@ -12,26 +12,25 @@ fn as_req() { msg_type: Integer::parse_bytes(b"10", 10).unwrap(), padata: None, req_body: KdcReqBody { - kdc_options: KdcOptions(KerberosFlags::from_vec(vec!(0;0))), + kdc_options: KdcOptions(KerberosFlags::from_vec(vec![0; 0])), cname: None, realm: KerberosString::new("COMPANY.INT".to_string()), sname: None, from: None, - till: KerberosTime(GeneralizedTime::parse_from_rfc2822("Fri, 04 Feb 2022 10:11:11 GMT").unwrap()), + till: KerberosTime( + GeneralizedTime::parse_from_rfc2822("Fri, 04 Feb 2022 10:11:11 GMT").unwrap(), + ), rtime: None, nonce: 123514514, etype: vec![18], addresses: None, enc_authorization_data: None, additional_tickets: None, - } + }, }); let data: &[u8] = &[ - 0x6A, 0x45, 0x30, 0x43, - 0xA1, 0x03, 0x02, 0x01, 0x05, - 0xA2, 0x03, 0x02, 0x01, 0x0A, - 0xA4, + 0x6A, 0x45, 0x30, 0x43, 0xA1, 0x03, 0x02, 0x01, 0x05, 0xA2, 0x03, 0x02, 0x01, 0x0A, 0xA4, ]; let enc = rasn::der::encode(&as_req).unwrap(); diff --git a/standards/pkix/tests/digicert.rs b/standards/pkix/tests/digicert.rs index 737bafe0..1257a9e6 100644 --- a/standards/pkix/tests/digicert.rs +++ b/standards/pkix/tests/digicert.rs @@ -171,7 +171,7 @@ fn lets_encrypt_x3() { 0xf8, 0xe3, 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31, 0xc5, 0xaf, 0xc4, 0x8d, 0x0d, 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84, 0x29, 0xb6, 0xd4, 0x0b, 0xc0, 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, - ]) + ]), }, issuer_unique_id: None, subject_unique_id: None, @@ -318,7 +318,7 @@ fn lets_encrypt_x3() { 0x6e, 0x7b, 0x4c, 0x7d, 0x87, 0xdd, 0xe0, 0xc9, 0x02, 0x44, 0xa7, 0x87, 0xaf, 0xc3, 0x34, 0x5b, 0xb4, 0x42, ][..], - ) + ), }; let original_data: &[u8] = include_bytes!("data/letsencrypt-x3.crt"); diff --git a/tests/explicit_delegate.rs b/tests/explicit_delegate.rs index 6f981442..fef92c18 100644 --- a/tests/explicit_delegate.rs +++ b/tests/explicit_delegate.rs @@ -5,9 +5,14 @@ use rasn::prelude::*; pub struct ExplicitDelegate(pub Sequence); #[derive(AsnType, Decode, Debug, Encode, PartialEq)] -pub struct Sequence { b: bool } +pub struct Sequence { + b: bool, +} -const _: () = assert!(Tag::const_eq(ExplicitDelegate::TAG, &Tag::new(Class::Application, 1))); +const _: () = assert!(Tag::const_eq( + ExplicitDelegate::TAG, + &Tag::new(Class::Application, 1) +)); #[test] fn der() {