Functions
The following functions are available globally.
-
Infix operator for testing if a string matches a regular expression.
Example
let sentence = "The world is flat." if sentence =~ "^The" { // The sentence starts with "The" }
Declaration
Swift
public func =~ (input: String, pattern: String) -> Bool
Parameters
input
The string that should be tested.
pattern
The regular expression that should be used for testing.
-
Infix operator for testing if a string matches a regular expression.
Example
let pattern = RegularExpression("^The")! let sentence = "The world is flat." if sentence =~ pattern { // The sentence starts with "The" }
Declaration
Swift
public func =~ (input: String, pattern: RegularExpression) -> Bool
Parameters
input
The string that should be tested.
pattern
The regular expression that should be used for testing.
-
The function that actually handles TLS reading. This has to be a static function, therefore a paired stream is stored inside the connection reference in order to be able to read data from it.
Declaration
Swift
private func tlsRead( connectionPtr: SSLConnectionRef, dataPtr: UnsafeMutableRawPointer, dataLengthPtr: UnsafeMutablePointer<Int> ) -> OSStatus
Parameters
connectionPtr
A pointer to the paired stream, from which data should be read and decrypted.
dataPtr
A pointer to a byte array, where the decrypted data should be stored.
dataLengthPtr
A pointer to an integer, where the amount of read bytes is stored.
Return Value
A status, as defined by the secure transport library.
-
A function that actually handles TLS writing. This has to be a static function, therefore a paired stream is stored inside the connection reference in order to be able to write data to it.
Declaration
Swift
private func tlsWrite( connectionPtr: SSLConnectionRef, dataPtr: UnsafeRawPointer, dataLengthPtr: UnsafeMutablePointer<Int> ) -> OSStatus
Parameters
connectionPtr
A pointer to the paired stream, to which data should be encrypted and written.
dataPtr
A pointer to the byte array containing the data which should be written.
dataLengthPtr
A pointer to an integer containing the maximum amount of bytes, that should be written. The number is replaced with the amount of bytes actually written.
Return Value
A status, as defined by the secure transport library.
-
Challenges the user to authenticate as the device owner. Biometric authentication (Face ID or Touch ID) is tried first if available and passcode authentication is used as a fallback.
Examples
var context = authenticateDeviceOwner(reason: "Unlock something") { authenticationError in guard authenticationError == nil else { // Failed to authenticate (the user just might have cancelled) // TODO: Handle error return } // Successfully authenticated unlockSomething() } // Invalidate context context.invalidate()
Note
In order to use Face ID, add [
NSFaceIDUsageDescription
][https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW75] to your [Info.plist
][https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009248-SW1].Declaration
Swift
public func authenticateDeviceOwner( reason: String, completion: @escaping (_ authenticationError: AuthenticationError?) -> Void ) -> AuthenticationContext
Parameters
reason
The reason describing the purpose of the authentication.
completion
A function that is called after the authentication finished (not neccessarily successfully).
authenticationError
Upon successful authentication this is
nil
else it contains the cause for failure.Return Value
The authentication context.