1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum EncryptionAlgorithm {
9 None,
10 Aes,
11}
12
13pub fn detect_encryption(fsp_flags: u32) -> EncryptionAlgorithm {
17 if (fsp_flags >> 13) & 0x01 != 0 {
18 EncryptionAlgorithm::Aes
19 } else {
20 EncryptionAlgorithm::None
21 }
22}
23
24pub fn is_encrypted(fsp_flags: u32) -> bool {
26 detect_encryption(fsp_flags) != EncryptionAlgorithm::None
27}
28
29impl std::fmt::Display for EncryptionAlgorithm {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 match self {
32 EncryptionAlgorithm::None => write!(f, "None"),
33 EncryptionAlgorithm::Aes => write!(f, "AES"),
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_detect_encryption() {
44 assert_eq!(detect_encryption(0), EncryptionAlgorithm::None);
45 assert_eq!(detect_encryption(1 << 13), EncryptionAlgorithm::Aes);
46 assert_eq!(detect_encryption(0xFF), EncryptionAlgorithm::None);
48 assert_eq!(detect_encryption(0xFF | (1 << 13)), EncryptionAlgorithm::Aes);
49 }
50
51 #[test]
52 fn test_is_encrypted() {
53 assert!(!is_encrypted(0));
54 assert!(is_encrypted(1 << 13));
55 }
56}