This commit is contained in:
moznion
2020-11-28 15:39:41 +09:00
parent 4b7eb55c10
commit 2d2069b0ab
4 changed files with 9 additions and 10 deletions

View File

@@ -14,7 +14,7 @@ pub struct AVP {
pub struct Attributes(pub(crate) Vec<AVP>);
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 attrs = Vec::new();

View File

@@ -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),
Err(e) => Err(FailedParsingUDPResponse(e)),
}

View File

@@ -43,7 +43,7 @@ impl Packet {
&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 {
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());
}
let attributes =
match Attributes::parse_attributes(&bs[RADIUS_PACKET_HEADER_LENGTH..len].to_vec()) {
Ok(attributes) => attributes,
Err(e) => return Err(e),
};
let attributes = match Attributes::decode(&bs[RADIUS_PACKET_HEADER_LENGTH..len].to_vec()) {
Ok(attributes) => attributes,
Err(e) => return Err(e),
};
Ok(Packet {
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,
];
let packet = Packet::parse(&request, &secret)?;
let packet = Packet::decode(&request, &secret)?;
assert_eq!(packet.code, Code::AccessRequest);
assert_eq!(packet.identifier, 0);

View File

@@ -121,7 +121,7 @@ impl Server {
return;
}
let packet = match Packet::parse(request_data, &secret) {
let packet = match Packet::decode(request_data, &secret) {
Ok(packet) => packet,
Err(e) => {
error!(