Skip to content

Commit

Permalink
Prepare for the possibility of this being usable with an MSRV bump
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Apr 23, 2022
1 parent 79f5a24 commit 389e8e6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
matrix:
RUST:
# MSRV
- VERSION: "1.41.0"
- VERSION: "1.47.0"
FLAGS: "--no-default-features --features std,derive"
- VERSION: stable
FLAGS: ""
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ derive = ["asn1_derive"]
[dependencies]
chrono = { version = "0.4", default-features = false, features = ["alloc"] }
asn1_derive = { path = "asn1_derive/", version = "0.8.7", optional = true }
proc-macro-hack = "0.5"

[dev-dependencies]
libc = "0.2"
1 change: 0 additions & 1 deletion asn1_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ proc-macro = true
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["parsing", "extra-traits"] }
proc-macro-hack = "0.5"
7 changes: 5 additions & 2 deletions asn1_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ fn generate_enum_write_block(name: &syn::Ident, data: &syn::DataEnum) -> proc_ma
}
}

// TODO: Duplicate of this function in src/object_identifier.rs, can we
// de-dupe?
fn _write_base128_int(data: &mut Vec<u8>, n: u32) {
if n == 0 {
data.push(0);
Expand All @@ -464,7 +466,7 @@ fn _write_base128_int(data: &mut Vec<u8>, n: u32) {
}
}

#[proc_macro_hack::proc_macro_hack]
#[proc_macro]
pub fn oid(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let p_arcs = Punctuated::<syn::LitInt, syn::Token![,]>::parse_terminated
.parse(item)
Expand All @@ -480,7 +482,8 @@ pub fn oid(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
}

let der_len = der_encoded.len();
der_encoded.resize(32, 0);
// TODO: is there a way to use the `MAX_OID_LENGTH` constant here?
der_encoded.resize(63, 0);
let der_lit = syn::LitByteStr::new(&der_encoded, proc_macro2::Span::call_site());
let expanded = quote::quote! {
asn1::ObjectIdentifier::from_der_unchecked(*#der_lit, #der_len as u8)
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ pub use crate::types::{Explicit, Implicit};
pub use crate::writer::{write, write_single, Writer};

#[cfg(feature = "derive")]
#[proc_macro_hack::proc_macro_hack(only_hack_old_rustc)]
pub use asn1_derive::oid;
#[cfg(feature = "derive")]
pub use asn1_derive::{Asn1Read, Asn1Write};
pub use asn1_derive::{oid, Asn1Read, Asn1Write};

/// Decodes an `OPTIONAL` ASN.1 value which has a `DEFAULT`. Generaly called
/// immediately after [`Parser::read_element`].
Expand Down
6 changes: 3 additions & 3 deletions src/object_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parser::{ParseError, ParseErrorKind, ParseResult};
use alloc::fmt;

const MAX_OID_LENGTH: usize = 32;
const MAX_OID_LENGTH: usize = 63;

/// Represents an ASN.1 `OBJECT IDENTIFIER`. ObjectIdentifiers are opaque, the only thing may be
/// done with them is test if they are equal to another `ObjectIdentifier`. The generally
Expand Down Expand Up @@ -165,7 +165,7 @@ mod tests {
".2.5",
"2..5",
"2.5.",
"1.3.6.1.4.1.1248.1.1.2.1.3.21.69.112.115.111.110.32.83.116.121.108.117.115.32.80.114.111.32.52.57.48.48.123.124412.31.213321.123",
"1.3.6.1.4.1.1248.1.1.2.1.3.21.69.112.115.111.110.32.83.116.121.108.117.115.32.80.114.111.32.52.57.48.48.123.124412.31.213321.123.110.32.83.116.121.108.117.115.32.80.114.111.32.52.57.48.48.123.124412.31.213321.123",
] {
assert_eq!(ObjectIdentifier::from_string(val), None);
}
Expand All @@ -184,7 +184,7 @@ mod tests {

#[test]
fn test_from_der() {
assert_eq!(ObjectIdentifier::from_der(b"\x06\x2b\x2b\x06\x01\x04\x01\x89\x60\x01\x01\x02\x01\x03\x15\x45\x70\x73\x6f\x6e\x20\x53\x74\x79\x6c\x75\x73\x20\x50\x72\x6f\x20\x34\x39\x30\x30\x7b\x87\xcb\x7c\x1f\x8d\x82\x49\x7b"), Err(ParseError::new(ParseErrorKind::OidTooLong)));
assert_eq!(ObjectIdentifier::from_der(b"\x06\x40\x2b\x06\x01\x04\x01\x89\x60\x01\x01\x02\x01\x03\x15\x45\x70\x73\x6f\x6e\x20\x53\x74\x79\x6c\x75\x73\x20\x50\x72\x6f\x20\x34\x39\x30\x30\x7b\x87\xcb\x7c\x1f\x8d\x82\x49\x7b\x2b\x06\x01\x04\x01\x89\x60\x01\x01\x02\x01\x03\x15\x45\x70\x73\x6f\x6e\x20"), Err(ParseError::new(ParseErrorKind::OidTooLong)));
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl fmt::Display for ParseError {
ParseErrorKind::ExtraData => write!(f, "extra data"),
ParseErrorKind::InvalidSetOrdering => write!(f, "SET value was ordered incorrectly"),
ParseErrorKind::EncodedDefault => write!(f, "DEFAULT value was explicitly encoded"),
ParseErrorKind::OidTooLong => write!(f, "OBJECT IDENTIFIER was too large to be stored in rust-asn1's buffer"),
}
}
}
Expand Down

0 comments on commit 389e8e6

Please sign in to comment.