gix_sec/
lib.rs

1//! A shared trust model for `gitoxide` crates.
2//!
3//! ## Feature Flags
4#![cfg_attr(
5    all(doc, feature = "document-features"),
6    doc = ::document_features::document_features!()
7)]
8#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
9// `unsafe_code` not forbidden because we need to interact with the libc
10#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
11
12use std::fmt::{Display, Formatter};
13
14/// A way to specify how 'safe' we feel about a resource, typically about a git repository.
15#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub enum Trust {
18    /// Caution is warranted when using the resource.
19    Reduced,
20    /// We have no doubts that this resource means no harm and it can be used at will.
21    Full,
22}
23
24///
25pub mod trust;
26
27/// Allow, deny or forbid using a resource or performing an action.
28#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub enum Permission {
31    /// Fail outright when trying to load a resource or performing an action.
32    Forbid,
33    /// Ignore resources or try to avoid performing an operation.
34    Deny,
35    /// Allow loading a resource or performing an action.
36    Allow,
37}
38
39///
40pub mod permission;
41
42bitflags::bitflags! {
43    /// Whether something can be read or written.
44    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
45    #[derive(Debug)]
46    pub struct ReadWrite: u8 {
47        /// The item can be read.
48        const READ = 1 << 0;
49        /// The item can be written
50        const WRITE = 1 << 1;
51    }
52}
53
54impl Display for ReadWrite {
55    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
56        std::fmt::Debug::fmt(self, f)
57    }
58}
59
60/// Various types to identify entities.
61pub mod identity;