Skip to content

Commit

Permalink
fix: compilation with default-features = false
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Apr 9, 2024
1 parent df661bb commit 6665b6f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 54 deletions.
110 changes: 71 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,81 @@ on:
pull_request:

jobs:
code-check:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
components: rustfmt, clippy
bins: cargo-audit
- name: Check formatting with cargofmt
run: cargo fmt -- --check
- name: Check for lint warnings
run: cargo clippy --all-features -- -D warnings
- name: Run cargo audit to identify known security vulnerabilities reported to the RustSec Advisory Database
run: cargo audit
release-tests-ubuntu:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-audit
- name:
Run cargo audit to identify known security vulnerabilities reported to the RustSec
Advisory Database
run: cargo audit

test:
name: test ${{ matrix.flags }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
flags: ["--no-default-features", "", "--features ed25519", "--features rust-secp256k1"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: test
run: cargo test ${{ matrix.flags }}

feature-checks:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2

clippy:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
env:
RUSTFLAGS: -Dwarnings

docs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Get latest version of stable Rust
uses: moonrepo/setup-rust@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
channel: stable
cache-target: release
bins: cargo-nextest
- name: Run tests in release
run: cargo nextest run --all --release --tests
- name: Run tests in release ed25519
run: cargo nextest run --all --release --features "ed25519" --tests
- name: Run tests in release secp256k1
run: cargo nextest run --all --release --features "secp256k1" --tests
- name: Run tests in release rust-secp256k1
run: cargo nextest run --all --release --features "rust-secp256k1" --tests
- name: Run tests in release all features
run: cargo nextest run --all --release --all-features
check-rustdoc-links:
name: Check rustdoc intra-doc links
cache-on-failure: true
- run: cargo doc --workspace --all-features --no-deps --document-private-items
env:
RUSTDOCFLAGS: "--cfg docsrs -D warnings"

fmt:
runs-on: ubuntu-latest
container:
image: rust
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Check rustdoc links
run: RUSTDOCFLAGS="--deny broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --all --check
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "enr"
authors = ["Age Manning <[email protected]>"]
edition = "2018"
edition = "2021"
version = "0.11.1"
description = "Rust implementation of Ethereum Node Record (ENR) EIP778"
readme = "./README.md"
Expand All @@ -12,30 +12,32 @@ license = "MIT"
exclude = [".gitignore", ".github/*"]

[dependencies]
alloy-rlp = { version = "0.3.4", default-features = true }
base64 = "0.21.7"
alloy-rlp = "0.3.4"
base64 = "0.21"
bytes = "1"
hex = { version = "0.4.3" }
hex = "0.4.3"
log = "0.4.21"
rand = "0.8"
zeroize = "1.7.0"
sha3 = "0.10"
k256 = { version = "0.13", features = ["ecdsa"], optional = true }
serde = { version = "1.0.197", features = ["derive"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
ed25519-dalek = { version = "2.1.1", optional = true, features = ["rand_core"] }
secp256k1 = { version = "0.28", optional = true, default-features = false, features = [
"global-context",
] }

[dev-dependencies]
alloy-rlp = { version = "0.3.4", features = ["derive"] }
secp256k1 = { features = ["rand-std"], version = "0.28" }
serde_json = { version = "1.0.114" }
secp256k1 = { version = "0.28", features = ["rand-std"] }
serde_json = "1.0"

[features]
default = ["serde", "k256"]
ed25519 = ["ed25519-dalek"]
rust-secp256k1 = ["secp256k1"]
default = ["serde"]
ed25519 = ["dep:ed25519-dalek"]
k256 = ["dep:k256"]
secp256k1 = ["rust-secp256k1"]
rust-secp256k1 = ["dep:secp256k1"]

[lib]
name = "enr"
Expand Down
2 changes: 1 addition & 1 deletion src/keys/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{ed25519_dalek as ed25519, EnrKey, EnrPublicKey, SigningError};
use crate::Key;
use alloy_rlp::Error as DecoderError;
use bytes::Bytes;
use std::{collections::BTreeMap, convert::TryFrom};
use std::collections::BTreeMap;
use zeroize::Zeroize;

/// A standard implementation of the `EnrKey` trait used to sign and modify ENR records. The variants here represent the currently
Expand Down
2 changes: 1 addition & 1 deletion src/keys/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
use crate::Key;
use alloy_rlp::{Decodable, Error as DecoderError};
use bytes::Bytes;
use std::{collections::BTreeMap, convert::TryFrom};
use std::collections::BTreeMap;

/// The ENR key that stores the public key in the ENR record.
pub const ENR_KEY: &str = "ed25519";
Expand Down
2 changes: 1 addition & 1 deletion src/keys/k256_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use k256::{
};
use rand::rngs::OsRng;
use sha3::{Digest, Keccak256};
use std::{collections::BTreeMap, convert::TryFrom};
use std::collections::BTreeMap;

/// The ENR key that stores the public key in the ENR record.
pub const ENR_KEY: &str = "secp256k1";
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
//!
//! ### Building an ENR with the default `k256` `secp256k1` key type
//!
//! Note the `k256` feature flag must be set (default).
//!
//! ```rust
//! # #[cfg(feature = "k256")] {
//! use enr::{Enr, k256};
//! use std::net::Ipv4Addr;
//! use rand::thread_rng;
Expand All @@ -61,6 +64,7 @@
//!
//! assert_eq!(enr.ip4(), Some("192.168.0.1".parse().unwrap()));
//! assert_eq!(enr.id(), Some("v4".into()));
//! # }
//! ```
//!
//! ### Building an ENR with the `CombinedKey` type (support for multiple signing
Expand Down Expand Up @@ -92,6 +96,7 @@
//! can be added using [`insert`] and retrieved with [`get`].
//!
//! ```rust
//! # #[cfg(feature = "k256")] {
//! use enr::{k256::ecdsa::SigningKey, Enr};
//! use std::net::Ipv4Addr;
//! use rand::thread_rng;
Expand Down Expand Up @@ -120,6 +125,7 @@
//! assert_eq!(decoded_enr.id(), Some("v4".into()));
//! assert_eq!(decoded_enr.tcp4(), Some(8001));
//! assert_eq!(decoded_enr.get("custom_key").as_ref().map(AsRef::as_ref), Some(vec![0,0,1]).as_deref());
//! # }
//! ```
//!
//! ### Encoding/Decoding ENR's of various key types
Expand Down Expand Up @@ -167,7 +173,7 @@
//! [`insert`]: struct.Enr.html#method.insert
//! [`get`]: struct.Enr.html#method.get

#![warn(clippy::all)]
#![warn(clippy::all, rustdoc::all)]
#![allow(
clippy::map_err_ignore,
clippy::missing_errors_doc,
Expand Down Expand Up @@ -1132,7 +1138,10 @@ fn check_spec_reserved_keys(key: &[u8], mut value: &[u8]) -> Result<(), Error> {
Ipv6Addr::decode(&mut value)?;
}
b"secp256k1" => {
#[cfg(all(feature = "k256", not(feature = "rust-secp256k1")))]
<Enr<k256::ecdsa::SigningKey>>::decode(&mut value)?;
#[cfg(feature = "rust-secp256k1")]
<Enr<secp256k1::SecretKey>>::decode(&mut value)?;
}
_ => return Ok(()),
};
Expand All @@ -1143,7 +1152,6 @@ fn check_spec_reserved_keys(key: &[u8], mut value: &[u8]) -> Result<(), Error> {
#[cfg(feature = "k256")]
mod tests {
use super::*;
use std::convert::TryFrom;

type DefaultEnr = Enr<k256::ecdsa::SigningKey>;

Expand Down

0 comments on commit 6665b6f

Please sign in to comment.