code cleanup and documentation
This commit is contained in:
@@ -6,12 +6,6 @@ use p256::ecdsa::{
|
||||
use rand_core::OsRng;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
pub enum MathError {
|
||||
DivisionByZero,
|
||||
NonPositiveLogarithm,
|
||||
NegativeSquareRoot,
|
||||
}
|
||||
|
||||
///
|
||||
/// contains the ecdsa private key, the ecdsa public key and the username
|
||||
///
|
||||
@@ -48,6 +42,9 @@ pub fn formatPubKey(crypto_pair: CryptographicSignature) -> String {
|
||||
hex::encode(pubkey_bytes)
|
||||
}
|
||||
|
||||
///
|
||||
/// takes a serialized message and adds the signature using the private key
|
||||
///
|
||||
pub fn sign_message(crypto_pair: CryptographicSignature, message: Vec<u8>) -> Vec<u8> {
|
||||
let length_bytes: [u8; 2] = message[5..7]
|
||||
.try_into()
|
||||
@@ -68,7 +65,6 @@ pub fn sign_message(crypto_pair: CryptographicSignature, message: Vec<u8>) -> Ve
|
||||
println!("signed_tmp:{:?}", signed_message);
|
||||
match signature {
|
||||
Ok(signature) => {
|
||||
//println!("Signature: {:?}", signature);
|
||||
let r = signature.0.r();
|
||||
let s = signature.0.s();
|
||||
|
||||
@@ -87,26 +83,30 @@ pub fn sign_message(crypto_pair: CryptographicSignature, message: Vec<u8>) -> Ve
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
use super::*;
|
||||
|
||||
/*#[test]
|
||||
///
|
||||
/// creates a cryptographic signature
|
||||
///
|
||||
#[test]
|
||||
fn creating_cryptographic_signature() {
|
||||
let username = String::from("quoicoubeh");
|
||||
let username = String::from("gamixtreize");
|
||||
let crypto_pair = CryptographicSignature::new(username);
|
||||
let formatted_pubkey =formatPubKey(crypto_pair);
|
||||
println!("pubkey : {}",formatted_pubkey);
|
||||
}*/
|
||||
let formatted_pubkey = formatPubKey(crypto_pair);
|
||||
println!("pubkey : {}", formatted_pubkey);
|
||||
}
|
||||
|
||||
/*#[test]
|
||||
///
|
||||
/// signs a message
|
||||
///
|
||||
#[test]
|
||||
fn signing_message() {
|
||||
let username = String::from("quoicoubeh");
|
||||
let crypto_pair = CryptographicSignature::new(username);
|
||||
let username_b = String::from("quoicoubeh");
|
||||
let handshake = HandshakeMessage::hello(0, 12, username_b);
|
||||
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);
|
||||
let signed_message = sign_message(crypto_pair, ser.clone());
|
||||
println!("unsigned_message: {:?}", ser);
|
||||
println!("signed_message: {:?}", signed_message);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user