Commit 9dd7b99d authored by Nick Mathewson's avatar Nick Mathewson 🦀
Browse files

Add serde derives for MistrustBuilder.

The Group and User (de)serialization is pretty ugly, and I can't
vouch for the correcness of MistrustBuilder.  I will seek feedback
before I proceed.
parent 330582a1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1204,6 +1204,7 @@ dependencies = [
 "educe",
 "libc",
 "once_cell",
 "serde",
 "tempfile",
 "thiserror",
 "users",
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ derive_builder = { version = "0.11", package = "derive_builder_fork_arti" }
educe = "0.4.6"
thiserror = "1"
walkdir = { version = "2", optional = true }
serde = { version = "1.0.103", features = ["derive"], optional = true }


[target.'cfg(unix)'.dependencies]
libc = "0.2"
+5 −0
Original line number Diff line number Diff line
@@ -283,6 +283,8 @@ mod user;
pub(crate) mod testing;
pub mod walk;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{
    fs::DirBuilder,
    path::{Path, PathBuf},
@@ -315,7 +317,10 @@ pub use user::{TrustedGroup, TrustedUser};
/// *  support more kinds of trust configuration, including more trusted users,
///    trusted groups, multiple trusted directories, etc?
#[derive(Debug, Clone, derive_builder::Builder)]
#[cfg_attr(feature = "serde", builder(derive(Debug, Serialize, Deserialize)))]
#[cfg_attr(not(feature = "serde"), builder(derive(Debug)))]
#[builder(build_fn(error = "Error"))]
#[cfg_attr(feature = "serde", builder_struct_attr(serde(default)))]
pub struct Mistrust {
    /// If the user called [`MistrustBuilder::ignore_prefix`], what did they give us?
    ///
+10 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

use crate::Error;
use once_cell::sync::Lazy;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{
    ffi::{OsStr, OsString},
    sync::Mutex,
@@ -80,7 +82,12 @@ fn cur_groups() -> Vec<u32> {
}

/// A user that we can be configured to trust.
//
// TODO: This thing is quite ugly to serialize and deserialize! Ideally I'd like
// something where I can say `33` for a number, `"user"` for a username... and I
// don't know what they should say for "Current" or "Nobody".
#[derive(Clone, Debug, educe::Educe, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[educe(Default)]
#[non_exhaustive]
pub enum TrustedUser {
@@ -144,7 +151,10 @@ impl TrustedUser {
}

/// A group that we can be configured to trust.
//
// TODO: See TODO for User above.
#[derive(Clone, Debug, educe::Educe, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[educe(Default)]
#[non_exhaustive]
pub enum TrustedGroup {