Skip to content

Commit

Permalink
Merge pull request #6 from dfns-labs/no-std
Browse files Browse the repository at this point in the history
Allow `no_std` for `generic-ec-zkp`
  • Loading branch information
survived authored Jul 28, 2023
2 parents 0763a7e + 4f910a4 commit f6ac5f4
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 236 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
cache-on-failure: "true"
- name: Build no-std
run: cargo build -p generic-ec --no-default-features
- name: Build
- name: Build with `alloc` only
run: cargo build -p generic-ec --no-default-features --features alloc
- name: Build all-features
run: cargo build -p generic-ec --all-features
- name: Run tests
run: cargo test
Expand Down
3 changes: 3 additions & 0 deletions generic-ec-zkp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ generic-tests = "0.1"
generic-ec = { path = "../generic-ec", default-features = false, features = ["all-curves"] }

[features]
default = ["std"]
std = ["alloc"]
alloc = []
serde = ["dep:serde", "generic-ec/serde", "generic-array/serde"]
10 changes: 10 additions & 0 deletions generic-ec-zkp/src/hash_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,14 @@ impl EncodesToBytes for u16 {
}

/// Error indicating that revealed data doesn't match commitment
#[derive(Debug, Clone, Copy)]
pub struct MismatchedRevealedData;

impl core::fmt::Display for MismatchedRevealedData {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("revealed data doesn't match commitment")
}
}

#[cfg(feature = "std")]
impl std::error::Error for MismatchedRevealedData {}
5 changes: 5 additions & 0 deletions generic-ec-zkp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![cfg_attr(not(test), forbid(unused_crate_dependencies))]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "alloc")]
extern crate alloc;

// We don't want this dependency to trigger unused dep lint
use generic_array as _;
Expand Down
Loading

0 comments on commit f6ac5f4

Please sign in to comment.