Thread 'async' through any protocol APIs that take Stores

In preparation for Desktop, which must asynchronously access its
database (rather than putting the entire operation on a background
thread with synchronization at the database layer).

The FFI and JNI wrappers (as well as the tests) use
futures::executor::block_on to turn the operations back into
synchronous ones.
This commit is contained in:
Jordan Rose
2020-11-03 14:32:27 -08:00
parent 75eb8df2ed
commit 90a9f76dc6
13 changed files with 1783 additions and 1699 deletions

View File

@@ -15,7 +15,7 @@ pub fn test_in_memory_protocol_store() -> InMemSignalProtocolStore {
}
#[allow(dead_code)]
pub fn encrypt(
pub async fn encrypt(
store: &mut InMemSignalProtocolStore,
remote_address: &ProtocolAddress,
msg: &str,
@@ -26,11 +26,11 @@ pub fn encrypt(
&mut store.session_store,
&mut store.identity_store,
None,
)
).await
}
#[allow(dead_code)]
pub fn decrypt(
pub async fn decrypt(
store: &mut InMemSignalProtocolStore,
remote_address: &ProtocolAddress,
msg: &CiphertextMessage,
@@ -45,11 +45,11 @@ pub fn decrypt(
&mut store.signed_pre_key_store,
&mut csprng,
None,
)
).await
}
#[allow(dead_code)]
pub fn create_pre_key_bundle<R: Rng + CryptoRng>(
pub async fn create_pre_key_bundle<R: Rng + CryptoRng>(
store: &mut dyn ProtocolStore,
mut csprng: &mut R,
) -> Result<PreKeyBundle, SignalProtocolError> {
@@ -58,7 +58,7 @@ pub fn create_pre_key_bundle<R: Rng + CryptoRng>(
let signed_pre_key_public = signed_pre_key_pair.public_key.serialize();
let signed_pre_key_signature = store
.get_identity_key_pair(None)?
.get_identity_key_pair(None).await?
.private_key()
.calculate_signature(&signed_pre_key_public, &mut csprng)?;
@@ -67,21 +67,21 @@ pub fn create_pre_key_bundle<R: Rng + CryptoRng>(
let signed_pre_key_id: u32 = csprng.gen();
let pre_key_bundle = PreKeyBundle::new(
store.get_local_registration_id(None)?,
store.get_local_registration_id(None).await?,
device_id,
Some(pre_key_id),
Some(pre_key_pair.public_key),
signed_pre_key_id,
signed_pre_key_pair.public_key,
signed_pre_key_signature.to_vec(),
*store.get_identity_key_pair(None)?.identity_key(),
*store.get_identity_key_pair(None).await?.identity_key(),
)?;
store.save_pre_key(
pre_key_id,
&PreKeyRecord::new(pre_key_id, &pre_key_pair),
None,
)?;
).await?;
let timestamp = csprng.gen();
@@ -94,7 +94,7 @@ pub fn create_pre_key_bundle<R: Rng + CryptoRng>(
&signed_pre_key_signature,
),
None,
)?;
).await?;
Ok(pre_key_bundle)
}