#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct AssociationOptions(pub u16);
impl AssociationOptions {
pub const NO_PROTECTION: u16 = 1;
pub const INTEGRITY: u16 = 2;
pub const CONFIDENTIALITY: u16 = 4;
pub const DETECT_REPLAY: u16 = 8;
pub const DETECT_MISORDERING: u16 = 16;
pub const ESTABLISH_TRUST_IN_TARGET: u16 = 32;
pub const ESTABLISH_TRUST_IN_CLIENT: u16 = 64;
pub const NO_DELEGATION: u16 = 128;
pub const SIMPLE_DELEGATION: u16 = 256;
pub const COMPOSITE_DELEGATION: u16 = 512;
pub const IDENTITY_ASSERTION: u16 = 1024;
pub const DELEGATION_BY_CLIENT: u16 = 2048;
#[must_use]
pub const fn from_bits(b: u16) -> Self {
Self(b)
}
#[must_use]
pub const fn has(&self, flag: u16) -> bool {
(self.0 & flag) != 0
}
#[must_use]
pub const fn with(mut self, flag: u16) -> Self {
self.0 |= flag;
self
}
}
#[cfg(test)]
#[allow(clippy::expect_used, clippy::unwrap_used, clippy::panic)]
mod tests {
use super::*;
#[test]
fn flag_values_match_spec_table_24_1() {
assert_eq!(AssociationOptions::NO_PROTECTION, 1);
assert_eq!(AssociationOptions::INTEGRITY, 2);
assert_eq!(AssociationOptions::CONFIDENTIALITY, 4);
assert_eq!(AssociationOptions::DETECT_REPLAY, 8);
assert_eq!(AssociationOptions::DETECT_MISORDERING, 16);
assert_eq!(AssociationOptions::ESTABLISH_TRUST_IN_TARGET, 32);
assert_eq!(AssociationOptions::ESTABLISH_TRUST_IN_CLIENT, 64);
assert_eq!(AssociationOptions::NO_DELEGATION, 128);
assert_eq!(AssociationOptions::SIMPLE_DELEGATION, 256);
assert_eq!(AssociationOptions::COMPOSITE_DELEGATION, 512);
assert_eq!(AssociationOptions::IDENTITY_ASSERTION, 1024);
assert_eq!(AssociationOptions::DELEGATION_BY_CLIENT, 2048);
}
#[test]
fn has_and_with_round_trip() {
let ao = AssociationOptions::default()
.with(AssociationOptions::CONFIDENTIALITY)
.with(AssociationOptions::ESTABLISH_TRUST_IN_TARGET);
assert!(ao.has(AssociationOptions::CONFIDENTIALITY));
assert!(ao.has(AssociationOptions::ESTABLISH_TRUST_IN_TARGET));
assert!(!ao.has(AssociationOptions::IDENTITY_ASSERTION));
assert_eq!(ao.0, 4 | 32);
}
}