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::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// Type used for identifying TLV format tags.
/// Although for some encodings tags can have theoretically any length,
/// this implementation supports tag length only up to 64bits.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktlvtag?language=objc)
pub type TKTLVTag = u64;

extern_class!(
    /// Base class representing Tag-Length-Value record.
    /// Every record has its tag and binary value represented as NSData instance.  Allows retrieving record's tag,
    /// value (as NSData object) and binary representation of the record. Existing subclasses implement assorted
    /// encodings - TKBERTLVRecord, TKSimpleTLVRecord and TKCompactTLVRecord.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tktlvrecord?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKTLVRecord;
);

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

impl TKTLVRecord {
    extern_methods!(
        /// Tag value of the record.
        #[unsafe(method(tag))]
        #[unsafe(method_family = none)]
        pub unsafe fn tag(&self) -> TKTLVTag;

        /// Value field of the record.
        #[unsafe(method(value))]
        #[unsafe(method_family = none)]
        pub unsafe fn value(&self) -> Retained<NSData>;

        /// Data object containing whole encoded record, including tag, length and value.
        #[unsafe(method(data))]
        #[unsafe(method_family = none)]
        pub unsafe fn data(&self) -> Retained<NSData>;

        /// Parses TLV record from data block
        ///
        /// Parameter `data`: Data block containing serialized form of TLV record.
        ///
        /// Returns: newly parsed record instance or nil if data do not represent valid record.
        #[unsafe(method(recordFromData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordFromData(data: &NSData) -> Option<Retained<Self>>;

        /// Parses sequence of TLV records from data block.
        /// The amount of records is determined by the length of input data block.
        ///
        /// Parameter `data`: Data block containing zero or more serialized forms of TLV record.
        ///
        /// Returns: An array of TLV record instances parsed from input data block or nil if data do not form valid TLV record sequence.
        #[unsafe(method(sequenceOfRecordsFromData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn sequenceOfRecordsFromData(
            data: &NSData,
        ) -> Option<Retained<NSArray<TKTLVRecord>>>;

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

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

extern_class!(
    /// TKBERTLVRecord implements encoding using BER-TLV encoding rules.
    /// It is able to parse BER-encoded data and always produces DER-encoded data.
    /// No interpretation of tag values is made, all values are treated only as NSData irrespective of the tag.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tkbertlvrecord?language=objc)
    #[unsafe(super(TKTLVRecord, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKBERTLVRecord;
);

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

impl TKBERTLVRecord {
    extern_methods!(
        /// Encodes tag using BER-TLV tag encoding rules.
        ///
        /// Parameter `tag`: Tag value to encode
        ///
        /// Returns: Binary block containing encoded tag value.
        #[unsafe(method(dataForTag:))]
        #[unsafe(method_family = none)]
        pub unsafe fn dataForTag(tag: TKTLVTag) -> Retained<NSData>;

        /// Creates TLV record with specified tag and value.
        ///
        /// Parameter `tag`: Tag value for the new record.
        ///
        /// Parameter `value`: Value for the new record.
        ///
        /// Returns: Newly created TLV record.
        #[unsafe(method(initWithTag:value:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTag_value(
            this: Allocated<Self>,
            tag: TKTLVTag,
            value: &NSData,
        ) -> Retained<Self>;

        /// Creates TKBERTLVRecord with specified tag and array of children TKTLVRecord instances as subrecords.
        ///
        /// Parameter `tag`: Tag value for the new record.
        ///
        /// Parameter `records`: Array of TKTLVRecord instances serving as subrecords of this record.
        ///
        /// Returns: Newly created TLV record.
        #[unsafe(method(initWithTag:records:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTag_records(
            this: Allocated<Self>,
            tag: TKTLVTag,
            records: &NSArray<TKTLVRecord>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `TKTLVRecord`.
impl TKBERTLVRecord {
    extern_methods!(
        /// Parses TLV record from data block
        ///
        /// Parameter `data`: Data block containing serialized form of TLV record.
        ///
        /// Returns: newly parsed record instance or nil if data do not represent valid record.
        #[unsafe(method(recordFromData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordFromData(data: &NSData) -> Option<Retained<Self>>;

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

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

extern_class!(
    /// TKSimpleTLVRecord implements Simple-TLV encoding according to ISO7816-4.
    /// Tag is number in range
    /// <
    /// 1..254> encoded as single byte, length is either single byte specifying length 0-254
    /// or 3 bytes encoded as 0xff followed by 2 bytes of big-endian encoded number.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksimpletlvrecord?language=objc)
    #[unsafe(super(TKTLVRecord, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKSimpleTLVRecord;
);

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

impl TKSimpleTLVRecord {
    extern_methods!(
        /// Creates TLV record with specified tag and value.
        ///
        /// Parameter `tag`: Tag value for the new record.
        ///
        /// Parameter `value`: Value for the new record.
        ///
        /// Returns: Newly created TLV record.
        #[unsafe(method(initWithTag:value:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTag_value(
            this: Allocated<Self>,
            tag: u8,
            value: &NSData,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `TKTLVRecord`.
impl TKSimpleTLVRecord {
    extern_methods!(
        /// Parses TLV record from data block
        ///
        /// Parameter `data`: Data block containing serialized form of TLV record.
        ///
        /// Returns: newly parsed record instance or nil if data do not represent valid record.
        #[unsafe(method(recordFromData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordFromData(data: &NSData) -> Option<Retained<Self>>;

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

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

extern_class!(
    /// TKCompactTLVRecord implements Compact-TLV encoding according to ISO7816-4
    /// Tag is number in range
    /// <
    /// 0..15> encoded as high 4 bits of initial byte, length is number in range
    /// <
    /// 0..15>
    /// encoded as low 4 bits of initial byte.  Value immediatelly follows leading byte.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tkcompacttlvrecord?language=objc)
    #[unsafe(super(TKTLVRecord, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct TKCompactTLVRecord;
);

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

impl TKCompactTLVRecord {
    extern_methods!(
        /// Creates TLV record with specified tag and value.
        ///
        /// Parameter `tag`: Tag value for the new record.
        ///
        /// Parameter `value`: Value for the new record.
        ///
        /// Returns: Newly created TLV record.
        #[unsafe(method(initWithTag:value:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTag_value(
            this: Allocated<Self>,
            tag: u8,
            value: &NSData,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `TKTLVRecord`.
impl TKCompactTLVRecord {
    extern_methods!(
        /// Parses TLV record from data block
        ///
        /// Parameter `data`: Data block containing serialized form of TLV record.
        ///
        /// Returns: newly parsed record instance or nil if data do not represent valid record.
        #[unsafe(method(recordFromData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn recordFromData(data: &NSData) -> Option<Retained<Self>>;

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

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