Unverified Commit 7c3a407b authored by Steven Fackler's avatar Steven Fackler
Browse files

Start switching over to macro'd cross references

parent 36540ce9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
members = [
    "openssl",
    "openssl-errors",
    "openssl-macros",
    "openssl-sys",
    "systest",
]
+12 −0
Original line number Diff line number Diff line
[package]
name = "openssl-macros"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "1", features = ["full"] }
+33 −0
Original line number Diff line number Diff line
use proc_macro::TokenStream;
use proc_macro2::Ident;
use quote::quote;
use syn::{parse_macro_input, ItemFn};

#[proc_macro_attribute]
pub fn corresponds(attr: TokenStream, item: TokenStream) -> TokenStream {
    let function = parse_macro_input!(attr as Ident);
    let item = parse_macro_input!(item as ItemFn);

    let function = function.to_string();
    let line1 = format!("This corresponds to [`{}`].", function);
    let line2 = format!(
        "[`{0}`]: https://www.openssl.org/docs/manmaster/man3/{0}.html",
        function
    );

    let attrs = item.attrs;
    let vis = item.vis;
    let sig = item.sig;
    let block = item.block;

    let out = quote! {
        #(#attrs)*
        #[doc = ""]
        #[doc = #line1]
        #[doc = ""]
        #[doc = #line2]
        #[doc(alias = #function)]
        #vis #sig #block
    };
    out.into()
}
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ foreign-types = "0.3.1"
libc = "0.2"
once_cell = "1.5.2"

openssl-macros = { path = "../openssl-macros" }
ffi = { package = "openssl-sys", version = "0.9.69", path = "../openssl-sys" }

[dev-dependencies]
+14 −52
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ use crate::pkey_ctx::PkeyCtxRef;
use crate::{cvt, cvt_p};
use cfg_if::cfg_if;
use foreign_types::{ForeignType, ForeignTypeRef};
use openssl_macros::corresponds;
use std::convert::TryFrom;
use std::ptr;

