mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Readability fixes for cargo clippy
This commit is contained in:
@@ -26,18 +26,18 @@ pub fn generate_encryption_details(client_pub_key: &[u8]) -> Keys {
|
||||
let big_0 = BigInt::from(0);
|
||||
let prime_root = BigInt::from(PRIME_ROOT);
|
||||
let my_prime = BigInt::from_bytes_be(num::bigint::Sign::Plus, PRIME_768);
|
||||
log::debug!("Generating keys for client pub key {}", client_num.to_string());
|
||||
log::debug!("Generating keys for client pub key {}", client_num);
|
||||
let mut rng = rand::rng();
|
||||
let mut bytes = rng.random::<[u8; SECRET_LEN]>();
|
||||
let mut my_secret = BigInt::from_bytes_be(num::bigint::Sign::Plus, &bytes);
|
||||
while my_secret >= &my_prime - 1 || my_secret == big_0 {
|
||||
bytes = rng.random::<[u8; SECRET_LEN]>();
|
||||
my_secret = BigInt::from_bytes_be(num::bigint::Sign::Plus, &bytes);
|
||||
log::debug!("Generated secret {} (prime to beat: {})", my_secret.to_string(), my_prime.to_string());
|
||||
log::debug!("Generated secret {} (prime to beat: {})", my_secret, my_prime);
|
||||
}
|
||||
let my_pub_key = prime_root.modpow(&my_secret, &my_prime);
|
||||
let shared_key = client_num.modpow(&my_secret, &my_prime);
|
||||
log::debug!("Generated shared key {} and pub key {}", shared_key.to_string(), my_pub_key.to_string());
|
||||
log::debug!("Generated shared key {} and pub key {}", shared_key, my_pub_key);
|
||||
let shared_key = shared_key.to_bytes_be().1;
|
||||
let enc_key: Vec<u8> = ring::digest::digest(&ring::digest::SHA256, &shared_key).as_ref().into();
|
||||
log::debug!("Encryption key is {:?}", enc_key.as_slice());
|
||||
|
||||
@@ -36,7 +36,7 @@ impl <'a> Handshake<Start<'a>> {
|
||||
if let Message::Standard(conn) = &packet.message {
|
||||
if let Data::InitStart(info) = &conn.data {
|
||||
if info.app_id != self.state.app_id {
|
||||
let err = ConnectError::WrongAppId { got: &info.app_id, expected: &self.state.app_id };
|
||||
let err = ConnectError::WrongAppId { got: &info.app_id, expected: self.state.app_id };
|
||||
return Err(HandshakeAnd {
|
||||
handshake: self,
|
||||
extra: err,
|
||||
@@ -75,7 +75,7 @@ pub enum EncryptError {
|
||||
impl Handshake<Connected> {
|
||||
const PUBLIC_KEY_PARAM_KEY: u8 = 1;
|
||||
|
||||
pub fn encrypt<'a>(self, packet: &'a Packet) -> Result<HandshakeAnd<Encrypted, (Packet, crate::encryption::CryptoImpl)>, HandshakeAnd<Connected, EncryptError>> {
|
||||
pub fn encrypt(self, packet: &Packet) -> Result<HandshakeAnd<Encrypted, (Packet, crate::encryption::CryptoImpl)>, HandshakeAnd<Connected, EncryptError>> {
|
||||
if let Packet::Packet(packet) = &packet {
|
||||
if let Message::Standard(conn) = &packet.message {
|
||||
if let Data::InternalOpReq(req) = &conn.data {
|
||||
@@ -153,7 +153,7 @@ impl <T: AuthProvider<E>, E> Handshake<Auth<T, E>> {
|
||||
const AUTH_REQUEST_CODE: u8 = 230;
|
||||
const USER_ID_KEY: u8 = 225;
|
||||
const NICKNAME_KEY: u8 = 225;
|
||||
pub fn authenticate<'a>(mut self, packet: &'a Packet, serdes_ctx: &polariton::packet::SerdesContext<(), polariton::serdes::NoCustomSerdes>) -> Result<Packet, HandshakeAnd<Auth<T, E>, AuthError<E>>> {
|
||||
pub fn authenticate(mut self, packet: &Packet, serdes_ctx: &polariton::packet::SerdesContext<(), polariton::serdes::NoCustomSerdes>) -> Result<Packet, HandshakeAnd<Auth<T, E>, AuthError<E>>> {
|
||||
if let Packet::Packet(packet) = &packet {
|
||||
if let Message::Standard(conn) = &packet.message {
|
||||
if let Data::OpReq(req) = &conn.data {
|
||||
|
||||
Reference in New Issue
Block a user