Skip to content

Commit

Permalink
Use doc_auto_cfg (#1116)
Browse files Browse the repository at this point in the history
Generates `doc_cfg` automatically
  • Loading branch information
tony-iqlusion authored Mar 28, 2023
1 parent 311fc5d commit 8de5858
Show file tree
Hide file tree
Showing 35 changed files with 7 additions and 83 deletions.
1 change: 0 additions & 1 deletion bip32/src/derivation_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use core::{
const PREFIX: &str = "m";

/// Derivation paths within a hierarchical keyspace.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DerivationPath {
path: Vec<ChildNumber>,
Expand Down
5 changes: 0 additions & 5 deletions bip32/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl Display for Error {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {}

impl From<bs58::decode::Error> for Error {
Expand Down Expand Up @@ -74,31 +73,27 @@ impl From<hmac::digest::InvalidLength> for Error {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<k256::elliptic_curve::Error> for Error {
fn from(_: k256::elliptic_curve::Error) -> Error {
Error::Crypto
}
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<k256::ecdsa::Error> for Error {
fn from(_: k256::ecdsa::Error) -> Error {
Error::Crypto
}
}

#[cfg(feature = "secp256k1-ffi")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1-ffi")))]
impl From<secp256k1_ffi::Error> for Error {
fn from(_: secp256k1_ffi::Error) -> Error {
Error::Crypto
}
}

#[cfg(feature = "secp256k1-ffi")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1-ffi")))]
impl From<secp256k1_ffi::scalar::OutOfRangeError> for Error {
fn from(_: secp256k1_ffi::scalar::OutOfRangeError) -> Error {
Error::Crypto
Expand Down
3 changes: 0 additions & 3 deletions bip32/src/extended_key/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const BIP39_DOMAIN_SEPARATOR: [u8; 12] = [

/// Extended private secp256k1 ECDSA signing key.
#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub type XPrv = ExtendedPrivateKey<k256::ecdsa::SigningKey>;

/// Extended private keys derived using BIP32.
Expand All @@ -52,7 +51,6 @@ where

/// Derive a child key from the given [`DerivationPath`].
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn derive_from_path<S>(seed: S, path: &DerivationPath) -> Result<Self>
where
S: AsRef<[u8]>,
Expand Down Expand Up @@ -163,7 +161,6 @@ where

/// Serialize this key as a self-[`Zeroizing`] `String`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn to_string(&self, prefix: Prefix) -> Zeroizing<String> {
Zeroizing::new(self.to_extended_key(prefix).to_string())
}
Expand Down
2 changes: 0 additions & 2 deletions bip32/src/extended_key/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use alloc::string::{String, ToString};

/// Extended public secp256k1 ECDSA verification key.
#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub type XPub = ExtendedPublicKey<k256::ecdsa::VerifyingKey>;

/// Extended public keys derived using BIP32.
Expand Down Expand Up @@ -94,7 +93,6 @@ where

/// Serialize this key as a `String`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn to_string(&self, prefix: Prefix) -> String {
self.to_extended_key(prefix).to_string()
}
Expand Down
4 changes: 1 addition & 3 deletions bip32/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(
Expand Down Expand Up @@ -130,11 +130,9 @@ pub use crate::{
pub use crate::derivation_path::DerivationPath;

#[cfg(feature = "bip39")]
#[cfg_attr(docsrs, doc(cfg(feature = "bip39")))]
pub use crate::mnemonic::{Language, Phrase as Mnemonic, Seed};

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub use {
crate::extended_key::{private_key::XPrv, public_key::XPub},
k256 as secp256k1,
Expand Down
1 change: 0 additions & 1 deletion bip32/src/mnemonic/phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ impl Phrase {

/// Convert this mnemonic phrase into the BIP39 seed value.
#[cfg(feature = "bip39")]
#[cfg_attr(docsrs, doc(cfg(feature = "bip39")))]
pub fn to_seed(&self, password: &str) -> Seed {
let salt = Zeroizing::new(format!("mnemonic{}", password));
let mut seed = [0u8; Seed::SIZE];
Expand Down
1 change: 0 additions & 1 deletion bip32/src/mnemonic/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use zeroize::Zeroize;

/// BIP39 seeds.
// TODO(tarcieri): support for 32-byte seeds
#[cfg_attr(docsrs, doc(cfg(feature = "bip39")))]
pub struct Seed(pub(crate) [u8; Seed::SIZE]);

impl Seed {
Expand Down
5 changes: 0 additions & 5 deletions bip32/src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub trait PrivateKey: Sized {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl PrivateKey for k256::SecretKey {
type PublicKey = k256::PublicKey;

Expand Down Expand Up @@ -59,7 +58,6 @@ impl PrivateKey for k256::SecretKey {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl PrivateKey for k256::ecdsa::SigningKey {
type PublicKey = k256::ecdsa::VerifyingKey;

Expand All @@ -83,23 +81,20 @@ impl PrivateKey for k256::ecdsa::SigningKey {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<XPrv> for k256::ecdsa::SigningKey {
fn from(xprv: XPrv) -> k256::ecdsa::SigningKey {
k256::ecdsa::SigningKey::from(&xprv)
}
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<&XPrv> for k256::ecdsa::SigningKey {
fn from(xprv: &XPrv) -> k256::ecdsa::SigningKey {
xprv.private_key().clone()
}
}

#[cfg(feature = "secp256k1-ffi")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1-ffi")))]
impl PrivateKey for secp256k1_ffi::SecretKey {
type PublicKey = secp256k1_ffi::PublicKey;

Expand Down
5 changes: 0 additions & 5 deletions bip32/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub trait PublicKey: Sized {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl PublicKey for k256::PublicKey {
fn from_bytes(bytes: PublicKeyBytes) -> Result<Self> {
Ok(k256::PublicKey::from_sec1_bytes(&bytes)?)
Expand All @@ -60,7 +59,6 @@ impl PublicKey for k256::PublicKey {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl PublicKey for k256::ecdsa::VerifyingKey {
fn from_bytes(bytes: PublicKeyBytes) -> Result<Self> {
Ok(k256::ecdsa::VerifyingKey::from_sec1_bytes(&bytes)?)
Expand All @@ -81,23 +79,20 @@ impl PublicKey for k256::ecdsa::VerifyingKey {
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<XPub> for k256::ecdsa::VerifyingKey {
fn from(xpub: XPub) -> k256::ecdsa::VerifyingKey {
k256::ecdsa::VerifyingKey::from(&xpub)
}
}

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
impl From<&XPub> for k256::ecdsa::VerifyingKey {
fn from(xpub: &XPub) -> k256::ecdsa::VerifyingKey {
*xpub.public_key()
}
}

#[cfg(feature = "secp256k1-ffi")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1-ffi")))]
impl PublicKey for secp256k1_ffi::PublicKey {
fn from_bytes(bytes: PublicKeyBytes) -> Result<Self> {
Ok(secp256k1_ffi::PublicKey::from_slice(&bytes)?)
Expand Down
2 changes: 1 addition & 1 deletion hkd32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! [bip32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]

#[cfg(feature = "alloc")]
Expand Down
1 change: 0 additions & 1 deletion hkd32/src/mnemonic/phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ impl Phrase {

/// Convert this mnemonic phrase into the BIP39 seed value.
#[cfg(feature = "bip39")]
#[cfg_attr(docsrs, doc(cfg(feature = "bip39")))]
pub fn to_seed(&self, password: &str) -> Seed {
let salt = Zeroizing::new(format!("mnemonic{}", password));
let mut seed = [0u8; Seed::SIZE];
Expand Down
1 change: 0 additions & 1 deletion hkd32/src/mnemonic/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use zeroize::Zeroize;

/// BIP39 seeds.
// TODO(tarcieri): support for 32-byte seeds
#[cfg_attr(docsrs, doc(cfg(feature = "bip39")))]
pub struct Seed(pub(crate) [u8; Seed::SIZE]);

impl Seed {
Expand Down
3 changes: 0 additions & 3 deletions iqhttp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error {
/// JSON errors
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
Json(serde_json::Error),

/// Invalid header value
Expand All @@ -26,7 +25,6 @@ pub enum Error {

/// Proxy errors
#[cfg(feature = "proxy")]
#[cfg_attr(docsrs, doc(cfg(feature = "proxy")))]
Proxy(std::io::Error),
}

Expand Down Expand Up @@ -65,7 +63,6 @@ impl From<hyper::Error> for Error {
}

#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Error {
Error::Json(err)
Expand Down
2 changes: 0 additions & 2 deletions iqhttp/src/https_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl HttpsClient {
/// via the provided HTTP CONNECT proxy.
// TODO(tarcieri): proxy auth
#[cfg(feature = "proxy")]
#[cfg_attr(docsrs, doc(cfg(feature = "proxy")))]
pub fn new_with_proxy(hostname: impl Into<String>, proxy_uri: Uri) -> Result<Self> {
let connector = Self::https_connector();
let proxy = Proxy::new(Intercept::All, proxy_uri);
Expand Down Expand Up @@ -113,7 +112,6 @@ impl HttpsClient {

/// Perform HTTP GET request and parse the response as JSON.
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub async fn get_json<T>(&self, path: &Path, query: &Query) -> Result<T>
where
T: DeserializeOwned,
Expand Down
3 changes: 1 addition & 2 deletions iqhttp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![forbid(unsafe_code)]
#![warn(
clippy::unwrap_used,
Expand All @@ -9,7 +9,6 @@
)]

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub mod serializers;

mod error;
Expand Down
2 changes: 1 addition & 1 deletion secrecy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ they aren't accidentally copied, logged, or otherwise exposed
(as much as possible), and also ensure secrets are securely wiped
from memory when dropped.
"""
version = "0.9.0-pre" # Also update html_root_url in lib.rs when bumping this
version = "0.9.0-pre"
authors = ["Tony Arcieri <[email protected]>"]
license = "Apache-2.0 OR MIT"
homepage = "https://github.com/iqlusioninc/crates/"
Expand Down
1 change: 0 additions & 1 deletion secrecy/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloc::boxed::Box;
use zeroize::Zeroize;

/// `Box` types containing a secret value
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub type SecretBox<S> = Secret<Box<S>>;

impl<S: DebugSecret + Zeroize> DebugSecret for Box<S> {}
1 change: 0 additions & 1 deletion secrecy/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use serde::de::{self, Deserialize};
/// Because of the nature of how the `BytesMut` type works, it needs some special
/// care in order to have a proper zeroizing drop handler.
#[derive(Clone)]
#[cfg_attr(docsrs, doc(cfg(feature = "bytes")))]
pub struct SecretBytesMut(BytesMut);

impl SecretBytesMut {
Expand Down
4 changes: 1 addition & 3 deletions secrecy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
//! the [`SerializableSecret`] marker trait on `T`.
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_root_url = "https://docs.rs/secrecy/0.8.0")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]

Expand Down Expand Up @@ -255,7 +254,6 @@ impl_debug_secret_for_array!(
/// [1]: https://docs.rs/secrecy/latest/secrecy/struct.Secret.html#implementations
/// [2]: https://serde.rs/field-attrs.html#serialize_with
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub trait SerializableSecret: Serialize {}

#[cfg(feature = "serde")]
Expand Down
1 change: 0 additions & 1 deletion secrecy/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloc::str::FromStr;
use alloc::string::{String, ToString};

/// Secret strings
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub type SecretString = Secret<String>;

impl DebugSecret for String {}
Expand Down
1 change: 0 additions & 1 deletion secrecy/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloc::vec::Vec;
use zeroize::Zeroize;

/// `Vec` types containing secret value
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub type SecretVec<S> = Secret<Vec<S>>;

impl<S: CloneableSecret + Zeroize> CloneableSecret for Vec<S> {}
Expand Down
4 changes: 0 additions & 4 deletions signatory/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ use crate::ed25519;
pub enum Algorithm {
/// ECDSA with NIST P-256.
#[cfg(feature = "nistp256")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp256")))]
EcdsaNistP256,

/// ECDSA with NIST P-384.
#[cfg(feature = "nistp384")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp384")))]
EcdsaNistP384,

/// ECDSA with secp256k1.
#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
EcdsaSecp256k1,

/// Ed25519.
#[cfg(feature = "ed25519")]
#[cfg_attr(docsrs, doc(cfg(feature = "ed25519")))]
Ed25519,
}

Expand Down
6 changes: 0 additions & 6 deletions signatory/src/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//! Elliptic Curve Digital Signature Algorithm (ECDSA) support.
#[cfg(feature = "nistp256")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp256")))]
pub mod nistp256;

#[cfg(feature = "nistp384")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp384")))]
pub mod nistp384;

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub mod secp256k1;

mod keyring;
Expand All @@ -18,13 +15,10 @@ pub use self::keyring::KeyRing;
pub use ecdsa::{elliptic_curve, Signature};

#[cfg(feature = "nistp256")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp256")))]
pub use {self::nistp256::NistP256Signer, p256::NistP256};

#[cfg(feature = "nistp384")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp384")))]
pub use {self::nistp384::NistP384Signer, p384::NistP384};

#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub use {self::secp256k1::Secp256k1Signer, k256::Secp256k1};
Loading

0 comments on commit 8de5858

Please sign in to comment.