@@ -104,10 +105,7 @@ foreign_type_and_impl_send_sync! {

impl MdCtx {
    /// Creates a new context.
    ///
    /// This corresponds to [`EVP_MD_CTX_new`].
    ///
    /// [`EVP_MD_CTX_new`]: https://www.openssl.org/docs/manmaster/crypto/EVP_MD_CTX_new.html
    #[corresponds(EVP_MD_CTX_new)]
    #[inline]
    pub fn new() -> Result<Self, ErrorStack> {
        ffi::init();
@@ -121,10 +119,7 @@ impl MdCtx {

impl MdCtxRef {
    /// Initializes the context to compute the digest of data.
    ///
    /// This corresponds to [`EVP_DigestInit_ex`].
    ///
    /// [`EVP_DigestInit_ex`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestInit_ex.html
    #[corresponds(EVP_DigestInit_ex)]
    #[inline]
    pub fn digest_init(&mut self, digest: &MdRef) -> Result<(), ErrorStack> {
        unsafe {
@@ -141,10 +136,7 @@ impl MdCtxRef {
    /// Initializes the context to compute the signature of data.
    ///
    /// A reference to the context's inner `PkeyCtx` is returned, allowing signature settings to be configured.
    ///
    /// This corresponds to [`EVP_DigestSignInit`].
    ///
    /// [`EVP_DigestSignInit`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignInit.html
    #[corresponds(EVP_DigestSignInit)]
    #[inline]
    pub fn digest_sign_init<'a, T>(
        &'a mut self,
@@ -170,10 +162,7 @@ impl MdCtxRef {
    /// Initializes the context to verify the signature of data.
    ///
    /// A reference to the context's inner `PkeyCtx` is returned, allowing signature settings to be configured.
    ///
    /// This corresponds to [`EVP_DigestVerifyInit`].
    ///
    /// [`EVP_DigestVerifyInit`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignInit.html
    #[corresponds(EVP_DigestVerifyInit)]
    #[inline]
    pub fn digest_verify_init<'a, T>(
        &'a mut self,
@@ -197,10 +186,7 @@ impl MdCtxRef {
    }

    /// Updates the context with more data.
    ///
    /// This corresponds to [`EVP_DigestUpdate`].
    ///
    /// [`EVP_DigestUpdate`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestUpdate.html
    #[corresponds(EVP_DigestUpdate)]
    #[inline]
    pub fn digest_update(&mut self, data: &[u8]) -> Result<(), ErrorStack> {
        unsafe {
@@ -215,10 +201,7 @@ impl MdCtxRef {
    }

    /// Updates the context with more data.
    ///
    /// This corresponds to [`EVP_DigestSignUpdate`].
    ///
    /// [`EVP_DigestSignUpdate`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignUpdate.html
    #[corresponds(EVP_DigestSignUpdate)]
    #[inline]
    pub fn digest_sign_update(&mut self, data: &[u8]) -> Result<(), ErrorStack> {
        unsafe {
@@ -233,10 +216,7 @@ impl MdCtxRef {
    }

    /// Updates the context with more data.
    ///
    /// This corresponds to [`EVP_DigestVerifyUpdate`].
    ///
    /// [`EVP_DigestVerifyUpdate`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestVerifyUpdate.html
    #[corresponds(EVP_DigestVerifyUpdate)]
    #[inline]
    pub fn digest_verify_update(&mut self, data: &[u8]) -> Result<(), ErrorStack> {
        unsafe {
@@ -251,10 +231,7 @@ impl MdCtxRef {
    }

    /// Copies the computed digest into the buffer, returning the number of bytes written.
    ///
    /// This corresponds to [`EVP_DigestFinal`].
    ///
    /// [`EVP_DigestFinal`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestFinal.html
    #[corresponds(EVP_DigestFinal)]
    #[inline]
    pub fn digest_final(&mut self, out: &mut [u8]) -> Result<usize, ErrorStack> {
        let mut len = u32::try_from(out.len()).unwrap_or(u32::MAX);
@@ -273,10 +250,7 @@ impl MdCtxRef {
    /// Copies the computed digest into the buffer.
    ///
    /// Requires OpenSSL 1.1.1 or newer.
    ///
    /// This corresponds to [`EVP_DigestFinalXOF`].
    ///
    /// [`EVP_DigestFinalXOF`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestFinalXOF.html
    #[corresponds(EVP_DigestFinalXOF)]
    #[inline]
    #[cfg(ossl111)]
    pub fn digest_final_xof(&mut self, out: &mut [u8]) -> Result<(), ErrorStack> {
@@ -295,10 +269,7 @@ impl MdCtxRef {
    ///
    /// If `out` is set to `None`, an upper bound on the number of bytes required for the output buffer will be
    /// returned.
    ///
    /// This corresponds to [`EVP_DigestSignFinal`].
    ///
    /// [`EVP_DigestSignFinal`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSignFinal.html
    #[corresponds(EVP_DigestSignFinal)]
    #[inline]
    pub fn digest_sign_final(&mut self, out: Option<&mut [u8]>) -> Result<usize, ErrorStack> {
        let mut len = out.as_ref().map_or(0, |b| b.len());
@@ -328,10 +299,7 @@ impl MdCtxRef {
    ///
    /// Returns `Ok(true)` if the signature is valid, `Ok(false)` if the signature is invalid, and `Err` if an error
    /// occurred.
    ///
    /// This corresponds to [`EVP_DigestVerifyFinal`].
    ///
    /// [`EVP_DigestVerifyFinal`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestVerifyFinal.html
    #[corresponds(EVP_DigestVerifyFinal)]
    #[inline]
    pub fn digest_verify_final(&mut self, signature: &[u8]) -> Result<bool, ErrorStack> {
        unsafe {
@@ -350,10 +318,7 @@ impl MdCtxRef {
    /// returned.
    ///
    /// Requires OpenSSL 1.1.1 or newer.
    ///
    /// This corresponds to [`EVP_DigestSign`].
    ///
    /// [`EVP_DigestSign`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestSign.html
    #[corresponds(EVP_DigestSign)]
    #[cfg(ossl111)]
    #[inline]
    pub fn digest_sign(&mut self, from: &[u8], to: Option<&mut [u8]>) -> Result<usize, ErrorStack> {
@@ -393,10 +358,7 @@ impl MdCtxRef {
    /// occurred.
    ///
    /// Requires OpenSSL 1.1.1 or newer.
    ///
    /// This corresponds to [`EVP_DigestVerify`].
    ///
    /// [`EVP_DigestVerify`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestVerify.html
    #[corresponds(EVP_DigestVerify)]
    #[cfg(ossl111)]
    #[inline]
    pub fn digest_verify(&mut self, data: &[u8], signature: &[u8]) -> Result<bool, ErrorStack> {