objc2-authentication-services 0.3.2

Bindings to the AuthenticationServices 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::*;

use crate::*;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/ascredentialidentitystoreerrordomain?language=objc)
    pub static ASCredentialIdentityStoreErrorDomain: &'static NSErrorDomain;
}

/// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/ascredentialidentitystoreerrorcode?language=objc)
// NS_ERROR_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ASCredentialIdentityStoreErrorCode(pub NSInteger);
impl ASCredentialIdentityStoreErrorCode {
    #[doc(alias = "ASCredentialIdentityStoreErrorCodeInternalError")]
    pub const InternalError: Self = Self(0);
    #[doc(alias = "ASCredentialIdentityStoreErrorCodeStoreDisabled")]
    pub const StoreDisabled: Self = Self(1);
    #[doc(alias = "ASCredentialIdentityStoreErrorCodeStoreBusy")]
    pub const StoreBusy: Self = Self(2);
}

unsafe impl Encode for ASCredentialIdentityStoreErrorCode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for ASCredentialIdentityStoreErrorCode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/ascredentialidentitytypes?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ASCredentialIdentityTypes(pub NSUInteger);
bitflags::bitflags! {
    impl ASCredentialIdentityTypes: NSUInteger {
        #[doc(alias = "ASCredentialIdentityTypesAll")]
        const All = 0;
        #[doc(alias = "ASCredentialIdentityTypesPassword")]
        const Password = 1;
        #[doc(alias = "ASCredentialIdentityTypesPasskey")]
        const Passkey = 1<<1;
        #[doc(alias = "ASCredentialIdentityTypesOneTimeCode")]
        const OneTimeCode = 1<<2;
    }
}

unsafe impl Encode for ASCredentialIdentityTypes {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for ASCredentialIdentityTypes {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/ascredentialidentitystore?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct ASCredentialIdentityStore;
);

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

impl ASCredentialIdentityStore {
    extern_methods!(
        #[unsafe(method(sharedStore))]
        #[unsafe(method_family = none)]
        pub unsafe fn sharedStore() -> Retained<ASCredentialIdentityStore>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(all(feature = "ASCredentialIdentityStoreState", feature = "block2"))]
        /// Get the state of the credential identity store.
        ///
        /// Parameter `completion`: completion handler to be called with the current state of the store.
        ///
        /// Call this method to find out the current state of the store before attempting to call other store methods.
        /// Use the provided ASCredentialIdentityStoreState to find out if the store is enabled and whether it supports incremental
        /// updates.
        #[unsafe(method(getCredentialIdentityStoreStateWithCompletion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getCredentialIdentityStoreStateWithCompletion(
            &self,
            completion: &block2::DynBlock<dyn Fn(NonNull<ASCredentialIdentityStoreState>)>,
        );

