objc2-security-foundation 0.3.2

Bindings to the SecurityFoundation framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-security")]
use objc2_security::*;

use crate::*;

extern_class!(
    /// SFAuthorization APIs are used for implementing access control in applications and daemons. It has NSCoder support for proxied objects SFAuthorization is a wrapper for using the Authorization API.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/securityfoundation/sfauthorization?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SFAuthorization;
);

extern_conformance!(
    unsafe impl NSCoding for SFAuthorization {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SFAuthorization {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for SFAuthorization {}
);

impl SFAuthorization {
    extern_methods!(
        /// Returns an authorization object initialized with a default environment, flags and rights.
        #[unsafe(method(authorization))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorization() -> Option<Retained<AnyObject>>;

        #[cfg(feature = "objc2-security")]
        /// Returns the AuthorizationRef for this SFAuthorization.
        #[unsafe(method(authorizationRef))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationRef(&self) -> AuthorizationRef;

        #[cfg(feature = "objc2-security")]
        /// Returns an authorization object initialized with the specified flags, rights and environment.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// Parameter `rights`: (input/optional) An AuthorizationItemSet containing rights for which authorization is being requested.  If none are specified the resulting AuthorizationRef will authorize nothing at all.
        ///
        /// Parameter `environment`: (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision.  See the AuthorizationEnvironment type for details.
        ///
        /// # Safety
        ///
        /// - `rights` must be a valid pointer.
        /// - `environment` must be a valid pointer.
        #[unsafe(method(authorizationWithFlags:rights:environment:))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationWithFlags_rights_environment(
            flags: AuthorizationFlags,
            rights: *const AuthorizationRights,
            environment: *const AuthorizationEnvironment,
        ) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "objc2-security")]
        /// Initializes an authorization object specified flags, rights and environment.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// Parameter `rights`: (input/optional) An AuthorizationItemSet containing rights for which authorization is being requested.  If none are specified the resulting AuthorizationRef will authorize nothing at all.
        ///
        /// Parameter `environment`: (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision.  See the AuthorizationEnvironment type for details.
        ///
        /// # Safety
        ///
        /// - `rights` must be a valid pointer.
        /// - `environment` must be a valid pointer.
        #[unsafe(method(initWithFlags:rights:environment:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFlags_rights_environment(
            this: Allocated<Self>,
            flags: AuthorizationFlags,
            rights: *const AuthorizationRights,
            environment: *const AuthorizationEnvironment,
        ) -> Option<Retained<Self>>;

        /// Initializes an authorization object initialized with a default environment, flags and rights.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Calling this will prevent any rights that were obtained by this object to be preserved. It effectively locks down all potentially shared authorizations.
        #[unsafe(method(invalidateCredentials))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateCredentials(&self);

        #[cfg(feature = "objc2-security")]
        /// Call obtainWithRight to gain a right to have access to a privilege operation. On success, YES is returned.
        ///
        /// Parameter `rightName`: The name of an authorization right.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// Parameter `error`: Resulting error.
        ///
        /// # Safety
        ///
        /// - `right_name` must be a valid pointer.
        /// - `error` might not allow `None`.
        #[unsafe(method(obtainWithRight:flags:error:))]
        #[unsafe(method_family = none)]
        pub unsafe fn obtainWithRight_flags_error(
            &self,
            right_name: AuthorizationString,
            flags: AuthorizationFlags,
            error: Option<&mut Option<Retained<NSError>>>,
        ) -> bool;

        #[cfg(feature = "objc2-security")]
        /// Call obtainWithRights to gain the rights to have access to privileged operations. On success, YES is returned.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// Parameter `rights`: (input) A rights set (see AuthorizationCreate).
        ///
        /// Parameter `environment`: (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision.  See the AuthorizationEnvironment type for details.
        ///
        /// Parameter `authorizedRights`: (output/optional) A pointer to a newly allocated AuthorizationInfoSet in which the authorized subset of rights are returned (authorizedRights should be deallocated by calling AuthorizationFreeInfoSet() when it is no longer needed).  If NULL the only information returned is the status.  Note that if the kAuthorizationFlagPreAuthorize flag was specified rights that could not be preauthorized are returned in authorizedRights, but their flags contains the kAuthorizationFlagCanNotPreAuthorize bit.
        ///
        /// Parameter `error`: Resulting error.
        ///
        /// # Safety
        ///
        /// - `rights` must be a valid pointer.
        /// - `environment` must be a valid pointer.
        /// - `authorized_rights` must be a valid pointer.
        /// - `error` might not allow `None`.
        #[unsafe(method(obtainWithRights:flags:environment:authorizedRights:error:))]
        #[unsafe(method_family = none)]
        pub unsafe fn obtainWithRights_flags_environment_authorizedRights_error(
            &self,
            rights: *const AuthorizationRights,
            flags: AuthorizationFlags,
            environment: *const AuthorizationEnvironment,
            authorized_rights: *mut *mut AuthorizationRights,
            error: Option<&mut Option<Retained<NSError>>>,
        ) -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
impl SFAuthorization {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// SFAuthorizationDeprecated.
impl SFAuthorization {
    extern_methods!(
        #[cfg(feature = "objc2-security")]
        /// DEPRECATED: Use obtainWithRights:flags:environment:authorizedRights:error:
        ///
        ///
        /// Call permitWithRights to gain the rights to have access to privileged operations and to obtain the result.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// Parameter `rights`: (input) A rights set (see AuthorizationCreate).
        ///
        /// Parameter `environment`: (input/optional) An AuthorizationItemSet containing enviroment state used when making the autorization decision.  See the AuthorizationEnvironment type for details.
        ///
        /// Parameter `authorizedRights`: (output/optional) A pointer to a newly allocated AuthorizationInfoSet in which the authorized subset of rights are returned (authorizedRights should be deallocated by calling AuthorizationFreeInfoSet() when it is no longer needed).  If NULL the only information returned is the status.  Note that if the kAuthorizationFlagPreAuthorize flag was specified rights that could not be preauthorized are returned in authorizedRights, but their flags contains the kAuthorizationFlagCanNotPreAuthorize bit.
        ///
        /// # Safety
        ///
        /// - `rights` must be a valid pointer.
        /// - `environment` must be a valid pointer.
        /// - `authorized_rights` must be a valid pointer.
        #[deprecated]
        #[unsafe(method(permitWithRights:flags:environment:authorizedRights:))]
        #[unsafe(method_family = none)]
        pub unsafe fn permitWithRights_flags_environment_authorizedRights(
            &self,
            rights: *const AuthorizationRights,
            flags: AuthorizationFlags,
            environment: *const AuthorizationEnvironment,
            authorized_rights: *mut AuthorizationRights,
        ) -> OSStatus;

        #[cfg(feature = "objc2-security")]
        /// DEPRECATED: Use obtainWithRight:flags:error:
        ///
        ///
        /// Call permitWithRight to gain a right to have access to a privilege operation.
        ///
        /// Parameter `rightName`: The name of an authorization right.
        ///
        /// Parameter `flags`: Authorization flags.
        ///
        /// # Safety
        ///
        /// `right_name` must be a valid pointer.
        #[deprecated]
        #[unsafe(method(permitWithRight:flags:))]
        #[unsafe(method_family = none)]
        pub unsafe fn permitWithRight_flags(
            &self,
            right_name: AuthorizationString,
            flags: AuthorizationFlags,
        ) -> OSStatus;
    );
}