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