I'm busy working with the Authorization Services APIs and came across an initializer for the type AuthorizationExternalForm that takes a 32 element tuple of UInt8s.
init(bytes: (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8))
Ref here: https://developer.apple.com/documentation/security/authorizationexternalform/1396798-init
Is there a shortcut to converting the contents of Data to that without explicitly referencing each element in a byte array?
I recommend that you wrap this up in a custom initialiser. Here’s the code I use:
extension AuthorizationExternalForm {
init?(data: Data) {
self.init()
let bytesCount = MemoryLayout.size(ofValue: self.bytes)
guard data.count == bytesCount else {
return nil
}
data.withUnsafeBytes { src in
withUnsafeMutablePointer(to: &self.bytes) { dst in
_ = memcpy(dst, src.baseAddress!, bytesCount)
}
}
}
}
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"