1
0

changing authentication token length to 32

This commit is contained in:
EAimTY 2023-02-02 21:02:52 +09:00
parent 61477f5094
commit 0070112e23
6 changed files with 16 additions and 16 deletions

View File

@ -251,7 +251,7 @@ impl Connection {
} }
async fn authenticate(self) { async fn authenticate(self) {
match self.model.authenticate([0; 8]).await { match self.model.authenticate([0; 32]).await {
Ok(()) => {} Ok(()) => {}
Err(err) => eprintln!("{err}"), Err(err) => eprintln!("{err}"),
} }

View File

@ -102,7 +102,7 @@ impl Connection<side::Client> {
} }
} }
pub async fn authenticate(&self, token: [u8; 8]) -> Result<(), Error> { pub async fn authenticate(&self, token: [u8; 32]) -> Result<(), Error> {
let model = self.model.send_authenticate(token); let model = self.model.send_authenticate(token);
let mut send = self.conn.open_uni().await?; let mut send = self.conn.open_uni().await?;
model.header().async_marshal(&mut send).await?; model.header().async_marshal(&mut send).await?;
@ -388,7 +388,7 @@ impl Packet {
#[non_exhaustive] #[non_exhaustive]
pub enum Task { pub enum Task {
Authenticate([u8; 8]), Authenticate([u8; 32]),
Connect(Connect), Connect(Connect),
Packet(Packet), Packet(Packet),
Dissociate(u16), Dissociate(u16),

View File

@ -11,7 +11,7 @@ pub struct Tx {
} }
impl Authenticate<side::Tx> { impl Authenticate<side::Tx> {
pub(super) fn new(token: [u8; 8]) -> Self { pub(super) fn new(token: [u8; 32]) -> Self {
Self { Self {
inner: Side::Tx(Tx { inner: Side::Tx(Tx {
header: Header::Authenticate(AuthenticateHeader::new(token)), header: Header::Authenticate(AuthenticateHeader::new(token)),
@ -27,18 +27,18 @@ impl Authenticate<side::Tx> {
} }
pub struct Rx { pub struct Rx {
token: [u8; 8], token: [u8; 32],
} }
impl Authenticate<side::Rx> { impl Authenticate<side::Rx> {
pub(super) fn new(token: [u8; 8]) -> Self { pub(super) fn new(token: [u8; 32]) -> Self {
Self { Self {
inner: Side::Rx(Rx { token }), inner: Side::Rx(Rx { token }),
_marker: side::Rx, _marker: side::Rx,
} }
} }
pub fn token(&self) -> [u8; 8] { pub fn token(&self) -> [u8; 32] {
let Side::Rx(rx) = &self.inner else { unreachable!() }; let Side::Rx(rx) = &self.inner else { unreachable!() };
rx.token rx.token
} }

View File

@ -50,7 +50,7 @@ where
} }
} }
pub fn send_authenticate(&self, token: [u8; 8]) -> Authenticate<side::Tx> { pub fn send_authenticate(&self, token: [u8; 32]) -> Authenticate<side::Tx> {
Authenticate::<side::Tx>::new(token) Authenticate::<side::Tx>::new(token)
} }

View File

@ -1,21 +1,21 @@
// +-------+ // +-------+
// | TOKEN | // | TOKEN |
// +-------+ // +-------+
// | 8 | // | 32 |
// +-------+ // +-------+
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Authenticate { pub struct Authenticate {
token: [u8; 8], token: [u8; 32],
} }
impl Authenticate { impl Authenticate {
const TYPE_CODE: u8 = 0x00; const TYPE_CODE: u8 = 0x00;
pub const fn new(token: [u8; 8]) -> Self { pub const fn new(token: [u8; 32]) -> Self {
Self { token } Self { token }
} }
pub fn token(&self) -> [u8; 8] { pub fn token(&self) -> [u8; 32] {
self.token self.token
} }
@ -24,11 +24,11 @@ impl Authenticate {
} }
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
8 32
} }
} }
impl From<Authenticate> for ([u8; 8],) { impl From<Authenticate> for ([u8; 32],) {
fn from(auth: Authenticate) -> Self { fn from(auth: Authenticate) -> Self {
(auth.token,) (auth.token,)
} }

View File

@ -164,14 +164,14 @@ impl Address {
impl Authenticate { impl Authenticate {
#[cfg(feature = "async_marshal")] #[cfg(feature = "async_marshal")]
async fn async_read(s: &mut (impl AsyncRead + Unpin)) -> Result<Self, UnmarshalError> { async fn async_read(s: &mut (impl AsyncRead + Unpin)) -> Result<Self, UnmarshalError> {
let mut buf = [0; 8]; let mut buf = [0; 32];
s.read_exact(&mut buf).await?; s.read_exact(&mut buf).await?;
Ok(Self::new(buf)) Ok(Self::new(buf))
} }
#[cfg(feature = "marshal")] #[cfg(feature = "marshal")]
fn read(s: &mut impl Read) -> Result<Self, UnmarshalError> { fn read(s: &mut impl Read) -> Result<Self, UnmarshalError> {
let mut buf = [0; 8]; let mut buf = [0; 32];
s.read_exact(&mut buf)?; s.read_exact(&mut buf)?;
Ok(Self::new(buf)) Ok(Self::new(buf))
} }