mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
Merge pull request #28 from RustCrypto/simplify-alloc-gating
signature: Simplify alloc gating
This commit is contained in:
+10
-17
@@ -2,17 +2,11 @@ language: rust
|
||||
cache: cargo
|
||||
|
||||
rust:
|
||||
- 1.31.0
|
||||
- 1.36.0
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
|
||||
install:
|
||||
- rustup component add rustfmt
|
||||
- rustup component add clippy
|
||||
- rustup target add thumbv7em-none-eabihf
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
|
||||
script:
|
||||
- cargo test --verbose --release
|
||||
- cargo test --verbose --all-features --release
|
||||
@@ -25,23 +19,22 @@ matrix:
|
||||
include:
|
||||
- name: "Rust: stable (thumbv7em-none-eabihf)"
|
||||
rust: stable
|
||||
script:
|
||||
- cd signature-crate && cargo build --target thumbv7em-none-eabihf --no-default-features --release
|
||||
install: rustup target add thumbv7em-none-eabihf
|
||||
script: cd signature-crate && cargo build --target thumbv7em-none-eabihf --no-default-features --release
|
||||
- name: "Rust: stable (wasm32-unknown-unknown)"
|
||||
rust: stable
|
||||
script:
|
||||
- cd signature-crate && cargo build --target wasm32-unknown-unknown --no-default-features --release
|
||||
install: rustup target add wasm32-unknown-unknown
|
||||
script: cd signature-crate && cargo build --target wasm32-unknown-unknown --no-default-features --release
|
||||
- name: rustfmt
|
||||
rust: stable
|
||||
script:
|
||||
- cargo fmt --all -- --check
|
||||
install: rustup component add rustfmt
|
||||
script: cargo fmt --all -- --check
|
||||
- name: clippy
|
||||
install: rustup component add clippy
|
||||
rust: stable
|
||||
script:
|
||||
- cargo clippy --all
|
||||
script: cargo clippy --all
|
||||
- name: docs
|
||||
script:
|
||||
- cargo doc --all --no-deps
|
||||
script: cargo doc --all --no-deps
|
||||
|
||||
branches:
|
||||
only:
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
[![Build Status][build-image]][build-link]
|
||||
|
||||
This crate contains traits which provide generic, object-safe APIs for
|
||||
generating and verifying [digital signatures].
|
||||
generating and verifying [digital signatures][1].
|
||||
|
||||
The long-term goal is to use this crate in conjunction with the
|
||||
[`ecdsa`][ecdsa-crate] and [`ed25519`][ed25519-crate], however those crates
|
||||
are a work-in-progress.
|
||||
It's presently useful in conjunction with the [`ed25519`][2] crate.
|
||||
Support is also planned for the [`ecdsa`][3] and [`rsa`][4] crates.
|
||||
|
||||
[Documentation][docs-link]
|
||||
|
||||
## Requirements
|
||||
|
||||
- Rust **1.36+**
|
||||
|
||||
## License
|
||||
|
||||
All crates licensed under either of
|
||||
@@ -37,12 +40,13 @@ dual licensed as above, without any additional terms or conditions.
|
||||
[docs-image]: https://docs.rs/signature/badge.svg
|
||||
[docs-link]: https://docs.rs/signature/
|
||||
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
|
||||
[rustc-image]: https://img.shields.io/badge/rustc-1.31+-blue.svg
|
||||
[rustc-image]: https://img.shields.io/badge/rustc-1.36+-blue.svg
|
||||
[build-image]: https://travis-ci.org/RustCrypto/signatures.svg?branch=master
|
||||
[build-link]: https://travis-ci.org/RustCrypto/signatures
|
||||
|
||||
[//]: # (general links)
|
||||
|
||||
[digital signatures]: https://en.wikipedia.org/wiki/Digital_signature
|
||||
[ecdsa-crate]: https://github.com/RustCrypto/signatures/tree/master/ecdsa
|
||||
[ed25519-crate]: https://github.com/RustCrypto/signatures/tree/master/ed25519
|
||||
[1]: https://en.wikipedia.org/wiki/Digital_signature
|
||||
[2]: https://github.com/RustCrypto/signatures/tree/master/ed25519
|
||||
[3]: https://github.com/RustCrypto/signatures/tree/master/ecdsa
|
||||
[4]: https://github.com/RustCrypto/RSA
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
use core::fmt::{self, Display};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::{boxed::Box, error::Error as StdError};
|
||||
use std::boxed::Box;
|
||||
|
||||
/// Signature errors
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Error {
|
||||
/// Cause of the error (if applicable)
|
||||
#[cfg(feature = "std")]
|
||||
cause: Option<Box<dyn StdError>>,
|
||||
cause: Option<Box<dyn std::error::Error>>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -23,7 +23,7 @@ impl Error {
|
||||
#[cfg(feature = "std")]
|
||||
pub fn from_cause<E>(cause: E) -> Self
|
||||
where
|
||||
E: Into<Box<dyn StdError>>,
|
||||
E: Into<Box<dyn std::error::Error>>,
|
||||
{
|
||||
Self {
|
||||
cause: Some(cause.into()),
|
||||
@@ -32,7 +32,7 @@ impl Error {
|
||||
|
||||
/// Borrow the error's underlying cause (if available)
|
||||
#[cfg(feature = "std")]
|
||||
pub fn cause(&self) -> Option<&dyn StdError> {
|
||||
pub fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||
self.cause.as_ref().map(|c| c.as_ref())
|
||||
}
|
||||
|
||||
@@ -40,16 +40,16 @@ impl Error {
|
||||
///
|
||||
/// Panics if the error does not have a cause.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn into_cause(self) -> Box<dyn StdError> {
|
||||
pub fn into_cause(self) -> Box<dyn std::error::Error> {
|
||||
self.cause
|
||||
.expect("into_cause called on an error with no cause")
|
||||
}
|
||||
|
||||
/// Attempt to downcast this error's cause into a concrete type
|
||||
#[cfg(feature = "std")]
|
||||
pub fn downcast<T>(self) -> Result<Box<T>, Box<dyn StdError>>
|
||||
pub fn downcast<T>(self) -> Result<Box<T>, Box<dyn std::error::Error>>
|
||||
where
|
||||
T: StdError + 'static,
|
||||
T: std::error::Error + 'static,
|
||||
{
|
||||
self.cause
|
||||
.map(|cause| cause.downcast())
|
||||
@@ -60,33 +60,30 @@ impl Error {
|
||||
#[cfg(feature = "std")]
|
||||
pub fn downcast_ref<T>(&self) -> Option<&T>
|
||||
where
|
||||
T: StdError + 'static,
|
||||
T: std::error::Error + 'static,
|
||||
{
|
||||
self.cause.as_ref().and_then(|cause| cause.downcast_ref())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "signature error")
|
||||
}
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "signature error")?;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(ref cause) = self.cause {
|
||||
write!(f, "{}", cause)
|
||||
} else {
|
||||
write!(f, "signature error")
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
if let Some(ref cause) = self.cause {
|
||||
write!(f, ": {}", cause)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl StdError for Error {
|
||||
fn cause(&self) -> Option<&dyn StdError> {
|
||||
impl std::error::Error for Error {
|
||||
fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||
self.cause.as_ref().map(|cause| cause.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,11 @@
|
||||
//! cryptography.
|
||||
|
||||
#![no_std]
|
||||
#![deny(
|
||||
warnings,
|
||||
missing_docs,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unsafe_code,
|
||||
unused_import_braces,
|
||||
unused_qualifications
|
||||
)]
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
|
||||
#![doc(html_root_url = "https://docs.rs/signature/0.2.0")]
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
#[allow(unused_imports)] // rustc bug?
|
||||
#[macro_use]
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -36,7 +27,6 @@ pub use signature_derive::{Signer, Verifier};
|
||||
pub use digest;
|
||||
|
||||
mod error;
|
||||
mod prelude;
|
||||
mod signature;
|
||||
mod signer;
|
||||
mod verifier;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//! Crate-local prelude (for alloc-dependent features like `Vec`)
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
pub use alloc::vec::Vec;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::vec::Vec;
|
||||
@@ -2,7 +2,7 @@ use core::fmt::Debug;
|
||||
|
||||
use crate::error::Error;
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::prelude::*;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// Trait impl'd by concrete types that represent digital signatures
|
||||
pub trait Signature: AsRef<[u8]> + Debug + Sized {
|
||||
|
||||
Reference in New Issue
Block a user