Skip to content

Commit

Permalink
Enable no_std support via a default-enabled std feature flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Dec 18, 2024
1 parent 6f71483 commit 96c0b79
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

Entries are listed in reverse chronological order.

## Unreleased

* Enable `no_std` use via a default-enabled `std` feature flag.

## 0.7.0

* Update the `reddsa` dependency to version 0.5.0.
* MSRV is now 1.65

## 0.6.0

Expand Down
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redjubjub"
edition = "2018"
edition = "2021"
# When releasing to crates.io:
# - Update CHANGELOG.md
# - Create git tag.
Expand All @@ -17,10 +17,10 @@ description = "A standalone implementation of the RedJubjub signature scheme."
features = ["nightly"]

[dependencies]
reddsa = "0.5.0"
rand_core = "0.6"
reddsa = { version = "0.5.0", default-features = false, features = ["alloc"] }
rand_core = { version = "0.6", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1.0"
thiserror = { version = "1.0", optional = true }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }

[dev-dependencies]
Expand All @@ -34,7 +34,8 @@ serde_json = "1.0"

[features]
nightly = []
default = ["serde"]
default = ["serde", "std"]
std = ["dep:thiserror", "reddsa/std"]

[[bench]]
name = "bench"
Expand Down
10 changes: 6 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
// - Deirdre Connolly <deirdre@zfnd.org>
// - Henry de Valence <hdevalence@hdevalence.ca>

#[cfg(feature = "std")]
use thiserror::Error;

/// An error related to RedJubJub signatures.
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum Error {
/// The encoding of a signing key was malformed.
#[error("Malformed signing key encoding.")]
#[cfg_attr(feature = "std", error("Malformed signing key encoding."))]
MalformedSigningKey,
/// The encoding of a verification key was malformed.
#[error("Malformed verification key encoding.")]
#[cfg_attr(feature = "std", error("Malformed verification key encoding."))]
MalformedVerificationKey,
/// Signature verification failed.
#[error("Invalid signature.")]
#[cfg_attr(feature = "std", error("Invalid signature."))]
InvalidSignature,
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#![deny(missing_docs)]
#![doc = include_str!("../README.md")]
#![no_std]

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

pub mod batch;
mod error;
Expand Down Expand Up @@ -53,7 +57,7 @@ impl SigType for SpendAuth {}

pub(crate) mod private {
use super::*;
pub trait Sealed: Copy + Clone + Eq + PartialEq + std::fmt::Debug {
pub trait Sealed: Copy + Clone + Eq + PartialEq + core::fmt::Debug {
type RedDSASigType: reddsa::SigType;
}
impl Sealed for Binding {
Expand Down
2 changes: 1 addition & 1 deletion src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// - Deirdre Connolly <deirdre@zfnd.org>
// - Henry de Valence <hdevalence@hdevalence.ca>

use std::convert::{TryFrom, TryInto};
use core::convert::{TryFrom, TryInto};

use crate::{Error, Randomizer, SigType, Signature, SpendAuth, VerificationKey};

Expand Down
4 changes: 2 additions & 2 deletions src/verification_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// - Deirdre Connolly <deirdre@zfnd.org>
// - Henry de Valence <hdevalence@hdevalence.ca>

use std::{convert::TryFrom, hash::Hash};
use core::{convert::TryFrom, hash::Hash};

use crate::{Error, Randomizer, SigType, Signature, SpendAuth};

Expand Down Expand Up @@ -81,7 +81,7 @@ impl<T: SigType> TryFrom<[u8; 32]> for VerificationKey<T> {
type Error = Error;

fn try_from(bytes: [u8; 32]) -> Result<Self, Self::Error> {
use std::convert::TryInto;
use core::convert::TryInto;
VerificationKeyBytes::from(bytes).try_into()
}
}
Expand Down

0 comments on commit 96c0b79

Please sign in to comment.