apple_security_framework/os/macos/
transform.rs

1//! Transform support
2
3use std::ptr;
4
5use core_foundation::{
6    base::{CFType, TCFType},
7    error::CFError,
8    string::CFString,
9};
10use security_framework_sys::transform::*;
11
12declare_TCFType! {
13    /// A type representing a transform.
14    SecTransform, SecTransformRef
15}
16impl_TCFType!(SecTransform, SecTransformRef, SecTransformGetTypeID);
17
18unsafe impl Sync for SecTransform {}
19unsafe impl Send for SecTransform {}
20
21impl SecTransform {
22    /// Sets an attribute of the transform.
23    pub fn set_attribute<T>(&mut self, key: &CFString, value: &T) -> Result<(), CFError>
24    where
25        T: TCFType,
26    {
27        unsafe {
28            let mut error = ptr::null_mut();
29            SecTransformSetAttribute(
30                self.0,
31                key.as_concrete_TypeRef(),
32                value.as_CFTypeRef(),
33                &mut error,
34            );
35            if !error.is_null() {
36                return Err(CFError::wrap_under_create_rule(error));
37            }
38
39            Ok(())
40        }
41    }
42
43    /// Executes the transform.
44    ///
45    /// The return type depends on the type of transform.
46    pub fn execute(&mut self) -> Result<CFType, CFError> {
47        unsafe {
48            let mut error = ptr::null_mut();
49            let result = SecTransformExecute(self.0, &mut error);
50            if result.is_null() {
51                return Err(CFError::wrap_under_create_rule(error));
52            }
53
54            Ok(CFType::wrap_under_create_rule(result))
55        }
56    }
57}