cleanup & try to create message obj in client
This commit is contained in:
parent
352c6ecffd
commit
f4996f366f
@ -4,11 +4,14 @@ use crypto_box::{
|
||||
};
|
||||
use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
use crate::message::*;
|
||||
|
||||
mod message;
|
||||
|
||||
fn main() {
|
||||
let port: u32 = 7878; // Port Server
|
||||
//let stream = TcpStream::connect("172.30.16.1:8080");
|
||||
//let stream = TcpStream::connect("27.0.0.1:8080");
|
||||
// Server Port
|
||||
let port: u32 = 7878;
|
||||
|
||||
match TcpStream::connect(format!("localhost:{}", port)) {
|
||||
Ok(mut stream) => {
|
||||
println!("Successfully connected to server");
|
||||
@ -49,6 +52,7 @@ fn main() {
|
||||
|
||||
// Encrypt the message using the box
|
||||
let ciphertext = salsa_box.encrypt(&nonce, &plaintext[..]).expect("Fehler");
|
||||
let message = Message::new(0,0,4, PayloadType::Msg);
|
||||
|
||||
println!("Sending {0} as {1:?}", buffer.trim(), plaintext);
|
||||
stream.write(buffer.as_bytes()).unwrap();
|
||||
@ -82,17 +86,3 @@ fn main() {
|
||||
}
|
||||
println!("Terminated.");
|
||||
}
|
||||
|
||||
fn generate_box(partner_public_key: PublicKey) -> (SalsaBox, PublicKey) {
|
||||
// Generate a random secret key.
|
||||
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()`
|
||||
let own_secret_key = SecretKey::generate(&mut OsRng);
|
||||
|
||||
// Get the public key for the secret key we just generated
|
||||
let own_public_key = own_secret_key.public_key().clone();
|
||||
|
||||
// Create a `SalsaBox` by performing Diffie-Hellman key agreement between
|
||||
// the two keys.
|
||||
let salsa_box = SalsaBox::new(&partner_public_key, &own_secret_key);
|
||||
(salsa_box, own_public_key)
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
<<<<<<< HEAD
|
||||
use std::{
|
||||
io::{BufReader, Read},
|
||||
net::TcpStream,
|
||||
};
|
||||
=======
|
||||
>>>>>>> f36772d9e5c0507015de02b8c71ff25d84789b98
|
||||
|
||||
const KEYLENGTH: u8 = 32;
|
||||
|
||||
@ -29,7 +26,7 @@ pub enum PayloadType {
|
||||
//160-255 reserved
|
||||
}
|
||||
|
||||
struct Message {
|
||||
pub struct Message {
|
||||
// Eigenschaften der Klasse
|
||||
src_id: u32,
|
||||
dest_id: u32,
|
||||
@ -38,7 +35,7 @@ struct Message {
|
||||
}
|
||||
|
||||
impl Message {
|
||||
fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
|
||||
pub fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
|
||||
let mut msg = Message {
|
||||
src_id: src_id,
|
||||
dest_id: dest_id,
|
||||
@ -69,7 +66,7 @@ impl Message {
|
||||
vec
|
||||
}
|
||||
|
||||
fn recive(stream: TcpStream) -> Message {
|
||||
fn receive(stream: TcpStream) -> Message {
|
||||
let buffreader = BufReader::new(stream);
|
||||
let mut byte_iterator = buffreader.bytes();
|
||||
let byte1 = byte_iterator.next().unwrap().unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user