Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ sha2 = { version = "0.9", default-features = false }

[features]
default = ["digest"]
alloc = []
dev = ["digest", "zeroize"]
digest = ["elliptic-curve/digest", "signature/digest-preview"]
hazmat = []
rand = ["elliptic-curve/rand", "signature/rand-preview"]
sign = ["digest", "hazmat", "hmac", "zeroize"]
std = ["elliptic-curve/std", "signature/std"]
std = ["alloc", "elliptic-curve/std", "signature/std"]
verify = ["digest", "hazmat"]
zeroize = ["elliptic-curve/zeroize"]

Expand Down
16 changes: 15 additions & 1 deletion ecdsa/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use core::{
};
use elliptic_curve::{consts::U9, weierstrass::Curve, ElementBytes};

#[cfg(feature = "alloc")]
use alloc::boxed::Box;

/// Maximum overhead of an ASN.1 DER-encoded ECDSA signature for a given curve:
/// 9-bytes.
///
Expand Down Expand Up @@ -92,6 +95,17 @@ where
self.s_range.end
}

/// Borrow this signature as a byte slice
pub fn as_bytes(&self) -> &[u8] {
&self.bytes.as_slice()[..self.len()]
}

/// Serialize this signature as a boxed byte slice
#[cfg(feature = "alloc")]
pub fn to_bytes(&self) -> Box<[u8]> {
self.as_bytes().to_vec().into_boxed_slice()
}

/// Create an ASN.1 DER encoded signature from the `r` and `s` scalars
pub(crate) fn from_scalars(r: &ElementBytes<C>, s: &ElementBytes<C>) -> Self {
let r_len = int_length(r);
Expand Down Expand Up @@ -144,7 +158,7 @@ where
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
fn as_ref(&self) -> &[u8] {
&self.bytes.as_slice()[..self.len()]
self.as_bytes()
}
}

Expand Down
3 changes: 3 additions & 0 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
html_root_url = "https://docs.rs/ecdsa/0.7.2"
)]

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

pub mod asn1;

#[cfg(feature = "dev")]
Expand Down