mirror of
https://github.com/cubixle/radius-rs.git
synced 2026-04-30 17:38:42 +01:00
Rename
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ pub struct AVP {
|
|||||||
pub struct Attributes(pub(crate) Vec<AVP>);
|
pub struct Attributes(pub(crate) Vec<AVP>);
|
||||||
|
|
||||||
impl Attributes {
|
impl Attributes {
|
||||||
pub(crate) fn parse_attributes(bs: &[u8]) -> Result<Attributes, String> {
|
pub(crate) fn decode(bs: &[u8]) -> Result<Attributes, String> {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut attrs = Vec::new();
|
let mut attrs = Vec::new();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match Packet::parse(&buf[..len].to_vec(), request_packet.get_secret()) {
|
match Packet::decode(&buf[..len].to_vec(), request_packet.get_secret()) {
|
||||||
Ok(response_packet) => Ok(response_packet),
|
Ok(response_packet) => Ok(response_packet),
|
||||||
Err(e) => Err(FailedParsingUDPResponse(e)),
|
Err(e) => Err(FailedParsingUDPResponse(e)),
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -43,7 +43,7 @@ impl Packet {
|
|||||||
&self.authenticator
|
&self.authenticator
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(bs: &[u8], secret: &[u8]) -> Result<Self, String> {
|
pub fn decode(bs: &[u8], secret: &[u8]) -> Result<Self, String> {
|
||||||
if bs.len() < RADIUS_PACKET_HEADER_LENGTH {
|
if bs.len() < RADIUS_PACKET_HEADER_LENGTH {
|
||||||
return Err(format!("radius packet doesn't have enough length of bytes; that has to be at least {} bytes", RADIUS_PACKET_HEADER_LENGTH));
|
return Err(format!("radius packet doesn't have enough length of bytes; that has to be at least {} bytes", RADIUS_PACKET_HEADER_LENGTH));
|
||||||
}
|
}
|
||||||
@@ -56,11 +56,10 @@ impl Packet {
|
|||||||
return Err("invalid radius packat lengt".to_owned());
|
return Err("invalid radius packat lengt".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
let attributes =
|
let attributes = match Attributes::decode(&bs[RADIUS_PACKET_HEADER_LENGTH..len].to_vec()) {
|
||||||
match Attributes::parse_attributes(&bs[RADIUS_PACKET_HEADER_LENGTH..len].to_vec()) {
|
Ok(attributes) => attributes,
|
||||||
Ok(attributes) => attributes,
|
Err(e) => return Err(e),
|
||||||
Err(e) => return Err(e),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Packet {
|
Ok(Packet {
|
||||||
code: Code::from(bs[0]),
|
code: Code::from(bs[0]),
|
||||||
@@ -242,7 +241,7 @@ mod tests {
|
|||||||
0x0a, 0xee, 0x04, 0x06, 0xc0, 0xa8, 0x01, 0x10, 0x05, 0x06, 0x00, 0x00, 0x00, 0x03,
|
0x0a, 0xee, 0x04, 0x06, 0xc0, 0xa8, 0x01, 0x10, 0x05, 0x06, 0x00, 0x00, 0x00, 0x03,
|
||||||
];
|
];
|
||||||
|
|
||||||
let packet = Packet::parse(&request, &secret)?;
|
let packet = Packet::decode(&request, &secret)?;
|
||||||
assert_eq!(packet.code, Code::AccessRequest);
|
assert_eq!(packet.code, Code::AccessRequest);
|
||||||
assert_eq!(packet.identifier, 0);
|
assert_eq!(packet.identifier, 0);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -121,7 +121,7 @@ impl Server {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let packet = match Packet::parse(request_data, &secret) {
|
let packet = match Packet::decode(request_data, &secret) {
|
||||||
Ok(packet) => packet,
|
Ok(packet) => packet,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!(
|
error!(
|
||||||
|
|||||||
Reference in New Issue
Block a user