mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 10:41:09 +00:00
Restrict Protected to some heap types. (#6471)
* Restrict `Protected` to some heap types. * Comment abut Protected usage. * Remove Protected from crypto, use secrecy crate for existing uses. * use a parse function * fix error convert * Rename and move secretY string function. * std result
This commit is contained in:
@@ -37,10 +37,16 @@ use regex::Regex;
|
||||
use base58::{FromBase58, ToBase58};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::hexdisplay::HexDisplay;
|
||||
use zeroize::Zeroize;
|
||||
#[doc(hidden)]
|
||||
pub use sp_std::ops::Deref;
|
||||
use sp_runtime_interface::pass_by::PassByInner;
|
||||
/// Trait to zeroize a memory buffer.
|
||||
pub use zeroize::Zeroize;
|
||||
/// Trait for accessing reference to `SecretString`.
|
||||
pub use secrecy::ExposeSecret;
|
||||
/// A store for sensitive data.
|
||||
#[cfg(feature = "std")]
|
||||
pub use secrecy::SecretString;
|
||||
|
||||
/// The root phrase for our publicly known keys.
|
||||
pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
||||
@@ -79,51 +85,6 @@ impl<S, T: UncheckedFrom<S>> UncheckedInto<T> for S {
|
||||
}
|
||||
}
|
||||
|
||||
/// A store for sensitive data.
|
||||
///
|
||||
/// Calls `Zeroize::zeroize` upon `Drop`.
|
||||
#[derive(Clone)]
|
||||
pub struct Protected<T: Zeroize>(T);
|
||||
|
||||
impl<T: Zeroize> AsRef<T> for Protected<T> {
|
||||
fn as_ref(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Zeroize> sp_std::ops::Deref for Protected<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Zeroize> std::fmt::Debug for Protected<T> {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(fmt, "<protected>")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Zeroize> From<T> for Protected<T> {
|
||||
fn from(t: T) -> Self {
|
||||
Protected(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Zeroize> Zeroize for Protected<T> {
|
||||
fn zeroize(&mut self) {
|
||||
self.0.zeroize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Zeroize> Drop for Protected<T> {
|
||||
fn drop(&mut self) {
|
||||
self.zeroize()
|
||||
}
|
||||
}
|
||||
|
||||
/// An error with the interpretation of a secret.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg(feature = "full_crypto")]
|
||||
|
||||
Reference in New Issue
Block a user