support crypto primitives for no_std introducing full_crypto feature (#3778)

* introduced "with_crypto" feature and applied switches like in substrate-api-client fork

* introduced "with_crypto" feature and applied switches like in substraTEE-worker fork

* distinguishing core::hash vs std::hash

* @bkchr's review requests fulfilled

* fixes

* revert dependency upgrade ed25519-dalek

* added full_crypto features to all crates using app_crypto! macro

* fixing CI complaints.

* fix again

* adding CI test for with_crypto feature

* added full_crypto for ecdsa. now builds wit h--no-deafault-features --features with_crypto

* remove --release from CI test

* @bkchr requested changes. moved full_crypto CI test to build stage

* fixing no_std issue

* CI fresh copy from srml-staking

* gitlab CI with +nightly

* solved no-feature-in-macro dilemma

* cosmetics

* Update core/application-crypto/src/sr25519.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/application-crypto/src/ed25519.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* even more simple

* undo line delete

* refactoring app_crypto macro. splitting functionalities based on full_crypto feature

* whitespace cosmetics
This commit is contained in:
brenzi
2019-11-04 10:53:41 +01:00
committed by Bastian Köcher
parent 2e424f4d9f
commit ed5ac30a44
13 changed files with 352 additions and 151 deletions
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
#[cfg(feature = "std")]
#[cfg(feature = "full_crypto")]
use primitives::crypto::Pair;
use codec::Codec;
@@ -30,7 +30,7 @@ pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
type Public: AppPublic;
/// The corresponding key pair type in this application scheme.
#[cfg(feature="std")]
#[cfg(feature = "full_crypto")]
type Pair: AppPair;
/// The corresponding signature type in this application scheme.
@@ -42,16 +42,22 @@ pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
/// Type which implements Hash in std, not when no-std (std variant).
#[cfg(feature = "std")]
pub trait MaybeHash: std::hash::Hash {}
pub trait MaybeHash: rstd::hash::Hash {}
#[cfg(feature = "std")]
impl<T: std::hash::Hash> MaybeHash for T {}
impl<T: rstd::hash::Hash> MaybeHash for T {}
/// Type which implements Hash in std, not when no-std (no-std variant).
#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))]
pub trait MaybeHash {}
#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))]
impl<T> MaybeHash for T {}
/// Type which implements Debug and Hash in std, not when no-std (no-std variant with crypto).
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
pub trait MaybeDebugHash: rstd::hash::Hash {}
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
impl<T: rstd::hash::Hash> MaybeDebugHash for T {}
/// A application's public key.
pub trait AppPublic:
AppKey + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec
@@ -62,7 +68,7 @@ pub trait AppPublic:
}
/// A application's key pair.
#[cfg(feature = "std")]
#[cfg(feature = "full_crypto")]
pub trait AppPair: AppKey + Pair<Public=<Self as AppKey>::Public> {
/// The wrapped type which is just a plain instance of `Pair`.
type Generic: IsWrappedBy<Self> + Pair<Public=<<Self as AppKey>::Public as AppPublic>::Generic>;