mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 20:01:03 +00:00
Make keystore return None when a key doesn't exist (#8163)
* Make keystore return `None` when a key doesn't exist * Fixes * More fixes * Update comment * Update primitives/keystore/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/keystore/src/local.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Address comments * Update client/keystore/src/local.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -625,9 +625,7 @@ mod tests {
|
|||||||
sp_consensus_babe::AuthorityId::ID,
|
sp_consensus_babe::AuthorityId::ID,
|
||||||
&alice.to_public_crypto_pair(),
|
&alice.to_public_crypto_pair(),
|
||||||
&to_sign,
|
&to_sign,
|
||||||
).unwrap()
|
).unwrap().unwrap().try_into().unwrap();
|
||||||
.try_into()
|
|
||||||
.unwrap();
|
|
||||||
let item = <DigestItem as CompatibleDigestItem>::babe_seal(
|
let item = <DigestItem as CompatibleDigestItem>::babe_seal(
|
||||||
signature,
|
signature,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -296,10 +296,10 @@ where
|
|||||||
for (sign_result, key) in signatures.into_iter().zip(keys) {
|
for (sign_result, key) in signatures.into_iter().zip(keys) {
|
||||||
let mut signed_addresses = vec![];
|
let mut signed_addresses = vec![];
|
||||||
|
|
||||||
// sign_with_all returns Result<Signature, Error> signature
|
|
||||||
// is generated for a public key that is supported.
|
|
||||||
// Verify that all signatures exist for all provided keys.
|
// Verify that all signatures exist for all provided keys.
|
||||||
let signature = sign_result.map_err(|_| Error::MissingSignature(key.clone()))?;
|
let signature = sign_result.ok()
|
||||||
|
.flatten()
|
||||||
|
.ok_or_else(|| Error::MissingSignature(key.clone()))?;
|
||||||
schema::SignedAuthorityAddresses {
|
schema::SignedAuthorityAddresses {
|
||||||
addresses: serialized_addresses.clone(),
|
addresses: serialized_addresses.clone(),
|
||||||
signature,
|
signature,
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ async fn build_dht_event(
|
|||||||
serialized_addresses.as_slice(),
|
serialized_addresses.as_slice(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::Signing)
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut signed_addresses = vec![];
|
let mut signed_addresses = vec![];
|
||||||
@@ -195,9 +195,7 @@ async fn build_dht_event(
|
|||||||
addresses: serialized_addresses.clone(),
|
addresses: serialized_addresses.clone(),
|
||||||
signature,
|
signature,
|
||||||
}
|
}
|
||||||
.encode(&mut signed_addresses)
|
.encode(&mut signed_addresses).unwrap();
|
||||||
.map_err(Error::EncodingProto)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let key = hash_authority_id(&public_key.to_raw_vec());
|
let key = hash_authority_id(&public_key.to_raw_vec());
|
||||||
let value = signed_addresses;
|
let value = signed_addresses;
|
||||||
|
|||||||
@@ -255,8 +255,8 @@ where
|
|||||||
let expected_author = slot_author::<P>(slot, epoch_data);
|
let expected_author = slot_author::<P>(slot, epoch_data);
|
||||||
expected_author.and_then(|p| {
|
expected_author.and_then(|p| {
|
||||||
if SyncCryptoStore::has_keys(
|
if SyncCryptoStore::has_keys(
|
||||||
&*self.keystore,
|
&*self.keystore,
|
||||||
&[(p.to_raw_vec(), sp_application_crypto::key_types::AURA)],
|
&[(p.to_raw_vec(), sp_application_crypto::key_types::AURA)],
|
||||||
) {
|
) {
|
||||||
Some(p.clone())
|
Some(p.clone())
|
||||||
} else {
|
} else {
|
||||||
@@ -299,6 +299,9 @@ where
|
|||||||
header_hash.as_ref()
|
header_hash.as_ref()
|
||||||
).map_err(|e| sp_consensus::Error::CannotSign(
|
).map_err(|e| sp_consensus::Error::CannotSign(
|
||||||
public.clone(), e.to_string(),
|
public.clone(), e.to_string(),
|
||||||
|
))?
|
||||||
|
.ok_or_else(|| sp_consensus::Error::CannotSign(
|
||||||
|
public.clone(), "Could not find key in keystore.".into(),
|
||||||
))?;
|
))?;
|
||||||
let signature = signature.clone().try_into()
|
let signature = signature.clone().try_into()
|
||||||
.map_err(|_| sp_consensus::Error::InvalidSignature(
|
.map_err(|_| sp_consensus::Error::InvalidSignature(
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ fn claim_secondary_slot(
|
|||||||
authority_id.as_ref(),
|
authority_id.as_ref(),
|
||||||
transcript_data,
|
transcript_data,
|
||||||
);
|
);
|
||||||
if let Ok(signature) = result {
|
if let Ok(Some(signature)) = result {
|
||||||
Some(PreDigest::SecondaryVRF(SecondaryVRFPreDigest {
|
Some(PreDigest::SecondaryVRF(SecondaryVRFPreDigest {
|
||||||
slot,
|
slot,
|
||||||
vrf_output: VRFOutput(signature.output),
|
vrf_output: VRFOutput(signature.output),
|
||||||
@@ -265,7 +265,7 @@ fn claim_primary_slot(
|
|||||||
authority_id.as_ref(),
|
authority_id.as_ref(),
|
||||||
transcript_data,
|
transcript_data,
|
||||||
);
|
);
|
||||||
if let Ok(signature) = result {
|
if let Ok(Some(signature)) = result {
|
||||||
let public = PublicKey::from_bytes(&authority_id.to_raw_vec()).ok()?;
|
let public = PublicKey::from_bytes(&authority_id.to_raw_vec()).ok()?;
|
||||||
let inout = match signature.output.attach_input_hash(&public, transcript) {
|
let inout = match signature.output.attach_input_hash(&public, transcript) {
|
||||||
Ok(inout) => inout,
|
Ok(inout) => inout,
|
||||||
|
|||||||
@@ -649,6 +649,9 @@ where
|
|||||||
)
|
)
|
||||||
.map_err(|e| sp_consensus::Error::CannotSign(
|
.map_err(|e| sp_consensus::Error::CannotSign(
|
||||||
public.clone(), e.to_string(),
|
public.clone(), e.to_string(),
|
||||||
|
))?
|
||||||
|
.ok_or_else(|| sp_consensus::Error::CannotSign(
|
||||||
|
public.clone(), "Could not find key in keystore.".into(),
|
||||||
))?;
|
))?;
|
||||||
let signature: AuthoritySignature = signature.clone().try_into()
|
let signature: AuthoritySignature = signature.clone().try_into()
|
||||||
.map_err(|_| sp_consensus::Error::InvalidSignature(
|
.map_err(|_| sp_consensus::Error::InvalidSignature(
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ pub enum Error {
|
|||||||
/// Public key type is not supported
|
/// Public key type is not supported
|
||||||
#[display(fmt="Key crypto type is not supported")]
|
#[display(fmt="Key crypto type is not supported")]
|
||||||
KeyNotSupported(KeyTypeId),
|
KeyNotSupported(KeyTypeId),
|
||||||
/// Pair not found for public key and KeyTypeId
|
|
||||||
#[display(fmt="Pair not found for {} public key", "_0")]
|
|
||||||
PairNotFound(String),
|
|
||||||
/// Keystore unavailable
|
/// Keystore unavailable
|
||||||
#[display(fmt="Keystore unavailable")]
|
#[display(fmt="Keystore unavailable")]
|
||||||
Unavailable,
|
Unavailable,
|
||||||
@@ -61,7 +58,6 @@ impl From<Error> for TraitError {
|
|||||||
fn from(error: Error) -> Self {
|
fn from(error: Error) -> Self {
|
||||||
match error {
|
match error {
|
||||||
Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
|
Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
|
||||||
Error::PairNotFound(e) => TraitError::PairNotFound(e),
|
|
||||||
Error::InvalidSeed | Error::InvalidPhrase | Error::InvalidPassword => {
|
Error::InvalidSeed | Error::InvalidPhrase | Error::InvalidPassword => {
|
||||||
TraitError::ValidationError(error.to_string())
|
TraitError::ValidationError(error.to_string())
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ impl LocalKeystore {
|
|||||||
|
|
||||||
/// Get a key pair for the given public key.
|
/// Get a key pair for the given public key.
|
||||||
///
|
///
|
||||||
/// This function is only available for a local keystore. If your application plans to work with
|
/// Returns `Ok(None)` if the key doesn't exist, `Ok(Some(_))` if the key exists and
|
||||||
/// remote keystores, you do not want to depend on it.
|
/// `Err(_)` when something failed.
|
||||||
pub fn key_pair<Pair: AppPair>(&self, public: &<Pair as AppKey>::Public) -> Result<Pair> {
|
pub fn key_pair<Pair: AppPair>(&self, public: &<Pair as AppKey>::Public) -> Result<Option<Pair>> {
|
||||||
self.0.read().key_pair::<Pair>(public)
|
self.0.read().key_pair::<Pair>(public)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ impl CryptoStore for LocalKeystore {
|
|||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> std::result::Result<Vec<u8>, TraitError> {
|
) -> std::result::Result<Option<Vec<u8>>, TraitError> {
|
||||||
SyncCryptoStore::sign_with(self, id, key, msg)
|
SyncCryptoStore::sign_with(self, id, key, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ impl CryptoStore for LocalKeystore {
|
|||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &sr25519::Public,
|
public: &sr25519::Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> std::result::Result<VRFSignature, TraitError> {
|
) -> std::result::Result<Option<VRFSignature>, TraitError> {
|
||||||
SyncCryptoStore::sr25519_vrf_sign(self, key_type, public, transcript_data)
|
SyncCryptoStore::sr25519_vrf_sign(self, key_type, public, transcript_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,28 +175,28 @@ impl SyncCryptoStore for LocalKeystore {
|
|||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> std::result::Result<Vec<u8>, TraitError> {
|
) -> std::result::Result<Option<Vec<u8>>, TraitError> {
|
||||||
match key.0 {
|
match key.0 {
|
||||||
ed25519::CRYPTO_ID => {
|
ed25519::CRYPTO_ID => {
|
||||||
let pub_key = ed25519::Public::from_slice(key.1.as_slice());
|
let pub_key = ed25519::Public::from_slice(key.1.as_slice());
|
||||||
let key_pair: ed25519::Pair = self.0.read()
|
let key_pair = self.0.read()
|
||||||
.key_pair_by_type::<ed25519::Pair>(&pub_key, id)
|
.key_pair_by_type::<ed25519::Pair>(&pub_key, id)
|
||||||
.map_err(|e| TraitError::from(e))?;
|
.map_err(|e| TraitError::from(e))?;
|
||||||
Ok(key_pair.sign(msg).encode())
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
}
|
}
|
||||||
sr25519::CRYPTO_ID => {
|
sr25519::CRYPTO_ID => {
|
||||||
let pub_key = sr25519::Public::from_slice(key.1.as_slice());
|
let pub_key = sr25519::Public::from_slice(key.1.as_slice());
|
||||||
let key_pair: sr25519::Pair = self.0.read()
|
let key_pair = self.0.read()
|
||||||
.key_pair_by_type::<sr25519::Pair>(&pub_key, id)
|
.key_pair_by_type::<sr25519::Pair>(&pub_key, id)
|
||||||
.map_err(|e| TraitError::from(e))?;
|
.map_err(|e| TraitError::from(e))?;
|
||||||
Ok(key_pair.sign(msg).encode())
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
},
|
},
|
||||||
ecdsa::CRYPTO_ID => {
|
ecdsa::CRYPTO_ID => {
|
||||||
let pub_key = ecdsa::Public::from_slice(key.1.as_slice());
|
let pub_key = ecdsa::Public::from_slice(key.1.as_slice());
|
||||||
let key_pair: ecdsa::Pair = self.0.read()
|
let key_pair = self.0.read()
|
||||||
.key_pair_by_type::<ecdsa::Pair>(&pub_key, id)
|
.key_pair_by_type::<ecdsa::Pair>(&pub_key, id)
|
||||||
.map_err(|e| TraitError::from(e))?;
|
.map_err(|e| TraitError::from(e))?;
|
||||||
Ok(key_pair.sign(msg).encode())
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
}
|
}
|
||||||
_ => Err(TraitError::KeyNotSupported(id))
|
_ => Err(TraitError::KeyNotSupported(id))
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ impl SyncCryptoStore for LocalKeystore {
|
|||||||
.map(|k| ed25519::Public::from_slice(k.as_slice()))
|
.map(|k| ed25519::Public::from_slice(k.as_slice()))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ed25519_generate_new(
|
fn ed25519_generate_new(
|
||||||
@@ -278,7 +278,8 @@ impl SyncCryptoStore for LocalKeystore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool {
|
fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool {
|
||||||
public_keys.iter().all(|(p, t)| self.0.read().key_phrase_by_type(&p, *t).is_ok())
|
public_keys.iter()
|
||||||
|
.all(|(p, t)| self.0.read().key_phrase_by_type(&p, *t).ok().flatten().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sr25519_vrf_sign(
|
fn sr25519_vrf_sign(
|
||||||
@@ -286,16 +287,19 @@ impl SyncCryptoStore for LocalKeystore {
|
|||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &Sr25519Public,
|
public: &Sr25519Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> std::result::Result<VRFSignature, TraitError> {
|
) -> std::result::Result<Option<VRFSignature>, TraitError> {
|
||||||
let transcript = make_transcript(transcript_data);
|
let transcript = make_transcript(transcript_data);
|
||||||
let pair = self.0.read().key_pair_by_type::<Sr25519Pair>(public, key_type)
|
let pair = self.0.read().key_pair_by_type::<Sr25519Pair>(public, key_type)?;
|
||||||
.map_err(|e| TraitError::PairNotFound(e.to_string()))?;
|
|
||||||
|
|
||||||
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
|
if let Some(pair) = pair {
|
||||||
Ok(VRFSignature {
|
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
|
||||||
output: inout.to_output(),
|
Ok(Some(VRFSignature {
|
||||||
proof,
|
output: inout.to_output(),
|
||||||
})
|
proof,
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,36 +415,53 @@ impl KeystoreInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the key phrase for a given public key and key type.
|
/// Get the key phrase for a given public key and key type.
|
||||||
fn key_phrase_by_type(&self, public: &[u8], key_type: KeyTypeId) -> Result<String> {
|
fn key_phrase_by_type(&self, public: &[u8], key_type: KeyTypeId) -> Result<Option<String>> {
|
||||||
if let Some(phrase) = self.get_additional_pair(public, key_type) {
|
if let Some(phrase) = self.get_additional_pair(public, key_type) {
|
||||||
return Ok(phrase.clone())
|
return Ok(Some(phrase.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = self.key_file_path(public, key_type).ok_or_else(|| Error::Unavailable)?;
|
let path = if let Some(path) = self.key_file_path(public, key_type) {
|
||||||
let file = File::open(path)?;
|
path
|
||||||
|
} else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
|
||||||
serde_json::from_reader(&file).map_err(Into::into)
|
if path.exists() {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
|
||||||
|
serde_json::from_reader(&file).map_err(Into::into).map(Some)
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a key pair for the given public key and key type.
|
/// Get a key pair for the given public key and key type.
|
||||||
fn key_pair_by_type<Pair: PairT>(&self,
|
fn key_pair_by_type<Pair: PairT>(
|
||||||
|
&self,
|
||||||
public: &Pair::Public,
|
public: &Pair::Public,
|
||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
) -> Result<Pair> {
|
) -> Result<Option<Pair>> {
|
||||||
let phrase = self.key_phrase_by_type(public.as_slice(), key_type)?;
|
let phrase = if let Some(p) = self.key_phrase_by_type(public.as_slice(), key_type)? {
|
||||||
|
p
|
||||||
|
} else {
|
||||||
|
return Ok(None)
|
||||||
|
};
|
||||||
|
|
||||||
let pair = Pair::from_string(
|
let pair = Pair::from_string(
|
||||||
&phrase,
|
&phrase,
|
||||||
self.password(),
|
self.password(),
|
||||||
).map_err(|_| Error::InvalidPhrase)?;
|
).map_err(|_| Error::InvalidPhrase)?;
|
||||||
|
|
||||||
if &pair.public() == public {
|
if &pair.public() == public {
|
||||||
Ok(pair)
|
Ok(Some(pair))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::InvalidPassword)
|
Err(Error::InvalidPassword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file path for the given public key and key type.
|
/// Get the file path for the given public key and key type.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the keystore only exists in-memory and there isn't any path to provide.
|
||||||
fn key_file_path(&self, public: &[u8], key_type: KeyTypeId) -> Option<PathBuf> {
|
fn key_file_path(&self, public: &[u8], key_type: KeyTypeId) -> Option<PathBuf> {
|
||||||
let mut buf = self.path.as_ref()?.clone();
|
let mut buf = self.path.as_ref()?.clone();
|
||||||
let key_type = hex::encode(key_type.0);
|
let key_type = hex::encode(key_type.0);
|
||||||
@@ -481,8 +502,12 @@ impl KeystoreInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a key pair for the given public key.
|
/// Get a key pair for the given public key.
|
||||||
pub fn key_pair<Pair: AppPair>(&self, public: &<Pair as AppKey>::Public) -> Result<Pair> {
|
///
|
||||||
self.key_pair_by_type::<Pair::Generic>(IsWrappedBy::from_ref(public), Pair::ID).map(Into::into)
|
/// Returns `Ok(None)` if the key doesn't exist, `Ok(Some(_))` if the key exists or `Err(_)` when
|
||||||
|
/// something failed.
|
||||||
|
pub fn key_pair<Pair: AppPair>(&self, public: &<Pair as AppKey>::Public) -> Result<Option<Pair>> {
|
||||||
|
self.key_pair_by_type::<Pair::Generic>(IsWrappedBy::from_ref(public), Pair::ID)
|
||||||
|
.map(|v| v.map(Into::into))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,13 +556,40 @@ mod tests {
|
|||||||
assert!(store.public_keys::<ed25519::AppPublic>().unwrap().is_empty());
|
assert!(store.public_keys::<ed25519::AppPublic>().unwrap().is_empty());
|
||||||
|
|
||||||
let key: ed25519::AppPair = store.generate().unwrap();
|
let key: ed25519::AppPair = store.generate().unwrap();
|
||||||
let key2: ed25519::AppPair = store.key_pair(&key.public()).unwrap();
|
let key2: ed25519::AppPair = store.key_pair(&key.public()).unwrap().unwrap();
|
||||||
|
|
||||||
assert_eq!(key.public(), key2.public());
|
assert_eq!(key.public(), key2.public());
|
||||||
|
|
||||||
assert_eq!(store.public_keys::<ed25519::AppPublic>().unwrap()[0], key.public());
|
assert_eq!(store.public_keys::<ed25519::AppPublic>().unwrap()[0], key.public());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has_keys_works() {
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
let store = LocalKeystore::open(temp_dir.path(), None).unwrap();
|
||||||
|
|
||||||
|
let key: ed25519::AppPair = store.0.write().generate().unwrap();
|
||||||
|
let key2 = ed25519::Pair::generate().0;
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!SyncCryptoStore::has_keys(&store, &[(key2.public().to_vec(), ed25519::AppPublic::ID)])
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!SyncCryptoStore::has_keys(
|
||||||
|
&store,
|
||||||
|
&[
|
||||||
|
(key2.public().to_vec(), ed25519::AppPublic::ID),
|
||||||
|
(key.public().to_raw_vec(), ed25519::AppPublic::ID),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
SyncCryptoStore::has_keys(&store, &[(key.public().to_raw_vec(), ed25519::AppPublic::ID)])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_insert_ephemeral_from_seed() {
|
fn test_insert_ephemeral_from_seed() {
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
@@ -554,7 +606,7 @@ mod tests {
|
|||||||
drop(store);
|
drop(store);
|
||||||
let store = KeystoreInner::open(temp_dir.path(), None).unwrap();
|
let store = KeystoreInner::open(temp_dir.path(), None).unwrap();
|
||||||
// Keys generated from seed should not be persisted!
|
// Keys generated from seed should not be persisted!
|
||||||
assert!(store.key_pair::<ed25519::AppPair>(&pair.public()).is_err());
|
assert!(store.key_pair::<ed25519::AppPair>(&pair.public()).unwrap().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -569,7 +621,7 @@ mod tests {
|
|||||||
let pair: ed25519::AppPair = store.generate().unwrap();
|
let pair: ed25519::AppPair = store.generate().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pair.public(),
|
pair.public(),
|
||||||
store.key_pair::<ed25519::AppPair>(&pair.public()).unwrap().public(),
|
store.key_pair::<ed25519::AppPair>(&pair.public()).unwrap().unwrap().public(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Without the password the key should not be retrievable
|
// Without the password the key should not be retrievable
|
||||||
@@ -582,7 +634,7 @@ mod tests {
|
|||||||
).unwrap();
|
).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pair.public(),
|
pair.public(),
|
||||||
store.key_pair::<ed25519::AppPair>(&pair.public()).unwrap().public(),
|
store.key_pair::<ed25519::AppPair>(&pair.public()).unwrap().unwrap().public(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +678,7 @@ mod tests {
|
|||||||
let store_key_pair = store.key_pair_by_type::<sr25519::AppPair>(
|
let store_key_pair = store.key_pair_by_type::<sr25519::AppPair>(
|
||||||
&key_pair.public(),
|
&key_pair.public(),
|
||||||
SR25519,
|
SR25519,
|
||||||
).expect("Gets key pair from keystore");
|
).expect("Gets key pair from keystore").unwrap();
|
||||||
|
|
||||||
assert_eq!(key_pair.public(), store_key_pair.public());
|
assert_eq!(key_pair.public(), store_key_pair.public());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ where
|
|||||||
AuthorityId::ID,
|
AuthorityId::ID,
|
||||||
&public.to_public_crypto_pair(),
|
&public.to_public_crypto_pair(),
|
||||||
&encoded[..],
|
&encoded[..],
|
||||||
).ok()?.try_into().ok()?;
|
).ok().flatten()?.try_into().ok()?;
|
||||||
|
|
||||||
Some(grandpa::SignedMessage {
|
Some(grandpa::SignedMessage {
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -474,8 +474,9 @@ pub trait Crypto {
|
|||||||
let keystore = &***self.extension::<KeystoreExt>()
|
let keystore = &***self.extension::<KeystoreExt>()
|
||||||
.expect("No `keystore` associated for the current context!");
|
.expect("No `keystore` associated for the current context!");
|
||||||
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
||||||
.map(|sig| ed25519::Signature::from_slice(sig.as_slice()))
|
|
||||||
.ok()
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.map(|sig| ed25519::Signature::from_slice(sig.as_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify `ed25519` signature.
|
/// Verify `ed25519` signature.
|
||||||
@@ -600,8 +601,9 @@ pub trait Crypto {
|
|||||||
let keystore = &***self.extension::<KeystoreExt>()
|
let keystore = &***self.extension::<KeystoreExt>()
|
||||||
.expect("No `keystore` associated for the current context!");
|
.expect("No `keystore` associated for the current context!");
|
||||||
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
||||||
.map(|sig| sr25519::Signature::from_slice(sig.as_slice()))
|
|
||||||
.ok()
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.map(|sig| sr25519::Signature::from_slice(sig.as_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify an `sr25519` signature.
|
/// Verify an `sr25519` signature.
|
||||||
@@ -646,8 +648,9 @@ pub trait Crypto {
|
|||||||
let keystore = &***self.extension::<KeystoreExt>()
|
let keystore = &***self.extension::<KeystoreExt>()
|
||||||
.expect("No `keystore` associated for the current context!");
|
.expect("No `keystore` associated for the current context!");
|
||||||
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
SyncCryptoStore::sign_with(keystore, id, &pub_key.into(), msg)
|
||||||
.map(|sig| ecdsa::Signature::from_slice(sig.as_slice()))
|
|
||||||
.ok()
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.map(|sig| ecdsa::Signature::from_slice(sig.as_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify `ecdsa` signature.
|
/// Verify `ecdsa` signature.
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ pub enum Error {
|
|||||||
/// Public key type is not supported
|
/// Public key type is not supported
|
||||||
#[display(fmt="Key not supported: {:?}", _0)]
|
#[display(fmt="Key not supported: {:?}", _0)]
|
||||||
KeyNotSupported(KeyTypeId),
|
KeyNotSupported(KeyTypeId),
|
||||||
/// Pair not found for public key and KeyTypeId
|
|
||||||
#[display(fmt="Pair was not found: {}", _0)]
|
|
||||||
PairNotFound(String),
|
|
||||||
/// Validation error
|
/// Validation error
|
||||||
#[display(fmt="Validation error: {}", _0)]
|
#[display(fmt="Validation error: {}", _0)]
|
||||||
ValidationError(String),
|
ValidationError(String),
|
||||||
@@ -125,37 +122,39 @@ pub trait CryptoStore: Send + Sync {
|
|||||||
/// Signs a message with the private key that matches
|
/// Signs a message with the private key that matches
|
||||||
/// the public key passed.
|
/// the public key passed.
|
||||||
///
|
///
|
||||||
/// Returns the SCALE encoded signature if key is found & supported,
|
/// Returns the SCALE encoded signature if key is found and supported, `None` if the key doesn't
|
||||||
/// an error otherwise.
|
/// exist or an error when something failed.
|
||||||
async fn sign_with(
|
async fn sign_with(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<u8>, Error>;
|
) -> Result<Option<Vec<u8>>, Error>;
|
||||||
|
|
||||||
/// Sign with any key
|
/// Sign with any key
|
||||||
///
|
///
|
||||||
/// Given a list of public keys, find the first supported key and
|
/// Given a list of public keys, find the first supported key and
|
||||||
/// sign the provided message with that key.
|
/// sign the provided message with that key.
|
||||||
///
|
///
|
||||||
/// Returns a tuple of the used key and the SCALE encoded signature.
|
/// Returns a tuple of the used key and the SCALE encoded signature or `None` if no key could
|
||||||
|
/// be found to sign.
|
||||||
async fn sign_with_any(
|
async fn sign_with_any(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
keys: Vec<CryptoTypePublicPair>,
|
keys: Vec<CryptoTypePublicPair>,
|
||||||
msg: &[u8]
|
msg: &[u8]
|
||||||
) -> Result<(CryptoTypePublicPair, Vec<u8>), Error> {
|
) -> Result<Option<(CryptoTypePublicPair, Vec<u8>)>, Error> {
|
||||||
if keys.len() == 1 {
|
if keys.len() == 1 {
|
||||||
return self.sign_with(id, &keys[0], msg).await.map(|s| (keys[0].clone(), s));
|
return Ok(self.sign_with(id, &keys[0], msg).await?.map(|s| (keys[0].clone(), s)));
|
||||||
} else {
|
} else {
|
||||||
for k in self.supported_keys(id, keys).await? {
|
for k in self.supported_keys(id, keys).await? {
|
||||||
if let Ok(sign) = self.sign_with(id, &k, msg).await {
|
if let Ok(Some(sign)) = self.sign_with(id, &k, msg).await {
|
||||||
return Ok((k, sign));
|
return Ok(Some((k, sign)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Error::KeyNotSupported(id))
|
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign with all keys
|
/// Sign with all keys
|
||||||
@@ -164,13 +163,13 @@ pub trait CryptoStore: Send + Sync {
|
|||||||
/// each key given that the key is supported.
|
/// each key given that the key is supported.
|
||||||
///
|
///
|
||||||
/// Returns a list of `Result`s each representing the SCALE encoded
|
/// Returns a list of `Result`s each representing the SCALE encoded
|
||||||
/// signature of each key or a Error for non-supported keys.
|
/// signature of each key, `None` if the key doesn't exist or a error when something failed.
|
||||||
async fn sign_with_all(
|
async fn sign_with_all(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
keys: Vec<CryptoTypePublicPair>,
|
keys: Vec<CryptoTypePublicPair>,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<Result<Vec<u8>, Error>>, ()> {
|
) -> Result<Vec<Result<Option<Vec<u8>>, Error>>, ()> {
|
||||||
let futs = keys.iter()
|
let futs = keys.iter()
|
||||||
.map(|k| self.sign_with(id, k, msg));
|
.map(|k| self.sign_with(id, k, msg));
|
||||||
|
|
||||||
@@ -187,16 +186,14 @@ pub trait CryptoStore: Send + Sync {
|
|||||||
/// Namely, VRFOutput and VRFProof which are returned
|
/// Namely, VRFOutput and VRFProof which are returned
|
||||||
/// inside the `VRFSignature` container struct.
|
/// inside the `VRFSignature` container struct.
|
||||||
///
|
///
|
||||||
/// This function will return an error in the cases where
|
/// This function will return `None` if the given `key_type` and `public` combination
|
||||||
/// the public key and key type provided do not match a private
|
/// doesn't exist in the keystore or an `Err` when something failed.
|
||||||
/// key in the keystore. Or, in the context of remote signing
|
|
||||||
/// an error could be a network one.
|
|
||||||
async fn sr25519_vrf_sign(
|
async fn sr25519_vrf_sign(
|
||||||
&self,
|
&self,
|
||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &sr25519::Public,
|
public: &sr25519::Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> Result<VRFSignature, Error>;
|
) -> Result<Option<VRFSignature>, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sync version of the CryptoStore
|
/// Sync version of the CryptoStore
|
||||||
@@ -285,37 +282,41 @@ pub trait SyncCryptoStore: CryptoStore + Send + Sync {
|
|||||||
/// Signs a message with the private key that matches
|
/// Signs a message with the private key that matches
|
||||||
/// the public key passed.
|
/// the public key passed.
|
||||||
///
|
///
|
||||||
/// Returns the SCALE encoded signature if key is found & supported,
|
/// Returns the SCALE encoded signature if key is found and supported, `None` if the key doesn't
|
||||||
/// an error otherwise.
|
/// exist or an error when something failed.
|
||||||
fn sign_with(
|
fn sign_with(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<u8>, Error>;
|
) -> Result<Option<Vec<u8>>, Error>;
|
||||||
|
|
||||||
/// Sign with any key
|
/// Sign with any key
|
||||||
///
|
///
|
||||||
/// Given a list of public keys, find the first supported key and
|
/// Given a list of public keys, find the first supported key and
|
||||||
/// sign the provided message with that key.
|
/// sign the provided message with that key.
|
||||||
///
|
///
|
||||||
/// Returns a tuple of the used key and the SCALE encoded signature.
|
/// Returns a tuple of the used key and the SCALE encoded signature or `None` if no key could
|
||||||
|
/// be found to sign.
|
||||||
fn sign_with_any(
|
fn sign_with_any(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
keys: Vec<CryptoTypePublicPair>,
|
keys: Vec<CryptoTypePublicPair>,
|
||||||
msg: &[u8]
|
msg: &[u8]
|
||||||
) -> Result<(CryptoTypePublicPair, Vec<u8>), Error> {
|
) -> Result<Option<(CryptoTypePublicPair, Vec<u8>)>, Error> {
|
||||||
if keys.len() == 1 {
|
if keys.len() == 1 {
|
||||||
return SyncCryptoStore::sign_with(self, id, &keys[0], msg).map(|s| (keys[0].clone(), s));
|
return Ok(
|
||||||
|
SyncCryptoStore::sign_with(self, id, &keys[0], msg)?.map(|s| (keys[0].clone(), s)),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
for k in SyncCryptoStore::supported_keys(self, id, keys)? {
|
for k in SyncCryptoStore::supported_keys(self, id, keys)? {
|
||||||
if let Ok(sign) = SyncCryptoStore::sign_with(self, id, &k, msg) {
|
if let Ok(Some(sign)) = SyncCryptoStore::sign_with(self, id, &k, msg) {
|
||||||
return Ok((k, sign));
|
return Ok(Some((k, sign)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Error::KeyNotSupported(id))
|
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign with all keys
|
/// Sign with all keys
|
||||||
@@ -324,13 +325,13 @@ pub trait SyncCryptoStore: CryptoStore + Send + Sync {
|
|||||||
/// each key given that the key is supported.
|
/// each key given that the key is supported.
|
||||||
///
|
///
|
||||||
/// Returns a list of `Result`s each representing the SCALE encoded
|
/// Returns a list of `Result`s each representing the SCALE encoded
|
||||||
/// signature of each key or a Error for non-supported keys.
|
/// signature of each key, `None` if the key doesn't exist or an error when something failed.
|
||||||
fn sign_with_all(
|
fn sign_with_all(
|
||||||
&self,
|
&self,
|
||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
keys: Vec<CryptoTypePublicPair>,
|
keys: Vec<CryptoTypePublicPair>,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<Result<Vec<u8>, Error>>, ()>{
|
) -> Result<Vec<Result<Option<Vec<u8>>, Error>>, ()> {
|
||||||
Ok(keys.iter().map(|k| SyncCryptoStore::sign_with(self, id, k, msg)).collect())
|
Ok(keys.iter().map(|k| SyncCryptoStore::sign_with(self, id, k, msg)).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,16 +345,14 @@ pub trait SyncCryptoStore: CryptoStore + Send + Sync {
|
|||||||
/// Namely, VRFOutput and VRFProof which are returned
|
/// Namely, VRFOutput and VRFProof which are returned
|
||||||
/// inside the `VRFSignature` container struct.
|
/// inside the `VRFSignature` container struct.
|
||||||
///
|
///
|
||||||
/// This function will return an error in the cases where
|
/// This function will return `None` if the given `key_type` and `public` combination
|
||||||
/// the public key and key type provided do not match a private
|
/// doesn't exist in the keystore or an `Err` when something failed.
|
||||||
/// key in the keystore. Or, in the context of remote signing
|
|
||||||
/// an error could be a network one.
|
|
||||||
fn sr25519_vrf_sign(
|
fn sr25519_vrf_sign(
|
||||||
&self,
|
&self,
|
||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &sr25519::Public,
|
public: &sr25519::Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> Result<VRFSignature, Error>;
|
) -> Result<Option<VRFSignature>, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A pointer to a keystore.
|
/// A pointer to a keystore.
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ impl CryptoStore for KeyStore {
|
|||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<u8>, Error> {
|
) -> Result<Option<Vec<u8>>, Error> {
|
||||||
SyncCryptoStore::sign_with(self, id, key, msg)
|
SyncCryptoStore::sign_with(self, id, key, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ impl CryptoStore for KeyStore {
|
|||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &sr25519::Public,
|
public: &sr25519::Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> Result<VRFSignature, Error> {
|
) -> Result<Option<VRFSignature>, Error> {
|
||||||
SyncCryptoStore::sr25519_vrf_sign(self, key_type, public, transcript_data)
|
SyncCryptoStore::sr25519_vrf_sign(self, key_type, public, transcript_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,27 +280,27 @@ impl SyncCryptoStore for KeyStore {
|
|||||||
id: KeyTypeId,
|
id: KeyTypeId,
|
||||||
key: &CryptoTypePublicPair,
|
key: &CryptoTypePublicPair,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
) -> Result<Vec<u8>, Error> {
|
) -> Result<Option<Vec<u8>>, Error> {
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
|
|
||||||
match key.0 {
|
match key.0 {
|
||||||
ed25519::CRYPTO_ID => {
|
ed25519::CRYPTO_ID => {
|
||||||
let key_pair: ed25519::Pair = self
|
let key_pair = self
|
||||||
.ed25519_key_pair(id, &ed25519::Public::from_slice(key.1.as_slice()))
|
.ed25519_key_pair(id, &ed25519::Public::from_slice(key.1.as_slice()));
|
||||||
.ok_or_else(|| Error::PairNotFound("ed25519".to_owned()))?;
|
|
||||||
return Ok(key_pair.sign(msg).encode());
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
}
|
}
|
||||||
sr25519::CRYPTO_ID => {
|
sr25519::CRYPTO_ID => {
|
||||||
let key_pair: sr25519::Pair = self
|
let key_pair = self
|
||||||
.sr25519_key_pair(id, &sr25519::Public::from_slice(key.1.as_slice()))
|
.sr25519_key_pair(id, &sr25519::Public::from_slice(key.1.as_slice()));
|
||||||
.ok_or_else(|| Error::PairNotFound("sr25519".to_owned()))?;
|
|
||||||
return Ok(key_pair.sign(msg).encode());
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
}
|
}
|
||||||
ecdsa::CRYPTO_ID => {
|
ecdsa::CRYPTO_ID => {
|
||||||
let key_pair: ecdsa::Pair = self
|
let key_pair = self
|
||||||
.ecdsa_key_pair(id, &ecdsa::Public::from_slice(key.1.as_slice()))
|
.ecdsa_key_pair(id, &ecdsa::Public::from_slice(key.1.as_slice()));
|
||||||
.ok_or_else(|| Error::PairNotFound("ecdsa".to_owned()))?;
|
|
||||||
return Ok(key_pair.sign(msg).encode());
|
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
|
||||||
}
|
}
|
||||||
_ => Err(Error::KeyNotSupported(id))
|
_ => Err(Error::KeyNotSupported(id))
|
||||||
}
|
}
|
||||||
@@ -311,15 +311,19 @@ impl SyncCryptoStore for KeyStore {
|
|||||||
key_type: KeyTypeId,
|
key_type: KeyTypeId,
|
||||||
public: &sr25519::Public,
|
public: &sr25519::Public,
|
||||||
transcript_data: VRFTranscriptData,
|
transcript_data: VRFTranscriptData,
|
||||||
) -> Result<VRFSignature, Error> {
|
) -> Result<Option<VRFSignature>, Error> {
|
||||||
let transcript = make_transcript(transcript_data);
|
let transcript = make_transcript(transcript_data);
|
||||||
let pair = self.sr25519_key_pair(key_type, public)
|
let pair = if let Some(k) = self.sr25519_key_pair(key_type, public) {
|
||||||
.ok_or_else(|| Error::PairNotFound("Not found".to_owned()))?;
|
k
|
||||||
|
} else {
|
||||||
|
return Ok(None)
|
||||||
|
};
|
||||||
|
|
||||||
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
|
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
|
||||||
Ok(VRFSignature {
|
Ok(Some(VRFSignature {
|
||||||
output: inout.to_output(),
|
output: inout.to_output(),
|
||||||
proof,
|
proof,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +398,7 @@ mod tests {
|
|||||||
&key_pair.public(),
|
&key_pair.public(),
|
||||||
transcript_data.clone(),
|
transcript_data.clone(),
|
||||||
);
|
);
|
||||||
assert!(result.is_err());
|
assert!(result.unwrap().is_none());
|
||||||
|
|
||||||
SyncCryptoStore::insert_unknown(
|
SyncCryptoStore::insert_unknown(
|
||||||
&store,
|
&store,
|
||||||
@@ -410,6 +414,6 @@ mod tests {
|
|||||||
transcript_data,
|
transcript_data,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(result.is_ok());
|
assert!(result.unwrap().is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user