objc2-crypto-token-kit 0.3.2

Bindings to the CryptoTokenKit 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!(
    /// Base interface for propagation token's items into the keychain.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktokenkeychainitem?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKTokenKeychainItem;
);

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

impl TKTokenKeychainItem {
    extern_methods!(
        #[cfg(feature = "TKToken")]
        /// Initializes item with objectID.
        ///
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(initWithObjectID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithObjectID(
            this: Allocated<Self>,
            object_id: &TKTokenObjectID,
        ) -> Retained<Self>;

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

        #[cfg(feature = "TKToken")]
        /// object ID for item identification
        #[unsafe(method(objectID))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectID(&self) -> Retained<TKTokenObjectID>;

        /// Contains the user-visible label for this item.  This property is an equivalent of kSecAttrLabel in SecItem.h
        #[unsafe(method(label))]
        #[unsafe(method_family = none)]
        pub unsafe fn label(&self) -> Option<Retained<NSString>>;

        /// Setter for [`label`][Self::label].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setLabel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLabel(&self, label: Option<&NSString>);

        #[cfg(feature = "TKToken")]
        /// Contains access constraints for this object keyed by TKTOpenOperation wrapped in NSNumber.
        #[unsafe(method(constraints))]
        #[unsafe(method_family = none)]
        pub unsafe fn constraints(
            &self,
        ) -> Option<Retained<NSDictionary<NSNumber, TKTokenOperationConstraint>>>;

        #[cfg(feature = "TKToken")]
        /// Setter for [`constraints`][Self::constraints].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `constraints` generic should be of the correct type.
        #[unsafe(method(setConstraints:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setConstraints(
            &self,
            constraints: Option<&NSDictionary<NSNumber, TKTokenOperationConstraint>>,
        );
    );
}

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

extern_class!(
    /// Interface for propagation token's certificates into the keychain.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktokenkeychaincertificate?language=objc)
    #[unsafe(super(TKTokenKeychainItem, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKTokenKeychainCertificate;
);

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

