diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-26 16:59:52 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-26 16:59:52 +0200 |
commit | 3bd9f255b44cc142286920ba4550310cf2a786fe (patch) | |
tree | dc8401f0680ba98a3cd061dae7b328572f670945 /src | |
parent | 690429be4453d41cc106b4b78ed633f31befd678 (diff) |
add helper constructors for CHAP
Diffstat (limited to 'src')
-rw-r--r-- | src/chap.rs | 28 | ||||
-rw-r--r-- | src/ppp.rs | 18 |
2 files changed, 45 insertions, 1 deletions
diff --git a/src/chap.rs b/src/chap.rs index d149a98..e19ef54 100644 --- a/src/chap.rs +++ b/src/chap.rs @@ -99,6 +99,34 @@ pub struct ChapPkt { } impl ChapPkt { + pub fn new_challenge(identifier: u8, value: Vec<u8>, name: String) -> Self { + Self { + identifier, + data: ChapData::Challenge(ChapChallenge { value, name }), + } + } + + pub fn new_response(identifier: u8, value: Vec<u8>, name: String) -> Self { + Self { + identifier, + data: ChapData::Response(ChapResponse { value, name }), + } + } + + pub fn new_success(identifier: u8, message: String) -> Self { + Self { + identifier, + data: ChapData::Success(ChapSuccess { message }), + } + } + + pub fn new_failure(identifier: u8, message: String) -> Self { + Self { + identifier, + data: ChapData::Failure(ChapFailure { message }), + } + } + pub fn len(&self) -> u16 { 4 + self.data.len() } @@ -1,4 +1,4 @@ -use crate::{Deserialize, Error, LcpPkt, PapPkt, Result, Serialize}; +use crate::{ChapPkt, Deserialize, Error, LcpPkt, PapPkt, Result, Serialize}; use std::io::{Read, Write}; @@ -207,6 +207,7 @@ impl From<QualityProto> for QualityProtocol { pub enum PppData { Lcp(LcpPkt), Pap(PapPkt), + Chap(ChapPkt), } impl Default for PppData { @@ -220,6 +221,7 @@ impl Serialize for PppData { match self { Self::Lcp(payload) => payload.serialize(w), Self::Pap(payload) => payload.serialize(w), + Self::Chap(payload) => payload.serialize(w), } } } @@ -229,6 +231,7 @@ impl PppData { match self { Self::Lcp(_) => LCP, Self::Pap(_) => PAP, + Self::Chap(_) => CHAP, } } @@ -236,6 +239,7 @@ impl PppData { match self { Self::Lcp(payload) => payload.len(), Self::Pap(payload) => payload.len(), + Self::Chap(payload) => payload.len(), } } @@ -257,6 +261,12 @@ impl PppData { tmp.deserialize(r)?; *self = Self::Pap(tmp); } + CHAP => { + let mut tmp = ChapPkt::default(); + + tmp.deserialize(r)?; + *self = Self::Chap(tmp); + } _ => return Err(Error::InvalidPppProtocol(*discriminant)), } @@ -283,6 +293,12 @@ impl PppPkt { } } + pub fn new_chap(chap: ChapPkt) -> Self { + Self { + data: PppData::Chap(chap), + } + } + pub fn len(&self) -> u16 { 2 + self.data.len() } |