.env, docs, performance, project name #2
|
@ -1,9 +1,9 @@
|
|||
use crate::helpers::bytes_to_privmsg_base64;
|
||||
use crate::{encryption, helpers};
|
||||
use eyre::Result;
|
||||
use pgp::{Deserializable, SignedPublicKey};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use eyre::Result;
|
||||
|
||||
pub fn handle_message_from_client(
|
||||
recieved: &str,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use eyre::Result;
|
||||
use pgp::crypto::sym::SymmetricKeyAlgorithm;
|
||||
use pgp::ser::Serialize;
|
||||
use pgp::{Deserializable, Message, SignedPublicKey, SignedSecretKey};
|
||||
use rand::prelude::*;
|
||||
use eyre::Result;
|
||||
|
||||
pub fn encrypt(key: &SignedPublicKey, message: &str) -> Result<Vec<u8>, pgp::errors::Error> {
|
||||
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>(
|
||||
key: &'a SignedSecretKey,
|
||||
message: Vec<u8>,
|
||||
message: &[u8],
|
||||
password: &'a str,
|
||||
) -> 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.map(|x| x.unwrap()).collect::<Vec<Message>>(); // Get all messages
|
||||
let message = &message[0]; // Get first message
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use base64::{engine::general_purpose, Engine as _};
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
use eyre::Result;
|
||||
use ircparser;
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
|
||||
static MAX_LENGTH: usize = 300;
|
||||
|
||||
|
@ -12,7 +12,7 @@ fn forward(
|
|||
server_forward: &str,
|
||||
) -> Result<(), mpsc::SendError<String>> {
|
||||
if ircparser::parse(message).unwrap()[0].command == "PRIVMSG" {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
pub fn send_key(
|
||||
sender: &Sender<String>,
|
||||
reciever: &str,
|
||||
key: &Vec<u8>,
|
||||
) -> Result<()> {
|
||||
pub fn send_key(sender: &Sender<String>, reciever: &str, key: &Vec<u8>) -> Result<()> {
|
||||
sender.send(format!("PRIVMSG {reciever} :START_KEY\r\n"))?;
|
||||
sender.send(bytes_to_privmsg_base64(key, reciever))?;
|
||||
sender.send(format!("PRIVMSG {reciever} :END_KEY\r\n"))?;
|
||||
|
@ -76,7 +72,8 @@ pub fn recieve_message_base64(
|
|||
.source
|
||||
.clone()
|
||||
.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)?;
|
||||
continue;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use eyre::Result;
|
||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||
use std::collections::HashMap;
|
||||
use std::net::{Shutdown, TcpStream};
|
||||
|
@ -5,7 +6,6 @@ use std::sync::mpsc;
|
|||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::{env, fs};
|
||||
use eyre::Result;
|
||||
|
||||
mod client_handler;
|
||||
mod encryption;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{encryption, helpers};
|
||||
use eyre::Result;
|
||||
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
use eyre::Result as Result;
|
||||
|
||||
fn forward(
|
||||
message: &str,
|
||||
|
@ -50,7 +50,7 @@ pub fn handle_message_from_server(
|
|||
&sender,
|
||||
"END_MESSAGE",
|
||||
)?; // 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
|
||||
} else if recieved_parsed.params[1] == "START_KEY" {
|
||||
|
|
Loading…
Reference in a new issue