feat(apps): permission manager equips apps (manifest+consent+decisions in /system), launches via init w/ file grant; shell unprivileged (/home); install/apps/allow/revoke; revoke stops running app; app-image tool; counter app
This commit is contained in:
@@ -19,6 +19,15 @@ macro_rules! catalog {
|
||||
}
|
||||
}
|
||||
|
||||
/// Its place in the catalog, as sent in a message word.
|
||||
pub fn index(self) -> usize {
|
||||
self as usize
|
||||
}
|
||||
|
||||
pub fn from_index(i: usize) -> Option<Self> {
|
||||
Capability::ALL.get(i).copied()
|
||||
}
|
||||
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
$(Capability::$variant => $name,)*
|
||||
@@ -65,6 +74,20 @@ pub struct Capabilities(u32);
|
||||
impl Capabilities {
|
||||
pub const NONE: Self = Self(0);
|
||||
|
||||
/// As sent in a message word.
|
||||
pub const fn bits(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// From a message word; bits past the catalog are dropped.
|
||||
pub fn from_bits(bits: u32) -> Self {
|
||||
Capability::ALL
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|c| bits & c.bit() != 0)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn with(self, c: Capability) -> Self {
|
||||
Self(self.0 | c.bit())
|
||||
}
|
||||
@@ -89,6 +112,11 @@ impl Capabilities {
|
||||
self.0 == 0
|
||||
}
|
||||
|
||||
/// Those in `self` but not in `other`.
|
||||
pub fn minus(self, other: Self) -> Self {
|
||||
Self(self.0 & !other.0)
|
||||
}
|
||||
|
||||
/// Whether every capability in `self` is in `other`.
|
||||
pub fn is_subset(self, other: Self) -> bool {
|
||||
self.0 & !other.0 == 0
|
||||
|
||||
@@ -36,7 +36,8 @@ impl<const N: usize> core::fmt::Debug for Text<N> {
|
||||
|
||||
impl<const N: usize> core::fmt::Display for Text<N> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
// `pad`, so `{:<20}` and the like line columns up.
|
||||
f.pad(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ impl AppId {
|
||||
|
||||
impl core::fmt::Display for AppId {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
f.pad(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user