enregistrement avec serveur

This commit is contained in:
TIBERGHIEN corentin
2025-12-16 22:43:49 +01:00
parent 721d52a028
commit 002a667837
6 changed files with 968 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
mod data;
mod protocol;
/// Messages sent to the Network thread by the GUI.
pub enum NetworkCommand {

View File

@@ -0,0 +1,49 @@
use http::{Request, Response};
use p256::ecdsa::{
Signature, SigningKey, VerifyingKey,
signature::{Signer, Verifier},
};
use rand_core::OsRng;
struct KeyRegistration {
priv_key: SigningKey,
pub_key: VerifyingKey,
username: String,
}
impl KeyRegistration {
fn new(username: String) -> KeyRegistration {
let priv_key = SigningKey::random(&mut OsRng);
let pub_key = VerifyingKey::from(&priv_key);
KeyRegistration {
priv_key: priv_key,
pub_key: pub_key,
username: username,
}
}
}
async fn register_with_the_server(key: KeyRegistration) -> Result<bytes::Bytes, reqwest::Error> {
let client = reqwest::Client::new();
let pubkey_ser = key.pub_key.to_encoded_point(false);
let pubkey_str = hex::encode(pubkey_ser);
let uri = format!("https://jch.irif.fr:8443/peers/{}/key", key.username);
let resp = client.put(uri).send().await?.error_for_status()?;
resp.bytes().await
}
/*#[cfg(test)]
mod tests {
use super::*;
#[test]
fn key_genereation() {
let keys = KeyRegistration::new();
let pubkey = keys.pub_key;
let pubkey_ser = pubkey.to_encoded_point(false);
println!("string pubkey: {}", hex::encode(pubkey_ser));
println!("string privkey: {}", hex::encode(keys.priv_key.to_bytes()))
}
}*/