objc2_crypto_token_kit/generated/TKSmartCard.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// Represents pool of SmartCard reader slots.
12 ///
13 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardslotmanager?language=objc)
14 #[unsafe(super(NSObject))]
15 #[derive(Debug, PartialEq, Eq, Hash)]
16 pub struct TKSmartCardSlotManager;
17);
18
19extern_conformance!(
20 unsafe impl NSObjectProtocol for TKSmartCardSlotManager {}
21);
22
23impl TKSmartCardSlotManager {
24 extern_methods!(
25 /// Global pool of SmartCard reader slots.
26 /// macOS: Note that defaultManager instance is accessible only if the calling application has 'com.apple.security.smartcard' entitlement set to Boolean:YES. If the calling application does not have this entitlement, defaultManager is always set to nil.
27 /// iOS: The defaultManager instance is always accessible.
28 #[unsafe(method(defaultManager))]
29 #[unsafe(method_family = none)]
30 pub unsafe fn defaultManager() -> Option<Retained<TKSmartCardSlotManager>>;
31
32 /// Array of currently known slots in the system. Slots are identified by NSString name instances. Use KVO to be notified about slots arrivals and removals.
33 #[unsafe(method(slotNames))]
34 #[unsafe(method_family = none)]
35 pub unsafe fn slotNames(&self) -> Retained<NSArray<NSString>>;
36
37 #[cfg(feature = "block2")]
38 /// Instantiates smartcard reader slot of specified name. If specified name is not registered, reports nil.
39 #[unsafe(method(getSlotWithName:reply:))]
40 #[unsafe(method_family = none)]
41 pub unsafe fn getSlotWithName_reply(
42 &self,
43 name: &NSString,
44 reply: &block2::DynBlock<dyn Fn(*mut TKSmartCardSlot)>,
45 );
46
47 /// Gets SmartCard reader slot with specified name. If reader slot with this name does not exist, returns nil.
48 #[unsafe(method(slotNamed:))]
49 #[unsafe(method_family = none)]
50 pub unsafe fn slotNamed(&self, name: &NSString) -> Option<Retained<TKSmartCardSlot>>;
51 );
52}
53
54/// Methods declared on superclass `NSObject`.
55impl TKSmartCardSlotManager {
56 extern_methods!(
57 #[unsafe(method(init))]
58 #[unsafe(method_family = init)]
59 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
60
61 #[unsafe(method(new))]
62 #[unsafe(method_family = new)]
63 pub unsafe fn new() -> Retained<Self>;
64 );
65}
66
67/// Enumerates all possible slot states.
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardslotstate?language=objc)
70// NS_ENUM
71#[repr(transparent)]
72#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
73pub struct TKSmartCardSlotState(pub NSInteger);
74impl TKSmartCardSlotState {
75 /// Slot is no longer known to the system. This is terminal state for TKSmartCardSlot instance, once reached, the slot instance can never be revived.
76 #[doc(alias = "TKSmartCardSlotStateMissing")]
77 pub const Missing: Self = Self(0);
78 /// The slot is empty, no card is inserted.
79 #[doc(alias = "TKSmartCardSlotStateEmpty")]
80 pub const Empty: Self = Self(1);
81 /// The card was inserted into the slot and an initial probe is in progress.
82 #[doc(alias = "TKSmartCardSlotStateProbing")]
83 pub const Probing: Self = Self(2);
84 /// The card inserted in the slot does not answer.
85 #[doc(alias = "TKSmartCardSlotStateMuteCard")]
86 pub const MuteCard: Self = Self(3);
87 /// Card properly answered to reset.
88 #[doc(alias = "TKSmartCardSlotStateValidCard")]
89 pub const ValidCard: Self = Self(4);
90}
91
92unsafe impl Encode for TKSmartCardSlotState {
93 const ENCODING: Encoding = NSInteger::ENCODING;
94}
95
96unsafe impl RefEncode for TKSmartCardSlotState {
97 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
98}
99
100/// Enumerates all possible PIN character sets.
101///
102/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpincharset?language=objc)
103// NS_ENUM
104#[repr(transparent)]
105#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
106pub struct TKSmartCardPINCharset(pub NSInteger);
107impl TKSmartCardPINCharset {
108 /// PIN is only composed of digits.
109 #[doc(alias = "TKSmartCardPINCharsetNumeric")]
110 pub const Numeric: Self = Self(0);
111 /// PIN can be composed of digits and letters.
112 #[doc(alias = "TKSmartCardPINCharsetAlphanumeric")]
113 pub const Alphanumeric: Self = Self(1);
114 /// PIN can be composed of digits and uppercase letters.
115 #[doc(alias = "TKSmartCardPINCharsetUpperAlphanumeric")]
116 pub const UpperAlphanumeric: Self = Self(2);
117}
118
119unsafe impl Encode for TKSmartCardPINCharset {
120 const ENCODING: Encoding = NSInteger::ENCODING;
121}
122
123unsafe impl RefEncode for TKSmartCardPINCharset {
124 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
125}
126
127/// Enumerates all possible PIN encoding types.
128///
129/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpinencoding?language=objc)
130// NS_ENUM
131#[repr(transparent)]
132#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
133pub struct TKSmartCardPINEncoding(pub NSInteger);
134impl TKSmartCardPINEncoding {
135 /// Characters are encoded in Binary format (1234 => 01h 02h 03h 04h).
136 #[doc(alias = "TKSmartCardPINEncodingBinary")]
137 pub const Binary: Self = Self(0);
138 /// Characters are encoded in ASCII format (1234 => 31h 32h 33h 34h).
139 #[doc(alias = "TKSmartCardPINEncodingASCII")]
140 pub const ASCII: Self = Self(1);
141 /// Characters (only digits) are encoded in BCD format (1234 => 12h 34h).
142 #[doc(alias = "TKSmartCardPINEncodingBCD")]
143 pub const BCD: Self = Self(2);
144}
145
146unsafe impl Encode for TKSmartCardPINEncoding {
147 const ENCODING: Encoding = NSInteger::ENCODING;
148}
149
150unsafe impl RefEncode for TKSmartCardPINEncoding {
151 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
152}
153
154/// Enumerates all posible PIN justification types.
155///
156/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpinjustification?language=objc)
157// NS_ENUM
158#[repr(transparent)]
159#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
160pub struct TKSmartCardPINJustification(pub NSInteger);
161impl TKSmartCardPINJustification {
162 /// Justify to the left.
163 #[doc(alias = "TKSmartCardPINJustificationLeft")]
164 pub const Left: Self = Self(0);
165 /// Justify to the right.
166 #[doc(alias = "TKSmartCardPINJustificationRight")]
167 pub const Right: Self = Self(1);
168}
169
170unsafe impl Encode for TKSmartCardPINJustification {
171 const ENCODING: Encoding = NSInteger::ENCODING;
172}
173
174unsafe impl RefEncode for TKSmartCardPINJustification {
175 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
176}
177
178/// Bitmask specifying condition(s) under which PIN entry should be considered complete.
179///
180/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpincompletion?language=objc)
181// NS_OPTIONS
182#[repr(transparent)]
183#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
184pub struct TKSmartCardPINCompletion(pub NSUInteger);
185bitflags::bitflags! {
186 impl TKSmartCardPINCompletion: NSUInteger {
187/// Completion by reaching the maximum PIN length.
188 #[doc(alias = "TKSmartCardPINCompletionMaxLength")]
189 const MaxLength = 1<<0;
190/// Completion by pressing the validation key.
191 #[doc(alias = "TKSmartCardPINCompletionKey")]
192 const Key = 1<<1;
193/// Completion by timeout expiration.
194 #[doc(alias = "TKSmartCardPINCompletionTimeout")]
195 const Timeout = 1<<2;
196 }
197}
198
199unsafe impl Encode for TKSmartCardPINCompletion {
200 const ENCODING: Encoding = NSUInteger::ENCODING;
201}
202
203unsafe impl RefEncode for TKSmartCardPINCompletion {
204 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
205}
206
207/// Bitmask specifying whether PIN confirmation should be requested.
208///
209/// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpinconfirmation?language=objc)
210// NS_OPTIONS
211#[repr(transparent)]
212#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
213pub struct TKSmartCardPINConfirmation(pub NSUInteger);
214bitflags::bitflags! {
215 impl TKSmartCardPINConfirmation: NSUInteger {
216/// No confirmation requested.
217 #[doc(alias = "TKSmartCardPINConfirmationNone")]
218 const None = 0;
219/// Confirmation (entry) of the new PIN requested.
220 #[doc(alias = "TKSmartCardPINConfirmationNew")]
221 const New = 1<<0;
222/// Confirmation (entry) of the current PIN requested.
223 #[doc(alias = "TKSmartCardPINConfirmationCurrent")]
224 const Current = 1<<1;
225 }
226}
227
228unsafe impl Encode for TKSmartCardPINConfirmation {
229 const ENCODING: Encoding = NSUInteger::ENCODING;
230}
231
232unsafe impl RefEncode for TKSmartCardPINConfirmation {
233 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
234}
235
236extern_class!(
237 /// Specifies PIN formatting properties.
238 ///
239 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardpinformat?language=objc)
240 #[unsafe(super(NSObject))]
241 #[derive(Debug, PartialEq, Eq, Hash)]
242 pub struct TKSmartCardPINFormat;
243);
244
245extern_conformance!(
246 unsafe impl NSObjectProtocol for TKSmartCardPINFormat {}
247);
248
249impl TKSmartCardPINFormat {
250 extern_methods!(
251 /// Format of PIN characters.
252 ///
253 /// Note: Default value: TKSmartCardPINCharsetNumeric
254 #[unsafe(method(charset))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn charset(&self) -> TKSmartCardPINCharset;
257
258 /// Setter for [`charset`][Self::charset].
259 #[unsafe(method(setCharset:))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn setCharset(&self, charset: TKSmartCardPINCharset);
262
263 /// Encoding of PIN characters.
264 ///
265 /// Note: Default value: TKSmartCardPINEncodingASCII
266 #[unsafe(method(encoding))]
267 #[unsafe(method_family = none)]
268 pub unsafe fn encoding(&self) -> TKSmartCardPINEncoding;
269
270 /// Setter for [`encoding`][Self::encoding].
271 #[unsafe(method(setEncoding:))]
272 #[unsafe(method_family = none)]
273 pub unsafe fn setEncoding(&self, encoding: TKSmartCardPINEncoding);
274
275 /// Minimum number of characters to form a valid PIN.
276 ///
277 /// Note: Default value: 4
278 #[unsafe(method(minPINLength))]
279 #[unsafe(method_family = none)]
280 pub unsafe fn minPINLength(&self) -> NSInteger;
281
282 /// Setter for [`minPINLength`][Self::minPINLength].
283 #[unsafe(method(setMinPINLength:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn setMinPINLength(&self, min_pin_length: NSInteger);
286
287 /// Maximum number of characters to form a valid PIN.
288 ///
289 /// Note: Default value: 8
290 #[unsafe(method(maxPINLength))]
291 #[unsafe(method_family = none)]
292 pub unsafe fn maxPINLength(&self) -> NSInteger;
293
294 /// Setter for [`maxPINLength`][Self::maxPINLength].
295 #[unsafe(method(setMaxPINLength:))]
296 #[unsafe(method_family = none)]
297 pub unsafe fn setMaxPINLength(&self, max_pin_length: NSInteger);
298
299 /// Total length of the PIN block in bytes.
300 ///
301 /// Note: Default value: 8
302 #[unsafe(method(PINBlockByteLength))]
303 #[unsafe(method_family = none)]
304 pub unsafe fn PINBlockByteLength(&self) -> NSInteger;
305
306 /// Setter for [`PINBlockByteLength`][Self::PINBlockByteLength].
307 #[unsafe(method(setPINBlockByteLength:))]
308 #[unsafe(method_family = none)]
309 pub unsafe fn setPINBlockByteLength(&self, pin_block_byte_length: NSInteger);
310
311 /// PIN justification within the PIN block.
312 ///
313 /// Note: Default value: TKSmartCardPINJustificationLeft
314 #[unsafe(method(PINJustification))]
315 #[unsafe(method_family = none)]
316 pub unsafe fn PINJustification(&self) -> TKSmartCardPINJustification;
317
318 /// Setter for [`PINJustification`][Self::PINJustification].
319 #[unsafe(method(setPINJustification:))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn setPINJustification(&self, pin_justification: TKSmartCardPINJustification);
322
323 /// Offset in bits within the PIN block to mark a location for filling in the formatted PIN (justified with respect to PINJustification).
324 ///
325 /// Note: Default value: 0
326 ///
327 /// The offset, in bits, within the PIN block to mark a location for filling in the formatted PIN, which is justified with respect to the PINJustification property value.
328 #[unsafe(method(PINBitOffset))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn PINBitOffset(&self) -> NSInteger;
331
332 /// Setter for [`PINBitOffset`][Self::PINBitOffset].
333 #[unsafe(method(setPINBitOffset:))]
334 #[unsafe(method_family = none)]
335 pub unsafe fn setPINBitOffset(&self, pin_bit_offset: NSInteger);
336
337 /// Offset in bits within the PIN block to mark a location for filling in the PIN length (always left justified).
338 ///
339 /// Note: Default value: 0
340 ///
341 /// The offset, in bits, within the PIN block to mark a location for filling in the PIN length, which is always left justified.
342 #[unsafe(method(PINLengthBitOffset))]
343 #[unsafe(method_family = none)]
344 pub unsafe fn PINLengthBitOffset(&self) -> NSInteger;
345
346 /// Setter for [`PINLengthBitOffset`][Self::PINLengthBitOffset].
347 #[unsafe(method(setPINLengthBitOffset:))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn setPINLengthBitOffset(&self, pin_length_bit_offset: NSInteger);
350
351 /// Size in bits of the PIN length field. If set to 0, PIN length is not written.
352 ///
353 /// Note: Default value: 0
354 #[unsafe(method(PINLengthBitSize))]
355 #[unsafe(method_family = none)]
356 pub unsafe fn PINLengthBitSize(&self) -> NSInteger;
357
358 /// Setter for [`PINLengthBitSize`][Self::PINLengthBitSize].
359 #[unsafe(method(setPINLengthBitSize:))]
360 #[unsafe(method_family = none)]
361 pub unsafe fn setPINLengthBitSize(&self, pin_length_bit_size: NSInteger);
362 );
363}
364
365/// Methods declared on superclass `NSObject`.
366impl TKSmartCardPINFormat {
367 extern_methods!(
368 #[unsafe(method(init))]
369 #[unsafe(method_family = init)]
370 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
371
372 #[unsafe(method(new))]
373 #[unsafe(method_family = new)]
374 pub unsafe fn new() -> Retained<Self>;
375 );
376}
377
378extern_protocol!(
379 /// Delegate for user interactions involving the SmartCard reader.
380 ///
381 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcarduserinteractiondelegate?language=objc)
382 pub unsafe trait TKSmartCardUserInteractionDelegate {
383 /// A valid character has been entered.
384 #[optional]
385 #[unsafe(method(characterEnteredInUserInteraction:))]
386 #[unsafe(method_family = none)]
387 unsafe fn characterEnteredInUserInteraction(
388 &self,
389 interaction: &TKSmartCardUserInteraction,
390 );
391
392 /// A correction key has been pressed.
393 #[optional]
394 #[unsafe(method(correctionKeyPressedInUserInteraction:))]
395 #[unsafe(method_family = none)]
396 unsafe fn correctionKeyPressedInUserInteraction(
397 &self,
398 interaction: &TKSmartCardUserInteraction,
399 );
400
401 /// The validation key has been pressed (end of PIN entry).
402 #[optional]
403 #[unsafe(method(validationKeyPressedInUserInteraction:))]
404 #[unsafe(method_family = none)]
405 unsafe fn validationKeyPressedInUserInteraction(
406 &self,
407 interaction: &TKSmartCardUserInteraction,
408 );
409
410 /// An invalid character has been entered.
411 #[optional]
412 #[unsafe(method(invalidCharacterEnteredInUserInteraction:))]
413 #[unsafe(method_family = none)]
414 unsafe fn invalidCharacterEnteredInUserInteraction(
415 &self,
416 interaction: &TKSmartCardUserInteraction,
417 );
418
419 /// Indicates that the old PIN needs to be entered.
420 #[optional]
421 #[unsafe(method(oldPINRequestedInUserInteraction:))]
422 #[unsafe(method_family = none)]
423 unsafe fn oldPINRequestedInUserInteraction(&self, interaction: &TKSmartCardUserInteraction);
424
425 /// Indicates that the new PIN needs to be entered.
426 #[optional]
427 #[unsafe(method(newPINRequestedInUserInteraction:))]
428 #[unsafe(method_family = none)]
429 unsafe fn newPINRequestedInUserInteraction(&self, interaction: &TKSmartCardUserInteraction);
430
431 /// Indicates that the new PIN needs to be confirmed (re-entered).
432 #[optional]
433 #[unsafe(method(newPINConfirmationRequestedInUserInteraction:))]
434 #[unsafe(method_family = none)]
435 unsafe fn newPINConfirmationRequestedInUserInteraction(
436 &self,
437 interaction: &TKSmartCardUserInteraction,
438 );
439 }
440);
441
442extern_class!(
443 /// Represents handle to a user interaction involving the SmartCard reader.
444 ///
445 /// It is a proxy object obtained as a result of invoking the userInteractionFor*** family of methods in TKSmartCardSlot and TKSmartCard.
446 ///
447 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcarduserinteraction?language=objc)
448 #[unsafe(super(NSObject))]
449 #[derive(Debug, PartialEq, Eq, Hash)]
450 pub struct TKSmartCardUserInteraction;
451);
452
453extern_conformance!(
454 unsafe impl NSObjectProtocol for TKSmartCardUserInteraction {}
455);
456
457impl TKSmartCardUserInteraction {
458 extern_methods!(
459 /// Delegate for state observing of the interaction.
460 #[unsafe(method(delegate))]
461 #[unsafe(method_family = none)]
462 pub unsafe fn delegate(
463 &self,
464 ) -> Option<Retained<ProtocolObject<dyn TKSmartCardUserInteractionDelegate>>>;
465
466 /// This is a [weak property][objc2::topics::weak_property].
467 /// Setter for [`delegate`][Self::delegate].
468 #[unsafe(method(setDelegate:))]
469 #[unsafe(method_family = none)]
470 pub unsafe fn setDelegate(
471 &self,
472 delegate: Option<&ProtocolObject<dyn TKSmartCardUserInteractionDelegate>>,
473 );
474
475 /// Initial interaction timeout. If set to 0, the reader-defined default timeout is used.
476 ///
477 /// Note: Default value: 0
478 #[unsafe(method(initialTimeout))]
479 #[unsafe(method_family = none)]
480 pub unsafe fn initialTimeout(&self) -> NSTimeInterval;
481
482 /// Setter for [`initialTimeout`][Self::initialTimeout].
483 #[unsafe(method(setInitialTimeout:))]
484 #[unsafe(method_family = none)]
485 pub unsafe fn setInitialTimeout(&self, initial_timeout: NSTimeInterval);
486
487 /// Timeout after the first key stroke. If set to 0, the reader-defined default timeout is used.
488 ///
489 /// Note: Default value: 0
490 #[unsafe(method(interactionTimeout))]
491 #[unsafe(method_family = none)]
492 pub unsafe fn interactionTimeout(&self) -> NSTimeInterval;
493
494 /// Setter for [`interactionTimeout`][Self::interactionTimeout].
495 #[unsafe(method(setInteractionTimeout:))]
496 #[unsafe(method_family = none)]
497 pub unsafe fn setInteractionTimeout(&self, interaction_timeout: NSTimeInterval);
498
499 #[cfg(feature = "block2")]
500 /// Runs the interaction.
501 #[unsafe(method(runWithReply:))]
502 #[unsafe(method_family = none)]
503 pub unsafe fn runWithReply(&self, reply: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>);
504
505 /// Attempts to cancel a running interaction. Note that for some interactions, this functionality might not be available.
506 ///
507 /// Returns: Returns NO if the operation is not running, or cancelling is not supported.
508 #[unsafe(method(cancel))]
509 #[unsafe(method_family = none)]
510 pub unsafe fn cancel(&self) -> bool;
511 );
512}
513
514/// Methods declared on superclass `NSObject`.
515impl TKSmartCardUserInteraction {
516 extern_methods!(
517 #[unsafe(method(init))]
518 #[unsafe(method_family = init)]
519 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
520
521 #[unsafe(method(new))]
522 #[unsafe(method_family = new)]
523 pub unsafe fn new() -> Retained<Self>;
524 );
525}
526
527extern_class!(
528 /// User interaction for the secure PIN operations on the SmartCard reader.
529 ///
530 /// Note: Result is available after the interaction has been successfully completed.
531 ///
532 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcarduserinteractionforpinoperation?language=objc)
533 #[unsafe(super(TKSmartCardUserInteraction, NSObject))]
534 #[derive(Debug, PartialEq, Eq, Hash)]
535 pub struct TKSmartCardUserInteractionForPINOperation;
536);
537
538extern_conformance!(
539 unsafe impl NSObjectProtocol for TKSmartCardUserInteractionForPINOperation {}
540);
541
542impl TKSmartCardUserInteractionForPINOperation {
543 extern_methods!(
544 /// Bitmask specifying condition(s) under which PIN entry should be considered complete.
545 ///
546 /// Note: Default value: TKSmartCardPINCompletionKey
547 #[unsafe(method(PINCompletion))]
548 #[unsafe(method_family = none)]
549 pub unsafe fn PINCompletion(&self) -> TKSmartCardPINCompletion;
550
551 /// Setter for [`PINCompletion`][Self::PINCompletion].
552 #[unsafe(method(setPINCompletion:))]
553 #[unsafe(method_family = none)]
554 pub unsafe fn setPINCompletion(&self, pin_completion: TKSmartCardPINCompletion);
555
556 /// List of message indices referring to a predefined message table. It is used to specify the type and number of messages displayed during the PIN operation.
557 ///
558 /// If nil, the reader does not display any message (reader specific). Typically, PIN verification takes 1 message, PIN modification 1-3 messages.
559 ///
560 /// Note: Default value: nil
561 #[unsafe(method(PINMessageIndices))]
562 #[unsafe(method_family = none)]
563 pub unsafe fn PINMessageIndices(&self) -> Option<Retained<NSArray<NSNumber>>>;
564
565 /// Setter for [`PINMessageIndices`][Self::PINMessageIndices].
566 #[unsafe(method(setPINMessageIndices:))]
567 #[unsafe(method_family = none)]
568 pub unsafe fn setPINMessageIndices(&self, pin_message_indices: Option<&NSArray<NSNumber>>);
569
570 /// Locale defining the language of displayed messages. If set to nil, the user's current locale is used.
571 ///
572 /// Note: Default value: the user's current locale
573 #[unsafe(method(locale))]
574 #[unsafe(method_family = none)]
575 pub unsafe fn locale(&self) -> Option<Retained<NSLocale>>;
576
577 /// Setter for [`locale`][Self::locale].
578 #[unsafe(method(setLocale:))]
579 #[unsafe(method_family = none)]
580 pub unsafe fn setLocale(&self, locale: Option<&NSLocale>);
581
582 /// SW1SW2 result code.
583 #[unsafe(method(resultSW))]
584 #[unsafe(method_family = none)]
585 pub unsafe fn resultSW(&self) -> u16;
586
587 /// Setter for [`resultSW`][Self::resultSW].
588 #[unsafe(method(setResultSW:))]
589 #[unsafe(method_family = none)]
590 pub unsafe fn setResultSW(&self, result_sw: u16);
591
592 /// Optional block of returned data (without SW1SW2 bytes).
593 #[unsafe(method(resultData))]
594 #[unsafe(method_family = none)]
595 pub unsafe fn resultData(&self) -> Option<Retained<NSData>>;
596
597 /// Setter for [`resultData`][Self::resultData].
598 #[unsafe(method(setResultData:))]
599 #[unsafe(method_family = none)]
600 pub unsafe fn setResultData(&self, result_data: Option<&NSData>);
601 );
602}
603
604/// Methods declared on superclass `NSObject`.
605impl TKSmartCardUserInteractionForPINOperation {
606 extern_methods!(
607 #[unsafe(method(init))]
608 #[unsafe(method_family = init)]
609 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
610
611 #[unsafe(method(new))]
612 #[unsafe(method_family = new)]
613 pub unsafe fn new() -> Retained<Self>;
614 );
615}
616
617extern_class!(
618 /// User interaction for the secure PIN verification on the SmartCard reader.
619 ///
620 /// Note: Result is available after the interaction has been successfully completed.
621 ///
622 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcarduserinteractionforsecurepinverification?language=objc)
623 #[unsafe(super(
624 TKSmartCardUserInteractionForPINOperation,
625 TKSmartCardUserInteraction,
626 NSObject
627 ))]
628 #[derive(Debug, PartialEq, Eq, Hash)]
629 pub struct TKSmartCardUserInteractionForSecurePINVerification;
630);
631
632extern_conformance!(
633 unsafe impl NSObjectProtocol for TKSmartCardUserInteractionForSecurePINVerification {}
634);
635
636impl TKSmartCardUserInteractionForSecurePINVerification {
637 extern_methods!();
638}
639
640/// Methods declared on superclass `NSObject`.
641impl TKSmartCardUserInteractionForSecurePINVerification {
642 extern_methods!(
643 #[unsafe(method(init))]
644 #[unsafe(method_family = init)]
645 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
646
647 #[unsafe(method(new))]
648 #[unsafe(method_family = new)]
649 pub unsafe fn new() -> Retained<Self>;
650 );
651}
652
653extern_class!(
654 /// User interaction for the secure PIN change on the SmartCard reader.
655 ///
656 /// Note: Result is available after the interaction has been successfully completed.
657 ///
658 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcarduserinteractionforsecurepinchange?language=objc)
659 #[unsafe(super(
660 TKSmartCardUserInteractionForPINOperation,
661 TKSmartCardUserInteraction,
662 NSObject
663 ))]
664 #[derive(Debug, PartialEq, Eq, Hash)]
665 pub struct TKSmartCardUserInteractionForSecurePINChange;
666);
667
668extern_conformance!(
669 unsafe impl NSObjectProtocol for TKSmartCardUserInteractionForSecurePINChange {}
670);
671
672impl TKSmartCardUserInteractionForSecurePINChange {
673 extern_methods!(
674 /// Bitmask specifying whether PIN confirmation should be requested.
675 ///
676 /// Note: Default value: TKSmartCardPINConfirmationNone
677 #[unsafe(method(PINConfirmation))]
678 #[unsafe(method_family = none)]
679 pub unsafe fn PINConfirmation(&self) -> TKSmartCardPINConfirmation;
680
681 /// Setter for [`PINConfirmation`][Self::PINConfirmation].
682 #[unsafe(method(setPINConfirmation:))]
683 #[unsafe(method_family = none)]
684 pub unsafe fn setPINConfirmation(&self, pin_confirmation: TKSmartCardPINConfirmation);
685 );
686}
687
688/// Methods declared on superclass `NSObject`.
689impl TKSmartCardUserInteractionForSecurePINChange {
690 extern_methods!(
691 #[unsafe(method(init))]
692 #[unsafe(method_family = init)]
693 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
694
695 #[unsafe(method(new))]
696 #[unsafe(method_family = new)]
697 pub unsafe fn new() -> Retained<Self>;
698 );
699}
700
701extern_class!(
702 /// Represents single slot which can contain SmartCard.
703 ///
704 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcardslot?language=objc)
705 #[unsafe(super(NSObject))]
706 #[derive(Debug, PartialEq, Eq, Hash)]
707 pub struct TKSmartCardSlot;
708);
709
710extern_conformance!(
711 unsafe impl NSObjectProtocol for TKSmartCardSlot {}
712);
713
714impl TKSmartCardSlot {
715 extern_methods!(
716 /// Current state of the slot. Use KVO to be notified about state changes.
717 #[unsafe(method(state))]
718 #[unsafe(method_family = none)]
719 pub unsafe fn state(&self) -> TKSmartCardSlotState;
720
721 #[cfg(feature = "TKSmartCardATR")]
722 /// ATR of the inserted SmartCard, or nil if no or mute SmartCard is inserted.
723 #[unsafe(method(ATR))]
724 #[unsafe(method_family = none)]
725 pub unsafe fn ATR(&self) -> Option<Retained<TKSmartCardATR>>;
726
727 /// Name of the SmartCard reader slot.
728 #[unsafe(method(name))]
729 #[unsafe(method_family = none)]
730 pub unsafe fn name(&self) -> Retained<NSString>;
731
732 /// Maximal length of input APDU that the slot is able to transfer to the card.
733 #[unsafe(method(maxInputLength))]
734 #[unsafe(method_family = none)]
735 pub unsafe fn maxInputLength(&self) -> NSInteger;
736
737 /// Maximal length of output APDU that the slot is able to transfer from the card.
738 #[unsafe(method(maxOutputLength))]
739 #[unsafe(method_family = none)]
740 pub unsafe fn maxOutputLength(&self) -> NSInteger;
741
742 /// Creates new object representing currently inserted and valid card.
743 ///
744 /// It is possible to instantiate multiple objects for single card, exclusivity is handled by sessions on the level of created SmartCard objects.
745 ///
746 /// Returns: Newly created SmartCard object, or nil if slot does not contain valid card.
747 #[unsafe(method(makeSmartCard))]
748 #[unsafe(method_family = none)]
749 pub unsafe fn makeSmartCard(&self) -> Option<Retained<TKSmartCard>>;
750 );
751}
752
753/// Methods declared on superclass `NSObject`.
754impl TKSmartCardSlot {
755 extern_methods!(
756 #[unsafe(method(init))]
757 #[unsafe(method_family = init)]
758 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
759
760 #[unsafe(method(new))]
761 #[unsafe(method_family = new)]
762 pub unsafe fn new() -> Retained<Self>;
763 );
764}
765
766extern_class!(
767 /// Represents SmartCard inserted in the slot. Once the card is physically removed from the slot, the session object is invalid and will always fail the operation invoked on it. In order to communicate with the card, an exclusive session must be established.
768 ///
769 /// See also [Apple's documentation](https://developer.apple.com/documentation/cryptotokenkit/tksmartcard?language=objc)
770 #[unsafe(super(NSObject))]
771 #[derive(Debug, PartialEq, Eq, Hash)]
772 pub struct TKSmartCard;
773);
774
775extern_conformance!(
776 unsafe impl NSObjectProtocol for TKSmartCard {}
777);
778
779impl TKSmartCard {
780 extern_methods!(
781 /// Slot in which is this card inserted.
782 #[unsafe(method(slot))]
783 #[unsafe(method_family = none)]
784 pub unsafe fn slot(&self) -> Retained<TKSmartCardSlot>;
785
786 /// Flag indicating whether card is valid, i.e. it was not removed from the reader. Use Key-Value-Observing to be notified about card removal.
787 #[unsafe(method(valid))]
788 #[unsafe(method_family = none)]
789 pub unsafe fn valid(&self) -> bool;
790
791 #[cfg(feature = "TKSmartCardATR")]
792 /// Bitmask containing allowed protocols to be used when communicating with the card. This property is consulted only during connection to the card, changes are not propagated to already connected session. By default, any protocol can be used.
793 #[unsafe(method(allowedProtocols))]
794 #[unsafe(method_family = none)]
795 pub unsafe fn allowedProtocols(&self) -> TKSmartCardProtocol;
796
797 #[cfg(feature = "TKSmartCardATR")]
798 /// Setter for [`allowedProtocols`][Self::allowedProtocols].
799 #[unsafe(method(setAllowedProtocols:))]
800 #[unsafe(method_family = none)]
801 pub unsafe fn setAllowedProtocols(&self, allowed_protocols: TKSmartCardProtocol);
802
803 #[cfg(feature = "TKSmartCardATR")]
804 /// Protocol used for communication with the SmartCard. If no card session is established, TKSmartCardProtocolNone is set.
805 #[unsafe(method(currentProtocol))]
806 #[unsafe(method_family = none)]
807 pub unsafe fn currentProtocol(&self) -> TKSmartCardProtocol;
808
809 /// Flag indicating whether card session should be considered as sensitive. Sensitive session always gets card after reset before communicating with it and never leaves card without reset to be used by another SmartCard object. This might be important in case that card session contain some important state which should not leak to another SmartCard object (possibly running in another, foreign application). Default is NO.
810 #[unsafe(method(sensitive))]
811 #[unsafe(method_family = none)]
812 pub unsafe fn sensitive(&self) -> bool;
813
814 /// Setter for [`sensitive`][Self::sensitive].
815 #[unsafe(method(setSensitive:))]
816 #[unsafe(method_family = none)]
817 pub unsafe fn setSensitive(&self, sensitive: bool);
818
819 /// User-specified context kept as long as the card is powered. Once the card is removed or another TKSmartCard object opens session, this property is automatically set to nil.
820 #[unsafe(method(context))]
821 #[unsafe(method_family = none)]
822 pub unsafe fn context(&self) -> Option<Retained<AnyObject>>;
823
824 /// Setter for [`context`][Self::context].
825 #[unsafe(method(setContext:))]
826 #[unsafe(method_family = none)]
827 pub unsafe fn setContext(&self, context: Option<&AnyObject>);
828
829 #[cfg(feature = "block2")]
830 /// Begins session with the card.
831 ///
832 /// When session exists, other requests for sessions from other card objects to the same card are blocked. Session is reference-counted, the same amount of 'end' calls must be done to really terminate the session. Note that finishing session does not automatically mean that the card is disconnected; it only happens when another session from different card object is requested.
833 ///
834 /// Parameter `success`: Signals whether session was successfully started.
835 ///
836 /// Parameter `error`: More information about error preventing the transaction to start
837 #[unsafe(method(beginSessionWithReply:))]
838 #[unsafe(method_family = none)]
839 pub unsafe fn beginSessionWithReply(
840 &self,
841 reply: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
842 );
843
844 #[cfg(feature = "block2")]
845 /// Transmits raw command to the card. This call is allowed only inside session.
846 ///
847 /// Parameter `request`: Request part of APDU
848 ///
849 /// Parameter `reponse`: Response part of APDU, or nil if communication with the card failed
850 ///
851 /// Parameter `error`: Error details when communication with the card failed
852 #[unsafe(method(transmitRequest:reply:))]
853 #[unsafe(method_family = none)]
854 pub unsafe fn transmitRequest_reply(
855 &self,
856 request: &NSData,
857 reply: &block2::DynBlock<dyn Fn(*mut NSData, *mut NSError)>,
858 );
859
860 /// Terminates the transaction. If no transaction is pending any more, the connection will be closed if there is another session in the system waiting for the transaction.
861 #[unsafe(method(endSession))]
862 #[unsafe(method_family = none)]
863 pub unsafe fn endSession(&self);
864
865 /// Creates a new user interaction object for secure PIN verification using the SmartCard reader facilities (typically a HW keypad).
866 ///
867 /// Note: This interaction is only allowed within a session.
868 ///
869 /// Parameter `PINFormat`: PIN format descriptor.
870 ///
871 /// Parameter `APDU`: Predefined APDU in which the SmartCard reader fills in the PIN.
872 ///
873 /// Parameter `PINByteOffset`: Offset in bytes within APDU data field to mark a location of a PIN block for filling in the entered PIN (currently unused, must be 0).
874 ///
875 /// Returns: A new user interaction object, or nil if this feature is not supported by the SmartCard reader. After the interaction has been successfully completed the operation result is available in the result properites.
876 #[unsafe(method(userInteractionForSecurePINVerificationWithPINFormat:APDU:PINByteOffset:))]
877 #[unsafe(method_family = none)]
878 pub unsafe fn userInteractionForSecurePINVerificationWithPINFormat_APDU_PINByteOffset(
879 &self,
880 pin_format: &TKSmartCardPINFormat,
881 apdu: &NSData,
882 pin_byte_offset: NSInteger,
883 ) -> Option<Retained<TKSmartCardUserInteractionForSecurePINVerification>>;
884
885 /// Creates a new user interaction object for secure PIN change using the SmartCard reader facilities (typically a HW keypad).
886 ///
887 /// Note: This interaction is only allowed within a session.
888 ///
889 /// Parameter `PINFormat`: PIN format descriptor.
890 ///
891 /// Parameter `APDU`: Predefined APDU in which the SmartCard reader fills in the PIN(s).
892 ///
893 /// Parameter `currentPINByteOffset`: Offset in bytes within APDU data field to mark a location of a PIN block for filling in the current PIN.
894 ///
895 /// Parameter `newPINByteOffset`: Offset in bytes within APDU data field to mark a location of a PIN block for filling in the new PIN.
896 ///
897 /// Returns: A new user interaction object, or nil if this feature is not supported by the SmartCard reader. After the interaction has been successfully completed the operation result is available in the result properites.
898 #[unsafe(method(userInteractionForSecurePINChangeWithPINFormat:APDU:currentPINByteOffset:newPINByteOffset:))]
899 #[unsafe(method_family = none)]
900 pub unsafe fn userInteractionForSecurePINChangeWithPINFormat_APDU_currentPINByteOffset_newPINByteOffset(
901 &self,
902 pin_format: &TKSmartCardPINFormat,
903 apdu: &NSData,
904 current_pin_byte_offset: NSInteger,
905 new_pin_byte_offset: NSInteger,
906 ) -> Option<Retained<TKSmartCardUserInteractionForSecurePINChange>>;
907 );
908}
909
910/// Methods declared on superclass `NSObject`.
911impl TKSmartCard {
912 extern_methods!(
913 #[unsafe(method(init))]
914 #[unsafe(method_family = init)]
915 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
916
917 #[unsafe(method(new))]
918 #[unsafe(method_family = new)]
919 pub unsafe fn new() -> Retained<Self>;
920 );
921}
922
923/// APDULevelTransmit.
924/// Extension of base TKSmartCard interface implementing ISO7816-3 and ISO7816-4 structured APDU transmission.
925impl TKSmartCard {
926 extern_methods!(
927 /// CLA byte which will be used for sendIns: APDU transmits. Default value is 0x00.
928 #[unsafe(method(cla))]
929 #[unsafe(method_family = none)]
930 pub unsafe fn cla(&self) -> u8;
931
932 /// Setter for [`cla`][Self::cla].
933 #[unsafe(method(setCla:))]
934 #[unsafe(method_family = none)]
935 pub unsafe fn setCla(&self, cla: u8);
936
937 /// Flag indicating whether extended length APDUs should be used. It is automatically enabled only when used slot supports transmitting extended length commands and card announces that extended length APDU are supported in its ATR. However, caller can explicitly override this decision.
938 #[unsafe(method(useExtendedLength))]
939 #[unsafe(method_family = none)]
940 pub unsafe fn useExtendedLength(&self) -> bool;
941
942 /// Setter for [`useExtendedLength`][Self::useExtendedLength].
943 #[unsafe(method(setUseExtendedLength:))]
944 #[unsafe(method_family = none)]
945 pub unsafe fn setUseExtendedLength(&self, use_extended_length: bool);
946
947 /// Flag indicating whether command chaining of APDU with data field longer than 255 bytes can be used. It is automatically enabled when card announces that command chaining is supported in its ATR. However, caller can explicitly override this decision.
948 #[unsafe(method(useCommandChaining))]
949 #[unsafe(method_family = none)]
950 pub unsafe fn useCommandChaining(&self) -> bool;
951
952 /// Setter for [`useCommandChaining`][Self::useCommandChaining].
953 #[unsafe(method(setUseCommandChaining:))]
954 #[unsafe(method_family = none)]
955 pub unsafe fn setUseCommandChaining(&self, use_command_chaining: bool);
956
957 #[cfg(feature = "block2")]
958 /// Transmits APDU to the card and returns response.
959 ///
960 /// Asynchronous high level variant of command for transmitting APDU to the card. Handles all ISO7816-4 APDU cases translation to proper sequences according to used protocol. Consults useExtendedAPDU and useCommandChaining properties and uses these modes whenever appropriate and beneficial for sending requested APDU request.
961 ///
962 /// Parameter `ins`: INS code of the APDU
963 ///
964 /// Parameter `p1`: P1 code of the APDU
965 ///
966 /// Parameter `p2`: P2 code of the APDU
967 ///
968 /// Parameter `requestData`: Data field of the APDU, or nil if no input data field should be present (i.e case1 or case2 APDUs). Length of the data serves as Lc field of the APDU.
969 ///
970 /// Parameter `le`: Expected number of bytes to be returned, or nil if no output data are expected (i.e. case1 or case3 APDUs). To get as much bytes as card provides, pass
971 /// @
972 /// 0.
973 ///
974 /// Parameter `replyData`: Block of returned data without SW1SW2 bytes, or nil if an error occured.
975 ///
976 /// Parameter `sw`: SW1SW2 result code, first two bytes of returned card's reply.
977 ///
978 /// Parameter `error`: Contains error details when nil is returned. Specific error is also filled in if there was no communication error, but card returned other SW code than 0x9000.
979 #[unsafe(method(sendIns:p1:p2:data:le:reply:))]
980 #[unsafe(method_family = none)]
981 pub unsafe fn sendIns_p1_p2_data_le_reply(
982 &self,
983 ins: u8,
984 p1: u8,
985 p2: u8,
986 request_data: Option<&NSData>,
987 le: Option<&NSNumber>,
988 reply: &block2::DynBlock<dyn Fn(*mut NSData, u16, *mut NSError)>,
989 );
990
991 #[cfg(feature = "block2")]
992 /// Synchronous variant of session creation. Begins the session, executes given block and ends session.
993 ///
994 /// Parameter `error`: Error receiving more information when transaction failed to start or block failed for some reason.
995 ///
996 /// Parameter `block`: Block to be executed when the session was successfully begun.
997 ///
998 /// Returns: Returns YES if the session was successfully begun and block returned YES, otherwise NO.
999 #[unsafe(method(inSessionWithError:executeBlock:))]
1000 #[unsafe(method_family = none)]
1001 pub unsafe fn inSessionWithError_executeBlock(
1002 &self,
1003 error: Option<&mut Option<Retained<NSError>>>,
1004 block: &block2::DynBlock<dyn Fn(*mut *mut NSError) -> Bool>,
1005 ) -> bool;
1006
1007 /// Transmits APDU to the card and returns response.
1008 ///
1009 /// Synchronous high level variant of command for transmitting APDU to the card. Handles all ISO7816-4 APDU cases translation to proper sequences according to used protocol. Should be used in block passed to -[TKSmartCard inSessionWithError:executeBlock:] method.
1010 ///
1011 /// Parameter `ins`: INS code of the APDU
1012 ///
1013 /// Parameter `p1`: P1 code of the APDU
1014 ///
1015 /// Parameter `p2`: P2 code of the APDU
1016 ///
1017 /// Parameter `data`: Data field of the APDU. Length of the data serves as Lc field of the APDU
1018 ///
1019 /// Parameter `le`: Expected number of bytes to be returned, or nil if no output data are expected (i.e. case1 or case3 APDUs). To get as much bytes as card provides, pass
1020 /// @
1021 /// 0.
1022 ///
1023 /// Parameter `sw`: On output, filled with SW1SW2 result code
1024 ///
1025 /// Parameter `error`: Contains error details when nil is returned. Specific error is also filled in if there was no communication error, but card returned other SW code than 0x9000.
1026 ///
1027 /// Returns: Returned data field, excluding SW status bytes. If an error occured, returns nil.
1028 #[unsafe(method(sendIns:p1:p2:data:le:sw:error:_))]
1029 #[unsafe(method_family = none)]
1030 pub unsafe fn sendIns_p1_p2_data_le_sw_error(
1031 &self,
1032 ins: u8,
1033 p1: u8,
1034 p2: u8,
1035 request_data: Option<&NSData>,
1036 le: Option<&NSNumber>,
1037 sw: NonNull<u16>,
1038 ) -> Result<Retained<NSData>, Retained<NSError>>;
1039 );
1040}