mirror of
https://git.mentality.rip/numas13/xash3d-master.git
synced 2025-03-10 04:31:10 +00:00
protocol: Do not print admin password hash
This commit is contained in:
parent
e7d846013d
commit
35b4abbf15
@ -2,7 +2,7 @@
|
||||
// SPDX-FileCopyrightText: 2023 Denis Drakhnia <numas13@gmail.com>
|
||||
|
||||
use crate::cursor::{Cursor, CursorMut};
|
||||
use crate::types::Str;
|
||||
use crate::types::{Hide, Str};
|
||||
use crate::Error;
|
||||
|
||||
pub const HASH_LEN: usize = 64;
|
||||
@ -30,7 +30,7 @@ impl AdminChallenge {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct AdminCommand<'a> {
|
||||
pub hash: &'a [u8],
|
||||
pub hash: Hide<&'a [u8]>,
|
||||
pub command: Str<&'a [u8]>,
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ impl<'a> AdminCommand<'a> {
|
||||
|
||||
pub fn new(hash: &'a [u8], command: &'a str) -> Self {
|
||||
Self {
|
||||
hash,
|
||||
hash: Hide(hash),
|
||||
command: Str(command.as_bytes()),
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ impl<'a> AdminCommand<'a> {
|
||||
pub fn decode_with_hash_len(hash_len: usize, src: &'a [u8]) -> Result<Self, Error> {
|
||||
let mut cur = Cursor::new(src);
|
||||
cur.expect(Self::HEADER)?;
|
||||
let hash = cur.get_bytes(hash_len)?;
|
||||
let hash = Hide(cur.get_bytes(hash_len)?);
|
||||
let command = Str(cur.get_bytes(cur.remaining())?);
|
||||
cur.expect_empty()?;
|
||||
Ok(Self { hash, command })
|
||||
@ -61,7 +61,7 @@ impl<'a> AdminCommand<'a> {
|
||||
pub fn encode(&self, buf: &mut [u8]) -> Result<usize, Error> {
|
||||
Ok(CursorMut::new(buf)
|
||||
.put_bytes(Self::HEADER)?
|
||||
.put_bytes(self.hash)?
|
||||
.put_bytes(&self.hash)?
|
||||
.put_bytes(&self.command)?
|
||||
.pos())
|
||||
}
|
||||
|
@ -49,3 +49,27 @@ impl<T> Deref for Str<T> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper for slice of bytes without printing
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Default)]
|
||||
pub struct Hide<T>(pub T);
|
||||
|
||||
impl<T> fmt::Debug for Hide<T> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "<hidden>")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Display for Hide<T> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "<hidden>")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Hide<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user