Skip to content

Commit

Permalink
Implement RuleSet for &RuleSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski authored and boustrophedon committed Jun 1, 2023
1 parent 8677c33 commit 62bd363
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ pub trait RuleSet {
fn name(&self) -> &'static str;
}

impl<T: ?Sized + RuleSet> RuleSet for &T {
#[inline]
fn simple_rules(&self) -> Vec<syscalls::Sysno> {
T::simple_rules(self)
}

#[inline]
fn conditional_rules(&self) -> HashMap<syscalls::Sysno, Vec<Rule>> {
T::conditional_rules(self)
}

#[inline]
fn name(&self) -> &'static str {
T::name(self)
}
}

#[must_use]
#[derive(Debug)]
/// A struct representing a set of rules to be loaded into a seccomp filter and applied to the
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ref_ruleset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use extrasafe::RuleSet;
use extrasafe::builtins::BasicCapabilities;

#[test]
/// Test if RuleSets can be references.
fn ref_ruleset() -> Result<(), extrasafe::ExtraSafeError> {
let ruleset: &dyn RuleSet = &BasicCapabilities;
extrasafe::SafetyContext::new().enable(ruleset)?.apply_to_current_thread()
}

0 comments on commit 62bd363

Please sign in to comment.