Skip to main content

spideroak_crypto_derive/
lib.rs

1//! Proc macros for [`spideroak-crypto`].
2//!
3//! [`spideroak-crypto`]: https://crates.io/crates/spideroak-crypto
4
5#![allow(unstable_name_collisions)]
6#![cfg_attr(docsrs, feature(doc_cfg))]
7#![warn(missing_docs)]
8
9mod alg_id;
10mod oid;
11
12use proc_macro::TokenStream;
13use syn::Error;
14
15/// See the `crypto` crate for documentation.
16#[proc_macro_derive(AlgId, attributes(alg_id))]
17pub fn alg_id(item: TokenStream) -> TokenStream {
18    alg_id::parse(item.into())
19        .unwrap_or_else(Error::into_compile_error)
20        .into()
21}
22
23/// Takes an OID string literal input (e.g., `"1.2.3"`), DER
24/// encodes it, and outputs the DER as a constant slice literal.
25#[proc_macro]
26pub fn oid(item: TokenStream) -> TokenStream {
27    oid::parse(item.into())
28        .unwrap_or_else(Error::into_compile_error)
29        .into()
30}