(feat): add max message size to wasm
Some checks failed
CI / rustfmt (push) Successful in 17s
CI / wasm build (push) Successful in 1m15s
CI / clippy (push) Successful in 1m30s
CI / test (push) Successful in 1m48s
CI / example (push) Successful in 1m32s
CI / duplicate code (push) Failing after 29s
CI / web client (push) Failing after 30s
CI / cargo-machete (push) Successful in 1m7s
CI / cargo-deny (push) Failing after 2m23s

(feat): add pq key generation to wasm
(qol): update gitignores
This commit is contained in:
Alois 2026-06-28 13:08:37 +02:00
commit d9ad5e5b3d
23 changed files with 341 additions and 1996 deletions

View file

@ -1,6 +1,7 @@
use mtp_codec::{CommunicationValue, DataType, DataValue, PROTOCOL_VERSION, Version};
use mtp_common::CommunicationError;
use mtp_transport::{Policy, Receiver, Sender};
#[cfg(feature = "crypto")]
use tokio::time::Duration;
#[cfg(feature = "crypto")]
@ -81,6 +82,51 @@ pub struct MTPConnection {
pub client_id: u64,
}
impl MTPConnection {
/*
* Send a request frame and wait for the response with the same frame id.
* Any expected response type is validated after the id match. Frames with
* other ids are consumed by this call, so applications that need broad
* routing should put request correlation in a dedicated receive task.
*/
pub async fn request(
&self,
request: &CommunicationValue,
expected_response: Option<mtp_codec::CommunicationType>,
) -> Result<CommunicationValue, CommunicationError> {
let request_id = request.get_id();
if request_id == 0 {
return Err(CommunicationError::Other(
"request frame must have a non-zero id".into(),
));
}
self.sender.send(request).await?;
let tm = mtp_codec::TypeMap::latest();
loop {
let response = self.receiver.receive().await?;
if response.get_id() != request_id {
continue;
}
if let Some(expected) = expected_response {
let expected_type = expected.to_id(&tm);
if response.get_type() != expected_type {
return Err(CommunicationError::Other(format!(
"unexpected response type: expected {:?}, got {:?}; parsed {}",
expected_type,
response.get_type(),
response
)));
}
}
return Ok(response);
}
}
}
#[cfg(feature = "crypto")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AuthState {
@ -288,7 +334,12 @@ async fn receive_verified_challenge(
}
};
verify_host_challenge(&challenge, host_public_key_bundle, bound_id, server_challenge)?;
verify_host_challenge(
&challenge,
host_public_key_bundle,
bound_id,
server_challenge,
)?;
Ok(server_challenge)
}
@ -437,6 +488,21 @@ impl MTPClient {
}
}
pub async fn auth_connect_or_register(
mut config: ClientConfig,
existing_client_id: Option<u64>,
keys: &mtp_crypto::Keyring,
host_public_key_bundle: &mtp_crypto::PublicKeyBundle,
) -> Result<MTPConnection, CommunicationError> {
match existing_client_id {
Some(client_id) => {
config.client_id = client_id;
Self::auth_connect(config, keys, host_public_key_bundle).await
}
None => Self::auth_register(config, keys, host_public_key_bundle).await,
}
}
async fn auth_register_inner(
config: ClientConfig,
keys: &mtp_crypto::Keyring,
@ -588,8 +654,8 @@ mod tests {
#[cfg(feature = "crypto")]
#[test]
fn test_auth_timeout_custom() {
let config = ClientConfig::new("https://localhost:4433")
.with_auth_timeout(Duration::from_secs(10));
let config =
ClientConfig::new("https://localhost:4433").with_auth_timeout(Duration::from_secs(10));
assert_eq!(config.auth_timeout, Duration::from_secs(10));
}
}