You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

message.rs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. use crypto_box::{
  2. aead::{Aead, AeadCore, OsRng},
  3. PublicKey, SalsaBox, SecretKey,
  4. };
  5. use std::io::Write;
  6. use std::net::TcpStream;
  7. const KEYLENGTH: u8 = 32;
  8. pub enum PayloadType {
  9. //0-31 system messages (plaintext)
  10. Ping = 1,
  11. Pong = 2,
  12. Error = 3,
  13. //32 - 63 Serverside messages (currently plaintext)
  14. Init = 32,
  15. Join = 33,
  16. Exit = 34,
  17. //64 -95 initial setup messages(plaintext)
  18. DhSetup = 64,
  19. DhReturn = 65,
  20. //96 - 127 client-client setup messages(DH or old KEY encrypted)
  21. AUTHORIZE = 96,
  22. KeyCurrent = 97,
  23. KeyNew = 98,
  24. //128-159 main messages (shared KEY encrypted)
  25. Msg = 128,
  26. //160-255 reserved
  27. }
  28. struct Message {
  29. // Eigenschaften der Klasse
  30. src_id: u32,
  31. dest_id: u32,
  32. size: u16,
  33. payload: Vec<u8>,
  34. }
  35. impl Message {
  36. fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
  37. let mut msg = Message {
  38. src_id: src_id,
  39. dest_id: dest_id,
  40. size: size,
  41. payload: Vec::with_capacity(size.into()),
  42. };
  43. msg.payload[0] = msg_type as u8;
  44. msg
  45. }
  46. fn creat_vec(ciphertext: Vec<u8>) -> Vec<u8> {
  47. let mut vec: Vec<u8> = vec![0; 14 + ciphertext.len()];
  48. for i in 14..(14 + ciphertext.len()){
  49. vec[i] = ciphertext[i - 14];
  50. }
  51. vec
  52. }
  53. // Methoden der Klasse
  54. }