code tidy

This commit is contained in:
Tiago Batista Cardoso
2026-01-25 14:22:20 +01:00
parent 55a0eb21bb
commit 15bfbcd0d4
12 changed files with 124 additions and 537 deletions

View File

@@ -1,11 +1,6 @@
use std::io::Read;
use bytes::Bytes;
use p256::EncodedPoint;
use p256::ecdsa::{
Signature, SigningKey, VerifyingKey,
signature::{Signer, Verifier},
};
use p256::ecdsa::{Signature, SigningKey, VerifyingKey, signature::Verifier};
use rand_core::OsRng;
use sha2::{Digest, Sha256};
@@ -37,15 +32,6 @@ impl CryptographicSignature {
}
}
///
/// returns a string representing the pub_key as a String
///
pub fn formatPubKey(crypto_pair: CryptographicSignature) -> String {
let encoded_point = crypto_pair.pub_key.to_encoded_point(false);
let pubkey_bytes = encoded_point.as_bytes();
hex::encode(pubkey_bytes)
}
pub async fn get_peer_key(username: &String) -> Result<VerifyingKey, reqwest::Error> {
let client = reqwest::Client::new();
let uri = format!("https://jch.irif.fr:8443/peers/{}/key", username);
@@ -126,34 +112,7 @@ pub fn sign_message(crypto_pair: &CryptographicSignature, message: &Vec<u8>) ->
signed_message
}
Err(e) => {
panic!("error");
panic!("error : {}", e);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
/*
///
/// creates a cryptographic signature
///
#[test]
fn creating_cryptographic_signature() {
let username = String::from("gamixtreize");
let crypto_pair = CryptographicSignature::new(username);
let formatted_pubkey = formatPubKey(crypto_pair);
println!("pubkey : {}", formatted_pubkey);
}*/
/*#[test]
fn signing_message() {
let username = String::from("gamixtreize");
let crypto_pair = CryptographicSignature::new(username.clone());
let handshake = HandshakeMessage::hello(0, 12, username);
let ser = handshake.serialize();
let signed_message = sign_message(&crypto_pair, &ser);
println!("unsigned_message: {:?}", ser);
println!("signed_message: {:?}", signed_message);
}*/
}