summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src/policy.rs
blob: d1857796c7d1cf3ab288fac13788154e8bcbc590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Policy objects.
//!
//! This module allows the caller to specify low-level policy like
//! what algorithms are allowed.
//!
//! Wraps the policy object functions, see
//! [`sequoia-openpgp::policy`].
//!
//! [`sequoia-openpgp::policy`]: ../../sequoia_openpgp/policy/index.html

use sequoia_openpgp as openpgp;

use crate::MoveIntoRaw;

use self::openpgp::policy;

/// A policy object.
#[crate::ffi_wrapper_type(
    prefix = "pgp_",
    derive = "Clone, Debug")]
pub struct Policy(Box<dyn policy::Policy>);

/// A StandardPolicy object.
#[crate::ffi_wrapper_type(
    prefix = "pgp_",
    derive = "Clone, Debug")]
pub struct StandardPolicy<'a>(policy::StandardPolicy<'a>);

/// A NullPolicy object.
#[crate::ffi_wrapper_type(
    prefix = "pgp_",
    derive = "Clone, Debug")]
pub struct NullPolicy(policy::NullPolicy);

/// Returns a new standard policy.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "C" fn pgp_standard_policy()
    -> *mut Policy
{
    let p : Box<dyn policy::Policy> = Box::new(policy::StandardPolicy::new());
    p.move_into_raw()
}

/// Returns a new null policy.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "C" fn pgp_null_policy()
    -> *mut Policy
{
    let p : Box<dyn policy::Policy> = Box::new(policy::NullPolicy::new());
    p.move_into_raw()
}