Changeset View
Changeset View
Standalone View
Standalone View
native/expo-modules/comm-expo-package/ios/AESCryptoModule.swift
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | private func decrypt(rawKey: Uint8Array, | ||||
} | } | ||||
let key = SymmetricKey(data: rawKey.data()) | let key = SymmetricKey(data: rawKey.data()) | ||||
let sealedBox = try AES.GCM.SealedBox(combined: sealedData.data()) | let sealedBox = try AES.GCM.SealedBox(combined: sealedData.data()) | ||||
let plaintext = try AES.GCM.open(sealedBox, using: key) | let plaintext = try AES.GCM.open(sealedBox, using: key) | ||||
plaintext.copyBytes(to: destination.rawBufferPtr()) | plaintext.copyBytes(to: destination.rawBufferPtr()) | ||||
} | } | ||||
// MARK: - Utilities | |||||
extension TypedArray { | |||||
func data() -> Data { | |||||
Data(bytes: self.rawPointer, count: self.byteLength) | |||||
} | |||||
func rawBufferPtr() -> UnsafeMutableRawBufferPointer { | |||||
UnsafeMutableRawBufferPointer(start: self.rawPointer, | |||||
count: self.byteLength) | |||||
} | |||||
} | |||||
// MARK: - Exception definitions | // MARK: - Exception definitions | ||||
private class InvalidKeyLengthException: Exception { | private class InvalidKeyLengthException: Exception { | ||||
override var reason: String { | override var reason: String { | ||||
"The AES key has invalid length" | "The AES key has invalid length" | ||||
} | } | ||||
} | } | ||||
Show All 11 Lines |