1use crate::new_policy::{ClassDefault, ClassDefaultRange, FsUseType};
6
7use bstr::BString;
8use thiserror::Error;
9
10#[derive(Clone, Debug, Error, PartialEq)]
12pub enum ParseError {
13 #[error("expected end of policy, but found {num_bytes} additional bytes")]
14 TrailingBytes { num_bytes: usize },
15 #[error("expected data item of type {type_name} ({type_size} bytes), but found {num_bytes}")]
16 MissingData { type_name: &'static str, type_size: usize, num_bytes: usize },
17 #[error(
18 "policy is of {observed} bytes, but this implementation only supports policies of up to {limit} bytes"
19 )]
20 UnsupportedlyLarge { observed: usize, limit: usize },
21 #[error("invalid ID value: {value}")]
22 InvalidId { value: u32 },
23}
24
25#[derive(Debug, Error, PartialEq)]
27pub enum ValidateError {
28 #[error(
29 "expected class default binary value to be one of {}, {}, or {}, but found {value}",
30 ClassDefault::Unspecified as u32,
31 ClassDefault::Source as u32,
32 ClassDefault::Target as u32
33 )]
34 InvalidClassDefault { value: u32 },
35 #[error(
36 "expected class default binary value to be one of {:?}, but found {value}",
37 [ClassDefaultRange::Unspecified as u32,
38 ClassDefaultRange::SourceLow as u32,
39 ClassDefaultRange::SourceHigh as u32,
40 ClassDefaultRange::SourceLowHigh as u32,
41 ClassDefaultRange::TargetLow as u32,
42 ClassDefaultRange::TargetHigh as u32,
43 ClassDefaultRange::TargetLowHigh as u32,
44 ClassDefaultRange::Glblub as u32]
45 )]
46 InvalidClassDefaultRange { value: u32 },
47 #[error("paths not ordered lexicographicaly")]
48 InvalidGenFsPathOrdering,
49 #[error("missing initial SID {initial_sid:?}")]
50 MissingInitialSid { initial_sid: crate::InitialSid },
51 #[error(
52 "invalid SELinux fs_use type; expected one of {:?}, but found {value}",
53 [FsUseType::Xattr as u32,
54 FsUseType::Trans as u32,
55 FsUseType::Task as u32]
56 )]
57 InvalidFsUseType { value: u32 },
58 #[error("non-optional Id field is zero")]
59 NonOptionalIdIsZero,
60 #[error("undefined {kind} Id value {id}")]
61 UnknownId { kind: &'static str, id: String },
62 #[error("invalid MLS range: {low}-{high}")]
63 InvalidMlsRange { low: BString, high: BString },
64}