impl TKTokenKeychainCertificate {
    extern_methods!(
        #[cfg(all(feature = "TKToken", feature = "objc2-security"))]
        /// initialize TKTokenKeychainCertificate with data from SecCertificateRef.  Use SecCertificateCreateWithData to obtain SecCertificateRef.
        /// `constraints`property is initialized indicating that reading of certificate is always allowed, all other operations are disallowed.
        ///
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(initWithCertificate:objectID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCertificate_objectID(
            this: Allocated<Self>,
            certificate_ref: &SecCertificate,
            object_id: &TKTokenObjectID,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "TKToken")]
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(initWithObjectID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithObjectID(
            this: Allocated<Self>,
            object_id: &TKTokenObjectID,
        ) -> Retained<Self>;

        /// Contains DER-encoded representation of an X.509 certificate.
        #[unsafe(method(data))]
        #[unsafe(method_family = none)]
        pub unsafe fn data(&self) -> Retained<NSData>;
    );
}

/// Methods declared on superclass `TKTokenKeychainItem`.
impl TKTokenKeychainCertificate {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

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

extern_class!(
    /// Interface for propagation token's keys into the keychain.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktokenkeychainkey?language=objc)
    #[unsafe(super(TKTokenKeychainItem, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKTokenKeychainKey;
);

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

impl TKTokenKeychainKey {
    extern_methods!(
        #[cfg(all(feature = "TKToken", feature = "objc2-security"))]
        /// Initialize TKTokenKeychainKey with informations from SecCertificateRef associated with the key.  Use SecCertificateCreateWithData to obtain SecCertificateRef.  If NULL is passed instead of certificate, all properties of created instance must be initialized manually.
        ///
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(initWithCertificate:objectID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCertificate_objectID(
            this: Allocated<Self>,
            certificate_ref: Option<&SecCertificate>,
            object_id: &TKTokenObjectID,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "TKToken")]
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(initWithObjectID:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithObjectID(
            this: Allocated<Self>,
            object_id: &TKTokenObjectID,
        ) -> Retained<Self>;

        /// Type of the key, currently kSecAttrKeyTypeRSA and kSecAttrKeyTypeECSECPrimeRandom is supported).  The property is an equivalent to kSecAttrKeyType in SecItem.h
        #[unsafe(method(keyType))]
        #[unsafe(method_family = none)]
        pub unsafe fn keyType(&self) -> Retained<NSString>;

        /// Setter for [`keyType`][Self::keyType].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setKeyType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setKeyType(&self, key_type: &NSString);

        /// Represents private tag data.  The property is an equivalent to kSecAttrApplicationTag in SecItem.h
        #[unsafe(method(applicationTag))]
        #[unsafe(method_family = none)]
        pub unsafe fn applicationTag(&self) -> Option<Retained<NSData>>;

        /// Setter for [`applicationTag`][Self::applicationTag].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setApplicationTag:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setApplicationTag(&self, application_tag: Option<&NSData>);

        /// Indicates the number of bits in this key.  The property is an equivalent to kSecAttrKeySizeInBits in SecItem.h
        #[unsafe(method(keySizeInBits))]
        #[unsafe(method_family = none)]
        pub unsafe fn keySizeInBits(&self) -> NSInteger;

        /// Setter for [`keySizeInBits`][Self::keySizeInBits].
        #[unsafe(method(setKeySizeInBits:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setKeySizeInBits(&self, key_size_in_bits: NSInteger);

        /// Contains raw public key data for this private key.
        #[unsafe(method(publicKeyData))]
        #[unsafe(method_family = none)]
        pub unsafe fn publicKeyData(&self) -> Option<Retained<NSData>>;

        /// Setter for [`publicKeyData`][Self::publicKeyData].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setPublicKeyData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPublicKeyData(&self, public_key_data: Option<&NSData>);

        /// SHA1 hash of the raw public key.  The property is an equivalent to kSecAttrApplicationLabel in SecItem.h
        #[unsafe(method(publicKeyHash))]
        #[unsafe(method_family = none)]
        pub unsafe fn publicKeyHash(&self) -> Option<Retained<NSData>>;

        /// Setter for [`publicKeyHash`][Self::publicKeyHash].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setPublicKeyHash:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPublicKeyHash(&self, public_key_hash: Option<&NSData>);

        /// Indicates whether this key can be used to decrypt data.  The property is an equivalent to kSecAttrCanDecrypt in SecItem.h
        #[unsafe(method(canDecrypt))]
        #[unsafe(method_family = none)]
        pub unsafe fn canDecrypt(&self) -> bool;

        /// Setter for [`canDecrypt`][Self::canDecrypt].
        #[unsafe(method(setCanDecrypt:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCanDecrypt(&self, can_decrypt: bool);

        /// Indicates whether this key can be used to create a digital signature.  The property is an equivalent to kSecAttrCanSign in SecItem.h
        #[unsafe(method(canSign))]
        #[unsafe(method_family = none)]
        pub unsafe fn canSign(&self) -> bool;

        /// Setter for [`canSign`][Self::canSign].
        #[unsafe(method(setCanSign:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCanSign(&self, can_sign: bool);

        /// Indicates whether this key can be used to perform Diffie-Hellman style cryptographic key exchange.
        #[unsafe(method(canPerformKeyExchange))]
        #[unsafe(method_family = none)]
        pub unsafe fn canPerformKeyExchange(&self) -> bool;

        /// Setter for [`canPerformKeyExchange`][Self::canPerformKeyExchange].
        #[unsafe(method(setCanPerformKeyExchange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCanPerformKeyExchange(&self, can_perform_key_exchange: bool);

        /// Indicates whether this key can be used for login in to the system.
        #[unsafe(method(isSuitableForLogin))]
        #[unsafe(method_family = none)]
        pub unsafe fn isSuitableForLogin(&self) -> bool;

        /// Setter for [`isSuitableForLogin`][Self::isSuitableForLogin].
        #[unsafe(method(setSuitableForLogin:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSuitableForLogin(&self, suitable_for_login: bool);
    );
}

/// Methods declared on superclass `TKTokenKeychainItem`.
impl TKTokenKeychainKey {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

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

extern_class!(
    /// Contains TKTokenKeychainItem instances (keys and certificates) which represent keychain state (i.e. set of items) of specific token.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktokenkeychaincontents?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKTokenKeychainContents;
);

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

impl TKTokenKeychainContents {
    extern_methods!(
        /// Fills keychain with the set of specified items.  All items belonging to token are first removed from the keychain and then the keychain is populated with new items.
        ///
        /// Parameter `items`: New items to be stored into the keychain.
        #[unsafe(method(fillWithItems:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fillWithItems(&self, items: &NSArray<TKTokenKeychainItem>);

        /// All items related to this token in the keychain.
        #[unsafe(method(items))]
        #[unsafe(method_family = none)]
        pub unsafe fn items(&self) -> Retained<NSArray<TKTokenKeychainItem>>;

        #[cfg(feature = "TKToken")]
        /// Returns key with specified objectID.  Fills error with TKTokenErrorCodeObjectNotFound if no such key exists.
        ///
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(keyForObjectID:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn keyForObjectID_error(
            &self,
            object_id: &TKTokenObjectID,
        ) -> Result<Retained<TKTokenKeychainKey>, Retained<NSError>>;

        #[cfg(feature = "TKToken")]
        /// Returns certificate with specified objectID.  Fills error with TKTokenErrorCodeObjectNotFound if no such certificate exists.
        ///
        /// # Safety
        ///
        /// `object_id` should be of the correct type.
        #[unsafe(method(certificateForObjectID:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn certificateForObjectID_error(
            &self,
            object_id: &TKTokenObjectID,
        ) -> Result<Retained<TKTokenKeychainCertificate>, Retained<NSError>>;

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

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