Thanks to visit codestin.com
Credit goes to lib.rs

#compile #byte #const #oid #asn-1

macro def_oid

Define OID into ASN1 bytes format at compile time by using OID arcs literal string

1 stable release

Uses new Rust 2024

1.0.0 Aug 7, 2025

#2490 in Encoding

MIT license

9KB
127 lines

def_oid

This crate provides two procedural macros. Both macros is used to declare fixed size array of u8. The array will contains OID encoded according to ASN1 encoding scheme. See X.690 for more detail.

Two usable macros are:

  • [const_oid!] - This macro can be used to declare constant variable. Since Rust required that all constant must have explicit type declared and OID size required some calculation, this macro do all that. For example, OID of 2.5.4.3 is [u8; 3] while 1.1.3.4.5555 is [u8; 5]. See [const_oid!] for how to use it.
  • [oid!] - This macro can be used to declare any variable. It will return fixed size array of u8.

def_oid

Why yet another OID crate ? This library allow a compile time OID encoded bytes by using one of the two procedural macros oid and const_oid. Both macro gives a fixed size array of u8 so it's no runtime overhead.

Use case

oid is used to get a fixed size bytes of OID. It can be used as expression.

some_function(oid!("2.5.4.3")); // some_function will received [85, 4, 3] of type [u8; 3]. 

const_oid is used to declare fixed size bytes constant variable. This is useful for global const declaration.

const_oid!(COMMON_NAME, "2.5.4.3"); // Declare const variable "COMMON_NAME" with type [u8; 3]
println!("{:?}", COMMON_NAME); // it should print [85, 4, 3]

Dependencies

~160–570KB
~14K SLoC