        #[cfg(all(
            feature = "ASCredentialIdentity",
            feature = "ASCredentialServiceIdentifier",
            feature = "block2"
        ))]
        /// List the currently saved credential identities.
        ///
        /// Parameter `serviceIdentifier`: Specify a service identifier to get only credential identities for that service.
        /// Pass nil to get credential identities for all services.
        ///
        /// Parameter `credentialIdentityTypes`: Specify one or more types to get only credential identities of those types.
        /// Pass ASCredentialIdentityTypesAll to get credential identities of all types.
        ///
        /// Call this method to get a list of all credential identities saved in the store for your extension.
        #[unsafe(method(getCredentialIdentitiesForService:credentialIdentityTypes:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getCredentialIdentitiesForService_credentialIdentityTypes_completionHandler(
            &self,
            service_identifier: Option<&ASCredentialServiceIdentifier>,
            credential_identity_types: ASCredentialIdentityTypes,
            completion_handler: &block2::DynBlock<
                dyn Fn(NonNull<NSArray<ProtocolObject<dyn ASCredentialIdentity>>>),
            >,
        );

        #[cfg(all(feature = "ASPasswordCredentialIdentity", feature = "block2"))]
        /// Save the given credential identities to the store.
        ///
        /// Parameter `credentialIdentities`: array of ASPasswordCredentialIdentity objects to save to the store.
        ///
        /// Parameter `completion`: optional completion handler to be called after adding the credential identities.
        /// If the operation fails, an error with domain ASCredentialIdentityStoreErrorDomain will be provided
        /// and none of the objects in credentialIdentities will be saved to the store.
        ///
        /// If the store supports incremental updates, call this method to add new credential
        /// identities since the last time the store was updated. Otherwise, call this method to pass all credential
        /// identities.
        /// If some credential identities in credentialIdentities already exist in the store, they will be replaced by
        /// those from credentialIdentities.
        #[deprecated]
        #[unsafe(method(saveCredentialIdentities:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn saveCredentialIdentities_completion(
            &self,
            credential_identities: &NSArray<ASPasswordCredentialIdentity>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(all(feature = "ASCredentialIdentity", feature = "block2"))]
        /// Save the given credential identities to the store.
        ///
        /// Parameter `credentialIdentities`: array of ASCredentialIdentity objects to save to the store.
        ///
        /// Parameter `completion`: optional completion handler to be called after adding the credential identities.
        /// If the operation fails, an error with domain ASCredentialIdentityStoreErrorDomain will be provided
        /// and none of the objects in credentialIdentities will be saved to the store.
        ///
        /// If the store supports incremental updates, call this method to add new credential
        /// identities since the last time the store was updated. Otherwise, call this method to pass all credential
        /// identities.
        /// If some credential identities in credentialIdentities already exist in the store, they will be replaced by
        /// those from credentialIdentities.
        #[unsafe(method(saveCredentialIdentityEntries:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn saveCredentialIdentityEntries_completion(
            &self,
            credential_identities: &NSArray<ProtocolObject<dyn ASCredentialIdentity>>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(all(feature = "ASPasswordCredentialIdentity", feature = "block2"))]
        /// Remove the given credential identities from the store.
        ///
        /// Parameter `credentialIdentities`: array of ASPasswordCredentialIdentity objects to remove from the store.
        ///
        /// Parameter `completion`: optional completion handler to be called after removing the credential identities.
        /// If the operation fails, an error with domain ASCredentialIdentityStoreErrorDomain will be provided
        /// and none of the objects in credentialIdentities will be removed from the store.
        ///
        /// Use this method only if the store supports incremental updates to remove previously added
        /// credentials to the store.
        #[deprecated]
        #[unsafe(method(removeCredentialIdentities:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeCredentialIdentities_completion(
            &self,
            credential_identities: &NSArray<ASPasswordCredentialIdentity>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(all(feature = "ASCredentialIdentity", feature = "block2"))]
        /// Remove the given credential identities from the store.
        ///
        /// Parameter `credentialIdentities`: array of ASCredentialIdentity objects to remove from the store.
        ///
        /// Parameter `completion`: optional completion handler to be called after removing the credential identities.
        /// If the operation fails, an error with domain ASCredentialIdentityStoreErrorDomain will be provided
        /// and none of the objects in credentialIdentities will be removed from the store.
        ///
        /// Use this method only if the store supports incremental updates to remove previously added
        /// credentials to the store.
        #[unsafe(method(removeCredentialIdentityEntries:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeCredentialIdentityEntries_completion(
            &self,
            credential_identities: &NSArray<ProtocolObject<dyn ASCredentialIdentity>>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Remove all existing credential identities from the store.
        ///
        /// Parameter `completion`: optional completion handler to be called after removing all existing credential identities.
        /// If the operation fails, an error with domain ASCredentialIdentityStoreErrorDomain will be provided and none of
        /// the existing credential identities will be removed from the store.
        #[unsafe(method(removeAllCredentialIdentitiesWithCompletion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeAllCredentialIdentitiesWithCompletion(
            &self,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(all(feature = "ASPasswordCredentialIdentity", feature = "block2"))]
        /// Replace existing credential identities with new credential identities.
        ///
        /// Parameter `newCredentialIdentities`: array of new credential identity objects to replace the old ones.
        ///
        /// Parameter `completion`: an optional completion block to be called after the operation is finished.
        ///
        /// This method will delete all existing credential identities that are persisted in the
        /// store and replace them with the provided array of credential identities. If the operation fails, an
        /// error with domain ASCredentialIdentityStoreErrorDomain will be provided and none of the new credential
        /// identities will be saved.
        #[deprecated]
        #[unsafe(method(replaceCredentialIdentitiesWithIdentities:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn replaceCredentialIdentitiesWithIdentities_completion(
            &self,
            new_credential_identities: &NSArray<ASPasswordCredentialIdentity>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(all(feature = "ASCredentialIdentity", feature = "block2"))]
        /// Replace existing credential identities with new credential identities.
        ///
        /// Parameter `newCredentialIdentities`: array of new credential identity objects to replace the old ones.
        ///
        /// Parameter `completion`: an optional completion block to be called after the operation is finished.
        ///
        /// This method will delete all existing credential identities that are persisted in the
        /// store and replace them with the provided array of credential identities. If the operation fails, an
        /// error with domain ASCredentialIdentityStoreErrorDomain will be provided and none of the new credential
        /// identities will be saved.
        #[unsafe(method(replaceCredentialIdentityEntries:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn replaceCredentialIdentityEntries_completion(
            &self,
            new_credential_identities: &NSArray<ProtocolObject<dyn ASCredentialIdentity>>,
            completion: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );
    );
}

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