SecurityPolicy

Struct SecurityPolicy 

Source
pub struct SecurityPolicy {
    pub allow_unsafe_code: bool,
    pub require_signatures: bool,
    pub min_trust_level: u8,
    pub max_complexity: u32,
    pub dangerous_permissions: Vec<String>,
    pub restricted_apis: Vec<String>,
}
Expand description

Security policy configuration for the plugin system

The SecurityPolicy defines the security requirements and restrictions for plugin validation and execution. It provides configurable security levels to balance functionality with safety requirements.

§Security Levels

  • Strict: Maximum security with signature requirements and minimal permissions
  • Standard: Balanced security for production environments
  • Permissive: Relaxed security for development and testing

§Examples

use sklears_core::plugin::{SecurityPolicy, Permission};

// Create a strict security policy
let strict_policy = SecurityPolicy::strict();
assert!(strict_policy.require_signatures);
assert!(!strict_policy.allow_unsafe_code);

// Create a custom policy
let custom_policy = SecurityPolicy {
    allow_unsafe_code: false,
    require_signatures: true,
    min_trust_level: 7,
    max_complexity: 15,
    dangerous_permissions: vec![
        "file_system_write".to_string(),
        "network_access".to_string(),
    ],
    restricted_apis: vec![
        "std::process::Command".to_string(),
    ],
};

Fields§

§allow_unsafe_code: bool

Whether to allow plugins with unsafe code blocks

§require_signatures: bool

Whether digital signatures are required for plugins

§min_trust_level: u8

Minimum trust level required for plugin publishers (0-10)

§max_complexity: u32

Maximum allowed cyclomatic complexity for plugin code

§dangerous_permissions: Vec<String>

List of dangerous permissions that trigger warnings

§restricted_apis: Vec<String>

List of restricted API patterns that are not allowed

Implementations§

Source§

impl SecurityPolicy

Source

pub fn strict() -> Self

Create a strict security policy suitable for production environments

This policy provides maximum security with signature requirements, no unsafe code, and minimal dangerous permissions.

§Examples
use sklears_core::plugin::SecurityPolicy;

let policy = SecurityPolicy::strict();
assert!(policy.require_signatures);
assert!(!policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 8);
Source

pub fn standard() -> Self

Create a standard security policy for typical production use

Balances security with functionality, allowing more flexibility than strict mode while maintaining essential protections.

§Examples
use sklears_core::plugin::SecurityPolicy;

let policy = SecurityPolicy::standard();
assert!(policy.require_signatures);
assert!(!policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 5);
Source

pub fn permissive() -> Self

Create a permissive security policy for development and testing

Provides minimal security restrictions to enable rapid development and testing. Should not be used in production environments.

§Examples
use sklears_core::plugin::SecurityPolicy;

let policy = SecurityPolicy::permissive();
assert!(!policy.require_signatures);
assert!(policy.allow_unsafe_code);
assert_eq!(policy.min_trust_level, 0);
Source

pub fn is_dangerous_permission(&self, permission: &Permission) -> bool

Check if a permission is considered dangerous

Dangerous permissions are those that could potentially be used maliciously or cause system damage if misused.

§Arguments
  • permission - The permission to check
§Returns

true if the permission is considered dangerous, false otherwise.

§Examples
use sklears_core::plugin::{SecurityPolicy, Permission};

let policy = SecurityPolicy::standard();
assert!(policy.is_dangerous_permission(&Permission::FileSystemWrite));
assert!(!policy.is_dangerous_permission(&Permission::FileSystemRead));
Source

pub fn is_restricted_api(&self, api: &str) -> bool

Check if an API call is restricted

Restricted APIs are those that are prohibited from use in plugins due to security concerns or system stability issues.

§Arguments
  • api - The API call pattern to check
§Returns

true if the API is restricted, false otherwise.

§Examples
use sklears_core::plugin::SecurityPolicy;

let policy = SecurityPolicy::standard();
assert!(policy.is_restricted_api("std::process::Command"));
assert!(!policy.is_restricted_api("std::fs::read_to_string"));
Source

pub fn add_dangerous_permission(&mut self, permission: String)

Add a dangerous permission to the policy

§Arguments
  • permission - The permission name to add as dangerous
Source

pub fn remove_dangerous_permission(&mut self, permission: &str)

Remove a dangerous permission from the policy

§Arguments
  • permission - The permission name to remove from dangerous list
Source

pub fn add_restricted_api(&mut self, api_pattern: String)

Add a restricted API pattern to the policy

§Arguments
  • api_pattern - The API pattern to restrict
Source

pub fn remove_restricted_api(&mut self, api_pattern: &str)

Remove a restricted API pattern from the policy

§Arguments
  • api_pattern - The API pattern to remove from restrictions
Source

pub fn validate(&self) -> Result<()>

Validate the policy configuration

Ensures that the policy configuration is consistent and valid.

§Returns

Ok(()) if the policy is valid, error otherwise.

Trait Implementations§

Source§

impl Clone for SecurityPolicy

Source§

fn clone(&self) -> SecurityPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecurityPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SecurityPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V