Skip to content

Commit

Permalink
Revert "Just write these like OIDs"
Browse files Browse the repository at this point in the history
This reverts commit a5ccda3.
  • Loading branch information
alex committed Jan 3, 2022
1 parent 53364b6 commit c0d8a7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
13 changes: 8 additions & 5 deletions asn1_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate proc_macro;

use syn::parse::Parser;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::token::Comma;
Expand Down Expand Up @@ -465,15 +466,17 @@ fn _write_base128_int(data: &mut Vec<u8>, n: u32) {

#[proc_macro_hack::proc_macro_hack]
pub fn oid(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let contents = item.to_string();
let mut arcs = contents.split('.');
let p_arcs = Punctuated::<syn::LitInt, syn::Token![,]>::parse_terminated
.parse(item)
.unwrap();
let mut arcs = p_arcs.iter();

let mut der_encoded = vec![];
let first = arcs.next().unwrap().parse::<u32>().unwrap();
let second = arcs.next().unwrap().parse::<u32>().unwrap();
let first = arcs.next().unwrap().base10_parse::<u32>().unwrap();
let second = arcs.next().unwrap().base10_parse::<u32>().unwrap();
_write_base128_int(&mut der_encoded, 40 * first + second);
for arc in arcs {
_write_base128_int(&mut der_encoded, arc.parse().unwrap());
_write_base128_int(&mut der_encoded, arc.base10_parse().unwrap());
}

let der_len = der_encoded.len();
Expand Down
3 changes: 1 addition & 2 deletions src/object_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MAX_OID_LENGTH: usize = 32;
/// `asn1::oid!()` and then compare ObjectIdentifiers you get from parsing to
/// those.
///
/// `asn1::oid!()` takes a series of arcs, for example: `asn1::oid!(1.2.3)`.
/// `asn1::oid!()` takes a series of arcs, for example: `asn1::oid!(1, 2, 3)`.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct ObjectIdentifier {
// Store the OID as DER encoded.
Expand Down Expand Up @@ -67,7 +67,6 @@ fn _write_base128_int(data: &mut [u8], data_len: &mut usize, n: u32) -> Option<(

impl ObjectIdentifier {
/// Parses an OID from a dotted string, e.g. `"1.2.840.113549"`.
/// ``asn1::oid!(1.2.3)`` is preferred for compile-time constants.
pub fn from_string(oid: &str) -> Option<ObjectIdentifier> {
let mut parts = oid.split('.');

Expand Down
6 changes: 3 additions & 3 deletions tests/oid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#[test]
fn test_oid_value() {
assert_eq!(
asn1::oid!(1.2.3.4),
asn1::oid!(1, 2, 3, 4),
asn1::ObjectIdentifier::from_string("1.2.3.4").unwrap()
);
}

#[test]
fn test_match_statement() {
const OID1: asn1::ObjectIdentifier = asn1::oid!(1.2.3.4);
const OID2: asn1::ObjectIdentifier = asn1::oid!(1.2.3.5);
const OID1: asn1::ObjectIdentifier = asn1::oid!(1, 2, 3, 4);
const OID2: asn1::ObjectIdentifier = asn1::oid!(1, 2, 3, 5);

let oid = asn1::ObjectIdentifier::from_string("1.2.3.4").unwrap();
let result = match oid {
Expand Down

0 comments on commit c0d8a7b

Please sign in to comment.