-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
Handling of Vendor Specific Attributes (VSA)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ pub mod rfc6911; | |
pub mod rfc7055; | ||
pub mod rfc7155; | ||
pub mod tag; | ||
pub mod vsa; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const SINGLE_FIELDS_COUNT: usize = 3; | ||
|
||
/// This struct represents a attribute-value pair. | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct VSA { | ||
vendor_id: Vec<u8>, | ||
type_id: u8, | ||
length: u8, | ||
tag: u8, | ||
value: Vec<u8>, | ||
} | ||
|
||
impl VSA { | ||
pub fn new(vendor_id: i32, type_id: u8, tag: u8, value: &str) -> VSA { | ||
VSA { | ||
vendor_id: vendor_id.to_be_bytes().to_vec(), | ||
type_id, | ||
length: (SINGLE_FIELDS_COUNT + value.len()) as u8, | ||
tag: tag, | ||
Check warning on line 19 in radius/src/core/vsa.rs GitHub Actions / build (ubuntu-latest, stable)
Check warning on line 19 in radius/src/core/vsa.rs GitHub Actions / build (ubuntu-latest, nightly)
Check warning on line 19 in radius/src/core/vsa.rs GitHub Actions / build (macOS-latest, stable)
Check warning on line 19 in radius/src/core/vsa.rs GitHub Actions / build (macOS-latest, nightly)
Check warning on line 19 in radius/src/core/vsa.rs GitHub Actions / build (windows-latest, stable)
|
||
value: value.as_bytes().to_vec(), | ||
} | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
Check warning on line 24 in radius/src/core/vsa.rs GitHub Actions / build (ubuntu-latest, stable)
Check warning on line 24 in radius/src/core/vsa.rs GitHub Actions / build (ubuntu-latest, nightly)
Check warning on line 24 in radius/src/core/vsa.rs GitHub Actions / build (macOS-latest, stable)
Check warning on line 24 in radius/src/core/vsa.rs GitHub Actions / build (macOS-latest, nightly)
Check warning on line 24 in radius/src/core/vsa.rs GitHub Actions / build (windows-latest, stable)
|
||
self.length as usize | ||
} | ||
|
||
pub fn message(&self) -> Vec<u8> { | ||
let mut msg = vec![self.type_id, self.length, self.tag]; | ||
msg.splice(0..0, self.vendor_id.iter().cloned()); | ||
msg.append(&mut self.value.clone()); | ||
|
||
msg | ||
} | ||
} |