Skip to main content

aranya_device_ffi/
lib.rs

1//! The `device` FFI module.
2
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![cfg_attr(not(any(test, doctest, feature = "std")), no_std)]
5#![warn(missing_docs)]
6
7mod tests;
8
9use core::convert::Infallible;
10
11use aranya_crypto::DeviceId;
12use aranya_policy_vm::{CommandContext, ffi::ffi};
13
14/// Implements the FFI `Device` module
15pub struct FfiDevice {
16    id: DeviceId,
17}
18
19#[ffi(module = "device")]
20impl FfiDevice {
21    /// Returns the current device's DeviceId
22    #[ffi_export(def = r#"function current_device_id() id"#)]
23    pub(crate) fn current_device_id<E: aranya_crypto::Engine>(
24        &self,
25        _ctx: &CommandContext,
26        _eng: &E,
27    ) -> Result<DeviceId, Infallible> {
28        Ok(self.id)
29    }
30}
31
32impl FfiDevice {
33    /// Constructor for FfiDevice that initializes it with a DeviceId
34    pub const fn new(id: DeviceId) -> Self {
35        Self { id }
36    }
37}