Skip to content

Commit

Permalink
support no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit committed Apr 3, 2023
1 parent 5a14675 commit d9ea287
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ categories = [ "cryptography" ]
cryptoxide = "0.4"

[features]
default = []
with-bench = []
default = ["std"]
std = []
with-bench = []
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
3 changes: 3 additions & 0 deletions src/derivation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

mod common;
pub mod v2;

Expand Down
6 changes: 6 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

const ALPHABET: &'static [u8] = b"0123456789abcdef";

pub fn encode(input: &[u8]) -> String {
Expand Down
3 changes: 3 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

use std::fmt;

use cryptoxide::constant_time::CtEqual;
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@
//! In soft derivation, the important property is that given the parent public key,
//! one can derive all softly derived children public key.
#![cfg_attr(feature = "with-bench", feature(test))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(error_in_core))]

#![cfg_attr(feature = "with-bench", feature(test))]
#[cfg(test)]
#[cfg(feature = "with-bench")]
extern crate test;

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

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

mod derivation;
mod hex;
mod key;
Expand Down
3 changes: 3 additions & 0 deletions src/securemem.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

pub fn zero(to_zero: &mut [u8]) {
// the unsafety of this call is bounded to the existence of the pointer
// and the accuracy of the length of the array.
Expand Down
3 changes: 3 additions & 0 deletions src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

use super::hex;
use std::error::Error;
use std::fmt;
Expand Down

0 comments on commit d9ea287

Please sign in to comment.