| 1 | #[cfg(feature = "serde")] |
| 2 | use serde_withrust-analyzer cargo serde_with 3.21.0 crate/::{DeserializeFromStrrust-analyzer cargo serde_with_macros 3.21.0 DeserializeFromStr:, SerializeDisplayrust-analyzer cargo serde_with_macros 3.21.0 SerializeDisplay:}; |
| 3 | |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#}; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 6 | |
| 7 | use thiserrorrust-analyzer cargo thiserror 2.0.18 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:; |
| 8 | |
| 9 | /// The identifier of an audit event, corresponding to the |
| 10 | /// `msg=audit(…)` part of every Linux Audit log line. |
| 11 | /// |
| 12 | /// The event ID can reasonably be expected to be unique per system. |
| 13 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 14 | #[cfg_attr(feature = "serde", derive(DeserializeFromStrrust-analyzer cargo serde_with_macros 3.21.0 DeserializeFromStr:, SerializeDisplayrust-analyzer cargo serde_with_macros 3.21.0 SerializeDisplay:))] |
| 15 | pub struct EventIDrust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID# { |
| 16 | /// Unix epoch-based timestamp, with mullisecond-precision |
| 17 | pub timestamprust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#timestamp.: u64, |
| 18 | /// Sequence number |
| 19 | pub sequencerust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#sequence.: u32, |
| 20 | } |
| 21 | |
| 22 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for EventIDrust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID# { |
| 23 | fn fmtrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 24 | let sec = self.timestamprust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#timestamp. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().1000; |
| 25 | let msec = self.timestamprust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#timestamp. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().1000; |
| 26 | let seq = self.sequencerust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#sequence.; |
| 27 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{sec}.{msec:03}:{seq}") |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /// The error type returned by [EventID::from_str] |
| 32 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:)] |
| 33 | pub enum ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError# { |
| 34 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("wrong format (character '{0}' not found)")] |
| 35 | Formatrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Format#(char), |
| 36 | #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("cannot parse number: {0}")] |
| 37 | Numberrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Number#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::ParseIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/ParseIntError#), |
| 38 | } |
| 39 | |
| 40 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for EventIDrust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID# { |
| 41 | type Errrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][FromStr]Err# = ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#; |
| 42 | fn from_strrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][FromStr], Selfrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 43 | let (sec, rest) = s.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('.').ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#::Formatrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Format#('.'))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 44 | let (msec, seq) = rest.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(':').ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#::Formatrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Format#(':'))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 45 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(EventIDrust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID# { |
| 46 | timestamprust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#timestamp.: u64::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64][FromStr]from_str().(sec).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#::Numberrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Number#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().1000 |
| 47 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().u64::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64][FromStr]from_str().(msec).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#::Numberrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Number#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 48 | sequencerust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID#sequence.: u32::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32][FromStr]from_str().(seq).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ParseEventIDErrorrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#::Numberrust-analyzer cargo linux-audit-parser 0.2.8 event_id/ParseEventIDError#Number#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 49 | }) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<str> for EventIDrust-analyzer cargo linux-audit-parser 0.2.8 event_id/EventID# { |
| 54 | fn eqrust-analyzer cargo linux-audit-parser 0.2.8 event_id/impl#[EventID][`PartialEq<str>`]eq().(&self, other: &str) -> bool { |
| 55 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{self}") rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().other |
| 56 | } |
| 57 | } |