chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"bfb8aecdc47faea066fd27b878d0640c2e7859033c513ed32f342f25faef0b87","Cargo.toml":"a631619d2ce5c7060ce03cbbfc08a45430350e55b700b8bb905ff4ecb2819a8e","Cargo.toml.orig":"f4d839a0543fac286eb3be3b6c56cb75bb5910f3cb8a98f44a448ff36a8e50ec","src/lib.rs":"c052170f4c8f719ef07a722a1961c0e52423e28951ddbdf3700d7329bb79a277","tests/test_oid.rs":"0a4ed684b2c503315955b28d0587cf27ee7ed07e860f598960a99ee0415684d8"},"package":"7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"}

View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "a20e5f7319c896737ad0f2557037817b91ad854f"
},
"path_in_vcs": "impl"
}

32
vendor/asn1-rs-impl/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,32 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "asn1-rs-impl"
version = "0.2.0"
authors = ["Pierre Chifflier <chifflier@wzdftpd.net>"]
description = "Implementation details for the `asn1-rs` crate"
homepage = "https://github.com/rusticata/asn1-rs"
license = "MIT/Apache-2.0"
repository = "https://github.com/rusticata/asn1-rs.git"
[lib]
proc-macro = true
[dependencies.proc-macro2]
version = "1"
[dependencies.quote]
version = "1"
[dependencies.syn]
version = "2.0"

126
vendor/asn1-rs-impl/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,126 @@
extern crate proc_macro;
use proc_macro::{Span, TokenStream};
use syn::{parse_macro_input, Error, LitInt};
#[proc_macro]
pub fn encode_oid(input: TokenStream) -> TokenStream {
let token_stream = input.to_string();
let (s, relative) = if token_stream.starts_with("rel ") {
(&token_stream[4..], true)
} else {
(token_stream.as_ref(), false)
};
let items: Result<Vec<_>, _> = s.split('.').map(|x| x.trim().parse::<u128>()).collect();
let mut items: &[_] = match items.as_ref() {
Ok(v) => v.as_ref(),
Err(_) => return create_error("Could not parse OID"),
};
let mut v = Vec::new();
if !relative {
if items.len() < 2 {
if items.len() == 1 && items[0] == 0 {
return "[0]".parse().unwrap();
}
return create_error("Need at least two components for non-relative oid");
}
if items[0] > 2 || items[1] > 39 {
return create_error("First components are too big");
}
let first_byte = (items[0] * 40 + items[1]) as u8;
v.push(first_byte);
items = &items[2..];
}
for &int in items {
let enc = encode_base128(int);
v.extend_from_slice(&enc);
}
// "fn answer() -> u32 { 42 }".parse().unwrap()
let mut s = String::with_capacity(2 + 6 * v.len());
s.push('[');
for byte in v.iter() {
s.insert_str(s.len(), &format!("0x{:02x}, ", byte));
}
s.push(']');
s.parse().unwrap()
}
#[inline]
fn create_error(msg: &str) -> TokenStream {
let s = format!("Invalid OID({})", msg);
Error::new(Span::call_site().into(), &s)
.to_compile_error()
.into()
}
// encode int as base128
fn encode_base128(int: u128) -> Vec<u8> {
let mut val = int;
let mut base128 = Vec::new();
let lo = val & 0x7f;
base128.push(lo as u8);
val >>= 7;
loop {
if val == 0 {
base128.reverse();
return base128;
}
let lo = val & 0x7f;
base128.push(lo as u8 | 0x80);
val >>= 7;
}
}
#[proc_macro]
pub fn encode_int(input: TokenStream) -> TokenStream {
let lit = parse_macro_input!(input as LitInt);
match impl_encode_int(lit) {
Ok(ts) => ts,
Err(e) => e.to_compile_error().into(),
}
// let token_stream = input.to_string();
// let items: Result<Vec<_>, _> = token_stream
// .split('.')
// .map(|x| x.trim().parse::<u64>())
// .collect();
// let err = Error::new(Span::call_site().into(), "invalid OID");
// if let Ok(items) = items {
// let mut v = Vec::new();
// if items.len() < 2 || items[0] > 2 || items[1] > 39 {
// return err.to_compile_error().into();
// }
// let first_byte = (items[0] * 40 + items[1]) as u8;
// v.push(first_byte);
// for &int in &items[2..] {
// let enc = encode_base128(int);
// v.extend_from_slice(&enc);
// }
// // "fn answer() -> u32 { 42 }".parse().unwrap()
// let mut s = String::with_capacity(2 + 6 * v.len());
// s.push('[');
// for byte in v.iter() {
// s.insert_str(s.len(), &format!("0x{:02x}, ", byte));
// }
// s.push(']');
// s.parse().unwrap()
// } else {
// eprintln!("could not parse OID '{}'", token_stream);
// err.to_compile_error().into()
// }
}
fn impl_encode_int(lit: LitInt) -> Result<TokenStream, Error> {
let value = lit.base10_parse::<u64>()?;
let bytes = value.to_be_bytes();
let v: Vec<_> = bytes.iter().skip_while(|&c| *c == 0).collect();
let mut s = String::with_capacity(2 + 6 * v.len());
s.push('[');
for byte in v.iter() {
s.insert_str(s.len(), &format!("0x{:02x}, ", byte));
}
s.push(']');
Ok(s.parse().unwrap())
}

Binary file not shown.

View File

@@ -0,0 +1 @@
{"name":"asn1-rs-impl","vers":"0.2.0","deps":[{"name":"proc-macro2","req":"^1","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"quote","req":"^1","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"syn","req":"^2.0","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false}],"features":{},"features2":null,"cksum":"9f8fc66eba525e4c8835e00a6bbf175f451e888401e7810978a3f47220a4ecfc","yanked":null,"links":null,"rust_version":null,"v":2}

15
vendor/asn1-rs-impl/tests/test_oid.rs vendored Normal file
View File

@@ -0,0 +1,15 @@
use asn1_rs_impl::{encode_int, encode_oid};
#[test]
fn test_encode_oid() {
// example from http://luca.ntop.org/Teaching/Appunti/asn1.html
let oid = encode_oid! {1.2.840.113549};
assert_eq!(oid, [0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d]);
}
#[test]
fn test_encode_int() {
//
let int = encode_int!(1234);
assert_eq!(int, [0x04, 0xd2]);
}