security_framework/os/macos/
transform.rs

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