aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pap.rs28
-rw-r--r--src/ppp.rs18
2 files changed, 45 insertions, 1 deletions
diff --git a/src/pap.rs b/src/pap.rs
index 093ddb3..0c605d9 100644
--- a/src/pap.rs
+++ b/src/pap.rs
@@ -113,6 +113,34 @@ pub struct PAPFullPkt {
}
impl PAPFullPkt {
+ pub fn new_authenticate_request(identifier: u8, peer_id: String, passwd: String) -> Self {
+ Self {
+ identifier,
+ payload: PAPPkt::AuthenticateRequest(PAPAuthenticateRequest {
+ peer_id: PAPString(peer_id),
+ passwd: PAPString(passwd),
+ }),
+ }
+ }
+
+ pub fn new_authenticate_ack(identifier: u8, msg: String) -> Self {
+ Self {
+ identifier,
+ payload: PAPPkt::AuthenticateAck(PAPAuthenticateAck {
+ msg: PAPString(msg),
+ }),
+ }
+ }
+
+ pub fn new_authenticate_nak(identifier: u8, msg: String) -> Self {
+ Self {
+ identifier,
+ payload: PAPPkt::AuthenticateNak(PAPAuthenticateNak {
+ msg: PAPString(msg),
+ }),
+ }
+ }
+
pub fn len(&self) -> u16 {
4 + self.payload.len()
}
diff --git a/src/ppp.rs b/src/ppp.rs
index 8aeef6a..c47e567 100644
--- a/src/ppp.rs
+++ b/src/ppp.rs
@@ -1,4 +1,4 @@
-use crate::{Deserialize, Error, LCPFullPkt, Result, Serialize};
+use crate::{Deserialize, Error, LCPFullPkt, PAPFullPkt, Result, Serialize};
use std::io::{Read, Write};
@@ -206,6 +206,7 @@ impl From<QualityProtocol> for QualityProtocolInfo {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PPPPkt {
Lcp(LCPFullPkt),
+ Pap(PAPFullPkt),
}
impl Default for PPPPkt {
@@ -218,6 +219,7 @@ impl Serialize for PPPPkt {
fn serialize<W: Write>(&self, w: &mut W) -> Result<()> {
match self {
Self::Lcp(payload) => payload.serialize(w),
+ Self::Pap(payload) => payload.serialize(w),
}
}
}
@@ -226,12 +228,14 @@ impl PPPPkt {
fn discriminant(&self) -> u16 {
match self {
Self::Lcp(_) => LCP,
+ Self::Pap(_) => PAP,
}
}
fn len(&self) -> u16 {
match self {
Self::Lcp(payload) => payload.len(),
+ Self::Pap(payload) => payload.len(),
}
}
@@ -247,6 +251,12 @@ impl PPPPkt {
tmp.deserialize(r)?;
*self = Self::Lcp(tmp);
}
+ PAP => {
+ let mut tmp = PAPFullPkt::default();
+
+ tmp.deserialize(r)?;
+ *self = Self::Pap(tmp);
+ }
_ => return Err(Error::InvalidPPPProtocol(*discriminant)),
}
@@ -267,6 +277,12 @@ impl PPPFullPkt {
}
}
+ pub fn new_pap(pap: PAPFullPkt) -> Self {
+ Self {
+ payload: PPPPkt::Pap(pap),
+ }
+ }
+
pub fn len(&self) -> u16 {
2 + self.payload.len()
}