Token
public final class Token
Class that represents connection to a smart card (or more generally, any cryptographic device). Token objects are obtained by calling the Reader.connect(completionHandler:)
method.
-
Gets the token model name.
Declaration
Swift
public func getModel() -> String
Return Value
The model name.
-
Gets the token serial number.
Declaration
Swift
public func getSerialNumber() -> String
Return Value
The serial number.
-
Gets the token label name.
Declaration
Swift
public func getLabel() -> String
Return Value
The label name.
-
Gets the token manufacturer name.
Declaration
Swift
public func getManufacturer() -> String
Return Value
The manufacturer name..
-
Returns if this token has been initialized for uses.
Note
This API does not provide any means to initialize a token.
Declaration
Swift
public func isInitialized() -> Bool
Return Value
true
if this token has been initialized;false
otherwise. -
Returns if this token allows user authentication through a hardware protected device (like a PIN pad reader, or using biometric recognition).
Declaration
Swift
public func hasProtectedAuthPath() -> Bool
Return Value
true
if this token allows user authentication through a hardware protected path,false
otherwise. -
Gets license validity for this card.
Declaration
Swift
public func isLicenseValid(completionHandler: @escaping (_ isValid: Bool?, _ error: NSError?) -> Void)
Parameters
completionHandler
The completion handler block to be called as soon as the operation has been performed.
isValid
contains whether license is valid. Error can occur if theSCMEnvironment
has been released for instance. -
Gets the end date for the license validity.
Declaration
Swift
public func getLicenseEndDate(completionHandler: @escaping (_ endDate: String?, _ error: NSError?) -> Void)
Parameters
completionHandler
The completion handler block to be called as soon as the operation has been performed.
endDate
contains the end date, as a string with the “YYYYMMDD” format. The return value may be “000000” for licenses with permanent validity. The return value may be an empty string for cards that do not have a license loaded, or for cards that benefit from a global licensing scheme. These cases can be identified depending on theisLicenseValid
result. Error can occur if theSCMEnvironment
has been released for instance. -
Generates an App License for the current token, if current API embeds this mechanism.
Note that the resulting license will be stored in app data; thus, for a same smart card, calling this function on each app instance (on a different device, after a re-installation or if app data is cleared) using this smart card is needed.
Declaration
Swift
public func generateAppLicense(completionHandler: @escaping (_ error: NSError?) -> Void)
Parameters
completionHandler(error)
The completion handler block to be called as soon as the operation has been performed. Error can occur if the
SCMEnvironment
has been released or typically if this API does not embed App License Generation. -
Disconnects from the token.
After performing this function, the token becomes unavailable.
Note:
If you wish to do more operation after you disconnected yourself from the token you should call
Reader.connect(completionHandler:)
in order to get a fresh token.Declaration
Swift
public func disconnect(completionHandler: @escaping (_ error: NSError?) -> Void)
Parameters
completionHandler
The completion handler block to be called as soon as the operation has been performed. It takes the following parameter:
- error
NSError?
: an error can occur if theSCMEnvironment
has been released by ARC or if something bad happened during the release of the token.
Note
The completion handler is executed on the same type ofDispatchQueue
as in the calling code. - error
-
Retrieves all objects found in the token (certificates and keys).
Example:
token.getObjects() { objects, error in if let error = error { print("fail to get objects: " + error.localizedDescription) } else { if let objects = objects { for object in objects { // loop over all object found } } // when done using the token you should release it token.disconnect() { error in if let error = error { print("fail to disconnect: " + error.localizedDescription) } } } }
Note:
- The private objects cannot be returned if the associated PIN has not been verified previously.
- Take in consideration that the API does not internally keep references to the retrieved obejcts, and calling this method will always return newly created
TokenObject
instances, even if the objects have been previously retrieved. To check whether two
TokenObject
instances refer to the same physical object in the card, the==
operator can be used.
Declaration
Swift
public func getObjects(completionHandler: @escaping (_ objects: Array<TokenObject>?, _ error: NSError?) -> Void)
Parameters
completionHandler
The completion handler block to be called as soon as the objets are retrieved. It takes the following parameters:
- objects
Array<TokenObject>?
: An array ofTokenObject
. - error
NSError?
:nil
if the objects were retrieved successfully; otherwise an error encapsulates the reason of failure.
Note
The completion handler is executed on the same type ofDispatchQueue
as in the calling code.