use gix_sec::Trust;
use crate::open::Permissions;
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
pub struct Config {
pub git_binary: bool,
pub system: bool,
pub git: bool,
pub user: bool,
pub env: bool,
pub includes: bool,
}
impl Config {
pub fn all() -> Self {
Config {
git_binary: false,
system: true,
git: true,
user: true,
env: true,
includes: true,
}
}
pub fn isolated() -> Self {
Config {
git_binary: false,
system: false,
git: false,
user: false,
env: false,
includes: false,
}
}
}
impl Default for Config {
fn default() -> Self {
Self::all()
}
}
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
pub struct Attributes {
pub git_binary: bool,
pub system: bool,
pub git: bool,
}
impl Attributes {
pub fn all() -> Self {
Attributes {
git_binary: false,
system: true,
git: true,
}
}
pub fn isolated() -> Self {
Attributes {
git_binary: false,
system: false,
git: false,
}
}
}
impl Default for Attributes {
fn default() -> Self {
Self::all()
}
}
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
pub struct Environment {
pub xdg_config_home: gix_sec::Permission,
pub home: gix_sec::Permission,
pub http_transport: gix_sec::Permission,
pub identity: gix_sec::Permission,
pub objects: gix_sec::Permission,
pub git_prefix: gix_sec::Permission,
pub ssh_prefix: gix_sec::Permission,
}
impl Environment {
pub fn all() -> Self {
let allow = gix_sec::Permission::Allow;
Environment {
xdg_config_home: allow,
home: allow,
git_prefix: allow,
ssh_prefix: allow,
http_transport: allow,
identity: allow,
objects: allow,
}
}
pub fn isolated() -> Self {
let deny = gix_sec::Permission::Deny;
Environment {
xdg_config_home: deny,
home: deny,
ssh_prefix: deny,
git_prefix: deny,
http_transport: deny,
identity: deny,
objects: deny,
}
}
}
impl Permissions {
pub fn secure() -> Self {
Permissions {
env: Environment::all(),
config: Config::all(),
attributes: Attributes::all(),
}
}
pub fn all() -> Self {
Permissions {
env: Environment::all(),
config: Config::all(),
attributes: Attributes::all(),
}
}
pub fn isolated() -> Self {
Permissions {
config: Config::isolated(),
attributes: Attributes::isolated(),
env: Environment::isolated(),
}
}
}
impl Permissions {
pub fn is_isolated(&self) -> bool {
*self == Self::isolated()
}
}
impl gix_sec::trust::DefaultForLevel for Permissions {
fn default_for_level(level: Trust) -> Self {
match level {
Trust::Full => Permissions::all(),
Trust::Reduced => Permissions::secure(),
}
}
}
impl Default for Permissions {
fn default() -> Self {
Permissions::secure()
}
}