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) -> BoolParameters
inputThe string that should be tested.
patternThe 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) -> BoolParameters
inputThe string that should be tested.
patternThe 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> ) -> OSStatusParameters
connectionPtrA pointer to the paired stream, from which data should be read and decrypted.
dataPtrA pointer to a byte array, where the decrypted data should be stored.
dataLengthPtrA 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> ) -> OSStatusParameters
connectionPtrA pointer to the paired stream, to which data should be encrypted and written.
dataPtrA pointer to the byte array containing the data which should be written.
dataLengthPtrA 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 ) -> AuthenticationContextParameters
reasonThe reason describing the purpose of the authentication.
completionA function that is called after the authentication finished (not neccessarily successfully).
authenticationErrorUpon successful authentication this is
nilelse it contains the cause for failure.Return Value
The authentication context.
View on GitHub
Functions Reference