Debian Codegraph @

src/common/mod.rs

raw symbols SCIP
1 #![forbid(unsafe_code)]
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#;
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/, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
5
6 pub use commandrust-analyzer cargo sudo-rs 0.2.14 common/command/::CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#;
7 pub use contextrust-analyzer cargo sudo-rs 0.2.14 common/context/::Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#;
8 pub use errorrust-analyzer cargo sudo-rs 0.2.14 common/error/::Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#;
9 pub use pathrust-analyzer cargo sudo-rs 0.2.14 common/path/::SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#;
10 pub use stringrust-analyzer cargo sudo-rs 0.2.14 common/string/::SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#;
11
12 pub mod bin_serderust-analyzer cargo sudo-rs 0.2.14 common/bin_serde/;
13 pub mod commandrust-analyzer cargo sudo-rs 0.2.14 common/command/;
14 pub mod contextrust-analyzer cargo sudo-rs 0.2.14 common/context/;
15 pub mod errorrust-analyzer cargo sudo-rs 0.2.14 common/error/;
16 mod pathrust-analyzer cargo sudo-rs 0.2.14 common/path/;
17 pub mod resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/;
18 mod stringrust-analyzer cargo sudo-rs 0.2.14 common/string/;
19
20 // Hardened enum values used for critical enums to mitigate attacks like Rowhammer.
21 // See for example https://arxiv.org/pdf/2309.02545.pdf
22 // The values are copied from https://github.com/sudo-project/sudo/commit/7873f8334c8d31031f8cfa83bd97ac6029309e4f#diff-b8ac7ab4c3c4a75aed0bb5f7c5fd38b9ea6c81b7557f775e46c6f8aa115e02cd
23 pub const HARDENED_ENUM_VALUE_0rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_0.: u32 = 0x52a2925; // 0101001010100010100100100101
24 pub const HARDENED_ENUM_VALUE_1rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_1.: u32 = 0xad5d6da; // 1010110101011101011011011010
25 pub const HARDENED_ENUM_VALUE_2rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_2.: u32 = 0x69d61fc8; // 1101001110101100001111111001000
26 pub const HARDENED_ENUM_VALUE_3rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_3.: u32 = 0x1629e037; // 0010110001010011110000000110111
27 pub const HARDENED_ENUM_VALUE_4rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_4.: u32 = 0x1fc8d3ac; // 11111110010001101001110101100
28 pub const HARDENED_ENUM_VALUE_5rust-analyzer cargo sudo-rs 0.2.14 common/HARDENED_ENUM_VALUE_5.: u32 = 0x70372c52; // 1110000001101110010110001010011
29
30 // FIXME replace with OsStr::display() once our MSRV is 1.87
31 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#<'a>(pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) &'a OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#);
32
33 impl fmtrust-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# for DisplayOsStrrust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#<'_> {
34 fn fmtrust-analyzer cargo sudo-rs 0.2.14 common/impl#[`DisplayOsStr<'_>`][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# {
35 for chunk in self.0rust-analyzer cargo sudo-rs 0.2.14 common/DisplayOsStr#0..as_encoded_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]as_encoded_bytes().().utf8_chunksrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/lossy/impl#[`[u8]`]utf8_chunks().() {
36 let valid = chunk.validrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/lossy/impl#[`Utf8Chunk<'a>`]valid().();
37 // If we successfully decoded the whole chunk as a valid string then
38 // we can return a direct formatting of the string which will also
39 // respect various formatting flags if possible.
40 if chunk.invalidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/lossy/impl#[`Utf8Chunk<'a>`]invalid().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
41 return valid.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Display]fmt().(f);
42 }
43
44 f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(valid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
45 f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(char::REPLACEMENT_CHARACTERrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]REPLACEMENT_CHARACTER.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46 }
47 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
48 }
49 }