General Upgrade, NEW: WebServers, Better Docs
Some checks failed
CI / checks (push) Failing after 5m18s
Some checks failed
CI / checks (push) Failing after 5m18s
This commit is contained in:
parent
5f11d476b6
commit
6e5c985719
122 changed files with 10309 additions and 5206 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
|
|
@ -8,6 +8,6 @@ name = "client"
|
|||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
mtp = { version = "0.1.0", path = "../../", features = ["client", "crypto", "files", "pipes"] }
|
||||
mtp = { version = "0.2.0", path = "../../", features = ["client", "crypto", "files", "pipes"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
rand = "0.8"
|
||||
rand = "0.10.1"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use mtp::client::{ClientConfig, MTPClient, MTPConnection};
|
|||
use mtp::crypto::{
|
||||
Ed25519Signer, KemPrivateKey, KemPublicKey, Keyring, MlDsaSigner, PublicKeyBundle,
|
||||
};
|
||||
use mtp::files::{load_keyring, save_keyring};
|
||||
use mtp::files::{load_keyring_raw, save_keyring_raw};
|
||||
|
||||
pub async fn connect_or_register(
|
||||
mut config: ClientConfig,
|
||||
|
|
@ -14,7 +14,10 @@ pub async fn connect_or_register(
|
|||
let keyring_path = format!("{key_prefix}.mk");
|
||||
let id_path = format!("{key_prefix}.id");
|
||||
|
||||
if let (Ok(keyring), Ok(id)) = (load_keyring(&keyring_path), fs::read_to_string(&id_path)) {
|
||||
if let (Ok(keyring), Ok(id)) = (
|
||||
load_keyring_raw(&keyring_path),
|
||||
fs::read_to_string(&id_path),
|
||||
) {
|
||||
let client_id: u64 = id.trim().parse()?;
|
||||
println!("Loaded client keys (ID: {client_id})");
|
||||
|
||||
|
|
@ -41,7 +44,7 @@ pub async fn connect_or_register(
|
|||
let conn = MTPClient::auth_register(config, &keyring, &host_public_key).await?;
|
||||
println!("Registered with ID: {}", conn.client_id);
|
||||
|
||||
save_keyring(&keyring, &keyring_path)?;
|
||||
save_keyring_raw(&keyring, &keyring_path)?;
|
||||
fs::write(&id_path, conn.client_id.to_string())?;
|
||||
println!("Saved client keys -> {keyring_path}");
|
||||
|
||||
|
|
|
|||
|
|
@ -13,33 +13,33 @@ pub fn build_demo_message(
|
|||
let signer = Ed25519Signer::new(&keyring.sig_cl_secret_key)?;
|
||||
|
||||
let tm = TypeMap::latest();
|
||||
let version_id = DataType::Version
|
||||
.try_to_id(&tm)
|
||||
.ok_or_else(|| std::io::Error::other("Version is absent from the type map"))?;
|
||||
let id_id = DataType::Id
|
||||
.try_to_id(&tm)
|
||||
.ok_or_else(|| std::io::Error::other("Id is absent from the type map"))?;
|
||||
|
||||
let inner_enc = DataValue::Container(vec![
|
||||
(
|
||||
DataType::Version.to_id(&tm),
|
||||
DataValue::Str("secret inner data".into()),
|
||||
),
|
||||
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(42)),
|
||||
(version_id, DataValue::Str("secret inner data".into())),
|
||||
(id_id, DataValue::UnsignedNumber(42)),
|
||||
]);
|
||||
let mut dv_enc = inner_enc;
|
||||
dv_enc.encrypt_container(enc_type, server_bundle, b"demo-aad");
|
||||
|
||||
let inner_sig = DataValue::Container(vec![
|
||||
(
|
||||
DataType::Version.to_id(&tm),
|
||||
DataValue::Str("signed by client".into()),
|
||||
),
|
||||
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(99)),
|
||||
(version_id, DataValue::Str("signed by client".into())),
|
||||
(id_id, DataValue::UnsignedNumber(99)),
|
||||
]);
|
||||
let mut dv_sig = inner_sig;
|
||||
dv_sig.sign_container(SigAlgorithm::ED25519, &signer);
|
||||
|
||||
let inner_sec = DataValue::Container(vec![
|
||||
(
|
||||
DataType::Version.to_id(&tm),
|
||||
version_id,
|
||||
DataValue::Str("signed+encrypted payload".into()),
|
||||
),
|
||||
(DataType::Id.to_id(&tm), DataValue::UnsignedNumber(7)),
|
||||
(id_id, DataValue::UnsignedNumber(7)),
|
||||
]);
|
||||
let mut dv_sec = inner_sec;
|
||||
dv_sec.sign_and_encrypt_container(
|
||||
|
|
@ -65,7 +65,7 @@ pub fn build_demo_message(
|
|||
)
|
||||
.add_typed_default(DataType::Data, DataValue::Str("Hello, MTP!".into()))
|
||||
.add_typed_default(DataType::Flags, DataValue::BoolTrue)
|
||||
.add_typed_default(DataType::Value, DataValue::Float(2, 12345))
|
||||
.add_typed_default(DataType::Value, DataValue::Float(1_234_500.0))
|
||||
.add_typed_default(
|
||||
DataType::BinaryData,
|
||||
DataValue::Bytes(vec![0xDE, 0xAD, 0xBE, 0xEF, 0x42]),
|
||||
|
|
|
|||
Loading…
Reference in a new issue