Use doc_auto_cfg (#618)

Generate feature-dependent rustdoc automatically rather than through
manual annotations
This commit is contained in:
Tony Arcieri
2023-01-15 14:51:43 -07:00
committed by GitHub
parent 6585326574
commit 7a0382c844
12 changed files with 11 additions and 86 deletions
-4
View File
@@ -222,7 +222,6 @@ where
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<C> From<Signature<C>> for Box<[u8]>
where
C: PrimeCurve,
@@ -235,7 +234,6 @@ where
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<C> SignatureEncoding for Signature<C>
where
C: PrimeCurve,
@@ -250,7 +248,6 @@ where
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<C> Serialize for Signature<C>
where
C: PrimeCurve,
@@ -266,7 +263,6 @@ where
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de, C> Deserialize<'de> for Signature<C>
where
C: PrimeCurve,
-3
View File
@@ -29,7 +29,6 @@ pub struct TestVector {
/// Define ECDSA signing test.
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
macro_rules! new_signing_test {
($curve:path, $vectors:expr) => {
use $crate::{
@@ -65,7 +64,6 @@ macro_rules! new_signing_test {
/// Define ECDSA verification test.
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
macro_rules! new_verification_test {
($curve:path, $vectors:expr) => {
use $crate::{
@@ -133,7 +131,6 @@ macro_rules! new_verification_test {
/// Define a Wycheproof verification test.
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
macro_rules! new_wycheproof_test {
($name:ident, $test_name: expr, $curve:path) => {
use $crate::{elliptic_curve::sec1::EncodedPoint, signature::Verifier, Signature};
-6
View File
@@ -50,7 +50,6 @@ use elliptic_curve::ScalarCore;
/// This trait is intended to be implemented on a type with access to the
/// secret scalar via `&self`, such as particular curve's `Scalar` type.
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub trait SignPrimitive<C>: Field + Into<FieldBytes<C>> + Reduce<C::UInt> + Sized
where
C: PrimeCurve + ProjectiveArithmetic + ScalarArithmetic<Scalar = Self>,
@@ -113,7 +112,6 @@ where
///
/// [RFC6979]: https://datatracker.ietf.org/doc/html/rfc6979
#[cfg(all(feature = "rfc6979"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rfc6979")))]
fn try_sign_prehashed_rfc6979<D>(
&self,
z: FieldBytes<C>,
@@ -135,7 +133,6 @@ where
///
/// [RFC6979]: https://datatracker.ietf.org/doc/html/rfc6979
#[cfg(all(feature = "rfc6979"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rfc6979")))]
fn try_sign_digest_rfc6979<D>(
&self,
msg_digest: D,
@@ -156,7 +153,6 @@ where
/// the affine point represeting the public key via `&self`, such as a
/// particular curve's `AffinePoint` type.
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub trait VerifyPrimitive<C>: AffineXCoordinate<C> + Copy + Sized
where
C: PrimeCurve + AffineArithmetic<AffinePoint = Self> + ProjectiveArithmetic,
@@ -194,7 +190,6 @@ where
/// Verify message digest against the provided signature.
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
fn verify_digest<D>(&self, msg_digest: D, sig: &Signature<C>) -> Result<()>
where
D: FixedOutput<OutputSize = FieldSize<C>>,
@@ -214,7 +209,6 @@ where
///
/// [1]: https://github.com/RustCrypto/traits/tree/master/signature/derive
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub trait DigestPrimitive: PrimeCurve {
/// Preferred digest to use when computing ECDSA signatures for this
/// elliptic curve. This is typically a member of the SHA-2 family.
+1 -18
View File
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
@@ -60,20 +60,13 @@ extern crate alloc;
mod recovery;
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
pub mod der;
#[cfg(feature = "dev")]
#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
pub mod dev;
#[cfg(feature = "hazmat")]
#[cfg_attr(docsrs, doc(cfg(feature = "hazmat")))]
pub mod hazmat;
#[cfg(feature = "signing")]
mod signing;
#[cfg(feature = "verifying")]
mod verifying;
@@ -86,11 +79,8 @@ pub use elliptic_curve::{self, sec1::EncodedPoint, PrimeCurve};
pub use signature::{self, Error, Result, SignatureEncoding};
#[cfg(feature = "signing")]
#[cfg_attr(docsrs, doc(cfg(feature = "signing")))]
pub use crate::signing::SigningKey;
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
pub use crate::verifying::VerifyingKey;
use core::{
@@ -156,7 +146,6 @@ where
{
/// Parse a signature from ASN.1 DER
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
pub fn from_der(bytes: &[u8]) -> Result<Self>
where
der::MaxSize<C>: ArrayLength<u8>,
@@ -187,7 +176,6 @@ where
/// Serialize this signature as ASN.1 DER.
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
pub fn to_der(&self) -> der::Signature<C>
where
der::MaxSize<C>: ArrayLength<u8>,
@@ -199,14 +187,12 @@ where
/// Convert this signature into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn to_vec(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
impl<C> Signature<C>
where
C: PrimeCurve + ScalarArithmetic,
@@ -347,7 +333,6 @@ where
}
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
impl<C> str::FromStr for Signature<C>
where
C: PrimeCurve + ScalarArithmetic,
@@ -384,7 +369,6 @@ where
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<C> Serialize for Signature<C>
where
C: PrimeCurve,
@@ -399,7 +383,6 @@ where
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de, C> Deserialize<'de> for Signature<C>
where
C: PrimeCurve,
-2
View File
@@ -72,7 +72,6 @@ impl RecoveryId {
}
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
impl RecoveryId {
/// Given a public key, message, and signature, use trial recovery
/// to determine if a suitable recovery ID exists, or return an error
@@ -158,7 +157,6 @@ impl From<RecoveryId> for u8 {
}
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
impl<C> VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
+1 -15
View File
@@ -1,6 +1,4 @@
//! ECDSA signing key.
// TODO(tarcieri): support for hardware crypto accelerators
//! ECDSA signing: producing signatures using a [`SigningKey`].
use crate::{
hazmat::{bits2field, DigestPrimitive, SignPrimitive},
@@ -46,7 +44,6 @@ use {crate::VerifyingKey, elliptic_curve::PublicKey, signature::KeypairRef};
/// Requires an [`elliptic_curve::ProjectiveArithmetic`] impl on the curve, and a
/// [`SignPrimitive`] impl on its associated `Scalar` type.
#[derive(Clone)]
#[cfg_attr(docsrs, doc(cfg(feature = "signing")))]
pub struct SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
@@ -97,7 +94,6 @@ where
/// Get the [`VerifyingKey`] which corresponds to this [`SigningKey`].
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
pub fn verifying_key(&self) -> &VerifyingKey<C> {
&self.verifying_key
}
@@ -196,7 +192,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C> PrehashSigner<der::Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
@@ -213,7 +208,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C> Signer<der::Signature<C>> for SigningKey<C>
where
Self: DigestSigner<C::Digest, Signature<C>>,
@@ -229,7 +223,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C, D> RandomizedDigestSigner<D, der::Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
@@ -251,7 +244,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C> RandomizedSigner<der::Signature<C>> for SigningKey<C>
where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
@@ -275,7 +267,6 @@ where
//
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
impl<C> AsRef<VerifyingKey<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
@@ -449,7 +440,6 @@ where
}
#[cfg(feature = "verifying")]
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
impl<C> KeypairRef for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
@@ -460,7 +450,6 @@ where
}
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
impl<C> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
@@ -477,7 +466,6 @@ where
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<C> EncodePrivateKey for SigningKey<C>
where
C: AssociatedOid + PrimeCurve + ProjectiveArithmetic,
@@ -492,7 +480,6 @@ where
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<C> FromStr for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
@@ -509,7 +496,6 @@ where
}
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
impl<C> DecodePrivateKey for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
+1 -12
View File
@@ -1,4 +1,4 @@
//! ECDSA verification key.
//! ECDSA verifying: checking signatures are authentic using a [`VerifyingKey`].
use crate::{
hazmat::{bits2field, DigestPrimitive, VerifyPrimitive},
@@ -30,7 +30,6 @@ use elliptic_curve::pkcs8::EncodePublicKey;
use core::str::FromStr;
#[cfg(all(feature = "pem", feature = "serde"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "serde"))))]
use serdect::serde::{de, ser, Deserialize, Serialize};
/// ECDSA verification key (i.e. public key). Generic over elliptic curves.
@@ -46,7 +45,6 @@ use serdect::serde::{de, ser, Deserialize, Serialize};
///
/// The serialization leverages the encoding used by the [`PublicKey`] type,
/// which is a binary-oriented ASN.1 DER encoding.
#[cfg_attr(docsrs, doc(cfg(feature = "verifying")))]
#[derive(Clone, Debug)]
pub struct VerifyingKey<C>
where
@@ -141,7 +139,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C, D> DigestVerifier<D, der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
@@ -159,7 +156,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C> PrehashVerifier<der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
@@ -176,7 +172,6 @@ where
}
#[cfg(feature = "der")]
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
impl<C> Verifier<der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
@@ -304,7 +299,6 @@ where
}
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
impl<C> TryFrom<pkcs8::SubjectPublicKeyInfo<'_>> for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
@@ -319,7 +313,6 @@ where
}
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
impl<C> DecodePublicKey for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
@@ -329,7 +322,6 @@ where
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<C> EncodePublicKey for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
@@ -342,7 +334,6 @@ where
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<C> FromStr for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
@@ -357,7 +348,6 @@ where
}
#[cfg(all(feature = "pem", feature = "serde"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "serde"))))]
impl<C> Serialize for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
@@ -373,7 +363,6 @@ where
}
#[cfg(all(feature = "pem", feature = "serde"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "pem", feature = "serde"))))]
impl<'de, C> Deserialize<'de> for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
+1 -3
View File
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
#![allow(non_snake_case)]
@@ -261,7 +261,6 @@
extern crate alloc;
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
pub mod pkcs8;
#[cfg(feature = "serde")]
@@ -347,7 +346,6 @@ impl Signature {
/// Convert this signature into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn to_vec(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
-6
View File
@@ -121,7 +121,6 @@ impl Drop for KeypairBytes {
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl EncodePrivateKey for KeypairBytes {
fn to_pkcs8_der(&self) -> Result<SecretDocument> {
// Serialize private key as nested OCTET STRING
@@ -198,7 +197,6 @@ impl fmt::Debug for KeypairBytes {
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl str::FromStr for KeypairBytes {
type Err = Error;
@@ -245,7 +243,6 @@ impl AsRef<[u8; Self::BYTE_SIZE]> for PublicKeyBytes {
impl DecodePublicKey for PublicKeyBytes {}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl EncodePublicKey for PublicKeyBytes {
fn to_public_key_der(&self) -> pkcs8::spki::Result<Document> {
pkcs8::SubjectPublicKeyInfo {
@@ -310,7 +307,6 @@ impl fmt::Debug for PublicKeyBytes {
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl str::FromStr for PublicKeyBytes {
type Err = pkcs8::spki::Error;
@@ -320,7 +316,6 @@ impl str::FromStr for PublicKeyBytes {
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl ToString for PublicKeyBytes {
fn to_string(&self) -> String {
self.to_public_key_pem(Default::default())
@@ -329,7 +324,6 @@ impl ToString for PublicKeyBytes {
}
#[cfg(feature = "pem")]
#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
#[cfg(test)]
mod tests {
use super::{KeypairBytes, PublicKeyBytes};
-4
View File
@@ -7,7 +7,6 @@ use core::fmt;
#[cfg(feature = "serde_bytes")]
use serde_bytes_crate as serde_bytes;
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl Serialize for Signature {
fn serialize<S: ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
use ser::SerializeTuple;
@@ -24,7 +23,6 @@ impl Serialize for Signature {
// serde lacks support for deserializing arrays larger than 32-bytes
// see: <https://github.com/serde-rs/serde/issues/631>
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> Deserialize<'de> for Signature {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct ByteArrayVisitor;
@@ -59,7 +57,6 @@ impl<'de> Deserialize<'de> for Signature {
}
#[cfg(feature = "serde_bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde_bytes")))]
impl serde_bytes::Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -70,7 +67,6 @@ impl serde_bytes::Serialize for Signature {
}
#[cfg(feature = "serde_bytes")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde_bytes")))]
impl<'de> serde_bytes::Deserialize<'de> for Signature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
-4
View File
@@ -21,7 +21,3 @@ zeroize = { version = "1", default-features = false }
[dev-dependencies]
sha2 = "0.10"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
+7 -9
View File
@@ -1,4 +1,11 @@
#![no_std]
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code, clippy::unwrap_used)]
#![warn(missing_docs, rust_2018_idioms)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]
//! ## Usage
//!
@@ -29,15 +36,6 @@
//! assert_eq!(&k.to_be_byte_array(), &RFC6979_EXPECTED_K.to_be_byte_array());
//! ```
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code, clippy::unwrap_used)]
#![warn(missing_docs, rust_2018_idioms)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]
use crypto_bigint::{ArrayEncoding, ByteArray, Integer};
use hmac::{
digest::{