Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Feb 28, 2022
1 parent a99a312 commit 8f45160
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 30 deletions.
8 changes: 5 additions & 3 deletions macros/src/asn_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down Expand Up @@ -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
);

Expand Down
9 changes: 5 additions & 4 deletions macros/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)*];
Expand Down Expand Up @@ -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!(
"{}.{}",
Expand Down
7 changes: 6 additions & 1 deletion macros/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 7 additions & 3 deletions macros/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
10 changes: 7 additions & 3 deletions macros/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -125,7 +130,6 @@ impl Tag {
let class = &self.class;
let value = &self.value;


quote!(#crate_root::Tag::new(#class, #value))
}
}
10 changes: 8 additions & 2 deletions src/ber/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ mod tests {

#[test]
fn integer() {
assert_eq!(32768, decode::<i32>(&[0x02, 0x03, 0x00, 0x80, 0x00,]).unwrap());
assert_eq!(
32768,
decode::<i32>(&[0x02, 0x03, 0x00, 0x80, 0x00,]).unwrap()
);
assert_eq!(32767, decode::<i32>(&[0x02, 0x02, 0x7f, 0xff]).unwrap());
assert_eq!(256, decode::<i16>(&[0x02, 0x02, 0x01, 0x00]).unwrap());
assert_eq!(255, decode::<i16>(&[0x02, 0x02, 0x00, 0xff]).unwrap());
Expand All @@ -422,7 +425,10 @@ mod tests {
assert_eq!(-129i16, decode::<i16>(&[0x02, 0x02, 0xff, 0x7f]).unwrap());
assert_eq!(-256i16, decode::<i16>(&[0x02, 0x02, 0xff, 0x00]).unwrap());
assert_eq!(-32768i32, decode::<i32>(&[0x02, 0x02, 0x80, 0x00]).unwrap());
assert_eq!(-32769i32, decode::<i32>(&[0x02, 0x03, 0xff, 0x7f, 0xff]).unwrap());
assert_eq!(
-32769i32,
decode::<i32>(&[0x02, 0x03, 0xff, 0x7f, 0xff]).unwrap()
);

let mut data = [0u8; 261];
data[0] = 0x02;
Expand Down
6 changes: 3 additions & 3 deletions src/types/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 6 additions & 7 deletions standards/kerberos/tests/as_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions standards/pkix/tests/digicert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions tests/explicit_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8f45160

Please sign in to comment.