Commit 12f02ba6 authored by Thomas Mühlbacher's avatar Thomas Mühlbacher
Browse files

zp: Assert auto trait impls for pub items

Closes #140.
parent d4180597
......@@ -19,3 +19,4 @@ zvariant = { path = "../zvariant", version = "2", default-features = false, feat
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
enumflags2 = { version = "0.6.4", features = ["serde"] }
static_assertions = "1.1.0"
use std::fmt::Display;
use static_assertions::assert_impl_all;
/// The error type for `zbus_polkit`.
///
/// The various errors that can be reported by this crate.
......@@ -18,6 +20,8 @@ pub enum Error {
MissingSender,
}
assert_impl_all!(Error: Send, Sync, Unpin);
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Error::Io(error)
......
......@@ -3,6 +3,7 @@ use std::{collections::HashMap, convert::TryFrom, io::BufRead, result::Result};
use enumflags2::BitFlags;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use static_assertions::assert_impl_all;
use zbus::{dbus_proxy, fdo};
use zvariant::{derive::Type, OwnedValue, Value};
......@@ -18,6 +19,8 @@ pub enum CheckAuthorizationFlags {
AllowUserInteraction = 0x01,
}
assert_impl_all!(CheckAuthorizationFlags: Send, Sync, Unpin);
/// An enumeration for granting implicit authorizations.
#[repr(u32)]
#[derive(Deserialize_repr, Serialize_repr, Type, Debug, PartialEq)]
......@@ -36,6 +39,8 @@ pub enum ImplicitAuthorization {
Authorized = 5,
}
assert_impl_all!(ImplicitAuthorization: Send, Sync, Unpin);
/// Flags describing features supported by the Authority implementation.
#[repr(u32)]
#[derive(Type, BitFlags, Debug, PartialEq, Copy, Clone, Serialize, Deserialize)]
......@@ -44,6 +49,8 @@ pub enum AuthorityFeatures {
TemporaryAuthorization = 0x01,
}
assert_impl_all!(AuthorityFeatures: Send, Sync, Unpin);
impl TryFrom<OwnedValue> for AuthorityFeatures {
type Error = <u32 as TryFrom<OwnedValue>>::Error;
......@@ -76,6 +83,8 @@ pub struct TemporaryAuthorization {
pub time_expires: u64,
}
assert_impl_all!(TemporaryAuthorization: Send, Sync, Unpin);
/// This struct describes identities such as UNIX users and UNIX groups. It is typically used to
/// check if a given process is authorized for an action.
///
......@@ -91,6 +100,8 @@ pub struct Identity<'a> {
pub identity_details: &'a HashMap<&'a str, Value<'a>>,
}
assert_impl_all!(Identity<'_>: Send, Sync, Unpin);
fn pid_start_time(pid: u32) -> Result<u64, Error> {
let fname = format!("/proc/{}/stat", pid);
let content = std::fs::read_to_string(fname)?;
......@@ -145,6 +156,8 @@ pub struct Subject {
pub subject_details: HashMap<String, OwnedValue>,
}
assert_impl_all!(Subject: Send, Sync, Unpin);
impl Subject {
/// Create a `Subject` for `pid`, `start_time` & `uid`.
///
......@@ -244,6 +257,8 @@ pub struct ActionDescription {
pub annotations: HashMap<String, String>,
}
assert_impl_all!(ActionDescription: Send, Sync, Unpin);
/// Describes the result of calling `CheckAuthorization()`
#[derive(Debug, Type, Serialize, Deserialize)]
pub struct AuthorizationResult {
......@@ -264,6 +279,8 @@ pub struct AuthorizationResult {
pub details: std::collections::HashMap<String, String>,
}
assert_impl_all!(AuthorizationResult: Send, Sync, Unpin);
/// This D-Bus interface is implemented by the /org/freedesktop/PolicyKit1/Authority object on the
/// well-known name org.freedesktop.PolicyKit1 on the system message bus.
#[dbus_proxy(
......@@ -427,3 +444,6 @@ trait Authority {
#[dbus_proxy(property)]
fn backend_version(&self) -> fdo::Result<String>;
}
assert_impl_all!(AsyncAuthorityProxy<'_>: Send, Sync, Unpin);
assert_impl_all!(AuthorityProxy<'_>: Send, Sync, Unpin);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment