Functions

The following functions are available globally.

  • Converts a string of hexadecimal digits to a Swift array.

    Declaration

    Swift

    public func arrayFrom(hexString: String) -> [UInt8]

    Parameters

    s

    the hex string (must contain an even number of digits)

    Return Value

    a Swift array

  • Converts a Swift UTF-8 String to a Swift array.

    Declaration

    Swift

    public func arrayFrom(string: String) -> [UInt8]

    Parameters

    s

    the string

    Return Value

    a Swift array

  • Converts a string of hexadecimal digits to an NSData object.

    Declaration

    Swift

    public func dataFrom(hexString: String) -> Data

    Parameters

    s

    the hex string (must contain an even number of digits)

    Return Value

    an NSData object

  • Converts a Swift array to an NSData object.

    Declaration

    Swift

    public func dataFrom(byteArray: [UInt8]) -> Data

    Parameters

    a

    the Swift array

    Return Value

    an NSData object

  • Converts a Swift array to a string of hexadecimal digits.

    Declaration

    Swift

    public func hexString(fromArray: [UInt8], uppercase: Bool = false) -> String

    Parameters

    a

    the Swift array

    uppercase

    if true use uppercase for letter digits, lowercase otherwise

    Return Value

    a Swift string

  • Converts a Swift array to a Swift String containing a comma separated list of bytes. This is used to generate test data programmatically.

    Declaration

    Swift

    public func hexList(fromArray: [UInt8]) -> String

    Parameters

    a

    the Swift array

    Return Value

    a Swift string

  • Zero pads a Swift array such that it is an integral number of blockSizeinBytes long.

    Declaration

    Swift

    public func zeroPad(array: [UInt8], blockSize: Int) -> [UInt8]

    Parameters

    a

    the Swift array

    blockSizeInBytes

    the block size in bytes (cunningly enough!)

    Return Value

    a Swift string

  • Zero pads a Swift string (after UTF8 conversion) such that it is an integral number of blockSizeinBytes long.

    Declaration

    Swift

    public func zeroPad(string: String, blockSize: Int) -> [UInt8]

    Parameters

    s

    the Swift array

    blockSizeInBytes

    the block size in bytes (cunningly enough!)

    Return Value

    a Swift string

  • Removes trailing zero padding. Removes each zero ( ie == 0x00 ) byte from the end of the array

    Declaration

    Swift

    public func removeTrailingZeroPadding(array: [UInt8]) -> [UInt8]

    Parameters

    a

    the Swift array

    Return Value

    a Swift array (shorter or equal)