Convert Public to CryptoTypePublicPair (#6014)

* Tabify code

* Implement CryptoTypePublicPair in app_crypto

* Cleanup redundancy

* Introduce to_public_crypto_pair to Public trait

* Implement method for test
This commit is contained in:
Rakan Alhneiti
2020-05-13 19:44:54 +02:00
committed by GitHub
parent daf8cf0600
commit 6bdfae2bcb
8 changed files with 52 additions and 50 deletions
+12
View File
@@ -559,6 +559,8 @@ pub trait Public:
/// Return a slice filled with raw data.
fn as_slice(&self) -> &[u8] { self.as_ref() }
/// Return `CryptoTypePublicPair` from public key.
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair;
}
/// An opaque 32-byte cryptographic identifier.
@@ -706,6 +708,11 @@ mod dummy {
#[cfg(feature = "std")]
fn to_raw_vec(&self) -> Vec<u8> { vec![] }
fn as_slice(&self) -> &[u8] { b"" }
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair {
CryptoTypePublicPair(
CryptoTypeId(*b"dumm"), Public::to_raw_vec(self)
)
}
}
impl Pair for Dummy {
@@ -1061,6 +1068,11 @@ mod tests {
fn to_raw_vec(&self) -> Vec<u8> {
vec![]
}
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair {
CryptoTypePublicPair(
CryptoTypeId(*b"dumm"), self.to_raw_vec(),
)
}
}
impl Pair for TestPair {
type Public = TestPublic;