Minor formatting changes
This commit is contained in:
parent
25b8f5b51e
commit
34b2e0e5a9
|
@ -1,9 +1,9 @@
|
||||||
use crate::helpers::bytes_to_privmsg_base64;
|
use crate::helpers::bytes_to_privmsg_base64;
|
||||||
use crate::{encryption, helpers};
|
use crate::{encryption, helpers};
|
||||||
|
use eyre::Result;
|
||||||
use pgp::{Deserializable, SignedPublicKey};
|
use pgp::{Deserializable, SignedPublicKey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::mpsc::{Receiver, Sender};
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
use eyre::Result;
|
|
||||||
|
|
||||||
pub fn handle_message_from_client(
|
pub fn handle_message_from_client(
|
||||||
recieved: &str,
|
recieved: &str,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use eyre::Result;
|
||||||
use pgp::crypto::sym::SymmetricKeyAlgorithm;
|
use pgp::crypto::sym::SymmetricKeyAlgorithm;
|
||||||
use pgp::ser::Serialize;
|
use pgp::ser::Serialize;
|
||||||
use pgp::{Deserializable, Message, SignedPublicKey, SignedSecretKey};
|
use pgp::{Deserializable, Message, SignedPublicKey, SignedSecretKey};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use eyre::Result;
|
|
||||||
|
|
||||||
pub fn encrypt(key: &SignedPublicKey, message: &str) -> Result<Vec<u8>, pgp::errors::Error> {
|
pub fn encrypt(key: &SignedPublicKey, message: &str) -> Result<Vec<u8>, pgp::errors::Error> {
|
||||||
let message = Message::new_literal("none", message);
|
let message = Message::new_literal("none", message);
|
||||||
|
@ -15,10 +15,10 @@ pub fn encrypt(key: &SignedPublicKey, message: &str) -> Result<Vec<u8>, pgp::err
|
||||||
|
|
||||||
pub fn decrypt<'a>(
|
pub fn decrypt<'a>(
|
||||||
key: &'a SignedSecretKey,
|
key: &'a SignedSecretKey,
|
||||||
message: Vec<u8>,
|
message: &[u8],
|
||||||
password: &'a str,
|
password: &'a str,
|
||||||
) -> Result<String, pgp::errors::Error> {
|
) -> Result<String, pgp::errors::Error> {
|
||||||
let message = Message::from_bytes(message.as_slice())?; // Convert message bytes to message object
|
let message = Message::from_bytes(message)?; // Convert message bytes to message object
|
||||||
let message = message.decrypt(|| password.to_string(), &[key])?.0; // Decrypt
|
let message = message.decrypt(|| password.to_string(), &[key])?.0; // Decrypt
|
||||||
let message = message.map(|x| x.unwrap()).collect::<Vec<Message>>(); // Get all messages
|
let message = message.map(|x| x.unwrap()).collect::<Vec<Message>>(); // Get all messages
|
||||||
let message = &message[0]; // Get first message
|
let message = &message[0]; // Get first message
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use base64::{engine::general_purpose, Engine as _};
|
use base64::{engine::general_purpose, Engine as _};
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use ircparser;
|
use ircparser;
|
||||||
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
|
|
||||||
static MAX_LENGTH: usize = 300;
|
static MAX_LENGTH: usize = 300;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ fn forward(
|
||||||
server_forward: &str,
|
server_forward: &str,
|
||||||
) -> Result<(), mpsc::SendError<String>> {
|
) -> Result<(), mpsc::SendError<String>> {
|
||||||
if ircparser::parse(message).unwrap()[0].command == "PRIVMSG" {
|
if ircparser::parse(message).unwrap()[0].command == "PRIVMSG" {
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
stream.send(message.replace(&server_local, server_forward))
|
stream.send(message.replace(&server_local, server_forward))
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,7 @@ pub fn bytes_to_privmsg_base64(message: &Vec<u8>, reciever: &str) -> String {
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_key(
|
pub fn send_key(sender: &Sender<String>, reciever: &str, key: &Vec<u8>) -> Result<()> {
|
||||||
sender: &Sender<String>,
|
|
||||||
reciever: &str,
|
|
||||||
key: &Vec<u8>,
|
|
||||||
) -> Result<()> {
|
|
||||||
sender.send(format!("PRIVMSG {reciever} :START_KEY\r\n"))?;
|
sender.send(format!("PRIVMSG {reciever} :START_KEY\r\n"))?;
|
||||||
sender.send(bytes_to_privmsg_base64(key, reciever))?;
|
sender.send(bytes_to_privmsg_base64(key, reciever))?;
|
||||||
sender.send(format!("PRIVMSG {reciever} :END_KEY\r\n"))?;
|
sender.send(format!("PRIVMSG {reciever} :END_KEY\r\n"))?;
|
||||||
|
@ -76,7 +72,8 @@ pub fn recieve_message_base64(
|
||||||
.source
|
.source
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or("".to_string())
|
.unwrap_or("".to_string())
|
||||||
.starts_with(&begin_source_reciever) || recieved.params[0].starts_with("#")
|
.starts_with(&begin_source_reciever)
|
||||||
|
|| recieved.params[0].starts_with("#")
|
||||||
{
|
{
|
||||||
forward(&recieved_raw, forward_stream, server_local, server_forward)?;
|
forward(&recieved_raw, forward_stream, server_local, server_forward)?;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use eyre::Result;
|
||||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{Shutdown, TcpStream};
|
use std::net::{Shutdown, TcpStream};
|
||||||
|
@ -5,7 +6,6 @@ use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use eyre::Result;
|
|
||||||
|
|
||||||
mod client_handler;
|
mod client_handler;
|
||||||
mod encryption;
|
mod encryption;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{encryption, helpers};
|
use crate::{encryption, helpers};
|
||||||
|
use eyre::Result;
|
||||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
use eyre::Result as Result;
|
|
||||||
|
|
||||||
fn forward(
|
fn forward(
|
||||||
message: &str,
|
message: &str,
|
||||||
|
@ -50,7 +50,7 @@ pub fn handle_message_from_server(
|
||||||
&sender,
|
&sender,
|
||||||
"END_MESSAGE",
|
"END_MESSAGE",
|
||||||
)?; // Get
|
)?; // Get
|
||||||
let message = encryption::decrypt(&secret_key, message, &passwd)?; // Decrypt
|
let message = encryption::decrypt(&secret_key, &message, &passwd)?; // Decrypt
|
||||||
|
|
||||||
listener_channel_tx.send(recieved.replace("START_MESSAGE", &message))?; // Send
|
listener_channel_tx.send(recieved.replace("START_MESSAGE", &message))?; // Send
|
||||||
} else if recieved_parsed.params[1] == "START_KEY" {
|
} else if recieved_parsed.params[1] == "START_KEY" {
|
||||||
|
|
Loading…
Reference in a new issue