Add tag structure

This commit is contained in:
moznion
2020-12-02 00:16:43 +09:00
parent e49b20bdd4
commit 51c59127ab
2 changed files with 42 additions and 0 deletions

View File

@@ -6,3 +6,4 @@ pub mod request;
pub mod rfc2865;
pub mod rfc2866;
pub mod rfc2867;
pub mod tag;

41
radius/src/tag.rs Normal file
View File

@@ -0,0 +1,41 @@
#[derive(Debug, PartialEq)]
pub struct Tag {
pub(crate) value: u8,
}
impl Tag {
pub fn get_value(&self) -> u8 {
self.value
}
pub fn is_zero(&self) -> bool {
self.value == 0
}
pub fn is_valid_value(&self) -> bool {
1 <= self.value && self.value <= 0x1f
}
}
#[cfg(test)]
mod tests {
use crate::tag::Tag;
#[test]
fn test_is_zero() {
let tag = Tag { value: 0 };
assert_eq!(tag.is_zero(), true);
let tag = Tag { value: 1 };
assert_eq!(tag.is_zero(), false);
}
#[test]
fn test_is_valid_value() {
let tag = Tag { value: 1 };
assert_eq!(tag.is_valid_value(), true);
let tag = Tag { value: 0 };
assert_eq!(tag.is_valid_value(), false);
let tag = Tag { value: 0x20 };
assert_eq!(tag.is_valid_value(), false);
}
}