Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Drop the Crypto facade in the cast app

Manav Rathi2632f8fcc3d0
diff --git a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
index 231f8c6403..e86791fa36 100644
--- a/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
+++ b/mobile/native/apple/apps/cast/Cast/Services/CastPairingService.swift
@@ -63,12 +63,8 @@ class RealCastPairingService {
return newInterval
}
- private func generateKeyPair() throws -> (publicKey: Data, privateKey: Data) {
- try Crypto.generateKeyPair()
- }
-
func registerDevice() async throws -> CastDevice {
- let keys = try generateKeyPair()
+ let keys = generateKeyPair()
let publicKeyBase64 = keys.publicKey.base64EncodedString()
print("POST \(baseURL)/cast/device-info")
@@ -186,10 +182,10 @@ class RealCastPairingService {
throw CastError.decryptionError("Invalid encrypted cast payload")
}
- let decryptedData = try Crypto.sealedBoxOpen(
- cipherText: encryptedBytes,
+ let decryptedData = try openSealedBox(
+ ciphertext: encryptedBytes,
publicKey: publicKey,
- secretKey: privateKey
+ privateKey: privateKey
)
// Handle potential base64 preprocessing from mobile client
diff --git a/mobile/native/apple/apps/cast/Cast/Services/Crypto.swift b/mobile/native/apple/apps/cast/Cast/Services/Crypto.swift
deleted file mode 100644
index 7a231853c2..0000000000
--- a/mobile/native/apple/apps/cast/Cast/Services/Crypto.swift
+++ /dev/null
@@ -1,20 +0,0 @@
-import Foundation
-
-enum Crypto {
- static func generateKeyPair() throws -> (publicKey: Data, privateKey: Data) {
- let keyPair = Cast.generateKeyPair()
- return (publicKey: keyPair.publicKey, privateKey: keyPair.privateKey)
- }
-
- static func secretBoxOpen(cipherText: Data, nonce: Data, key: Data) throws -> Data {
- try Cast.openSecretBox(ciphertext: cipherText, nonce: nonce, key: key)
- }
-
- static func sealedBoxOpen(cipherText: Data, publicKey: Data, secretKey: Data) throws -> Data {
- try Cast.openSealedBox(ciphertext: cipherText, publicKey: publicKey, privateKey: secretKey)
- }
-
- static func decryptSecretStream(encryptedData: Data, key: Data, header: Data) throws -> Data {
- try Cast.decryptSecretStream(encryptedData: encryptedData, header: header, key: key)
- }
-}
diff --git a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
index c5b5c27eaf..cafd67f92f 100644
--- a/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
+++ b/mobile/native/apple/apps/cast/Cast/ViewModels/SlideshowService.swift
@@ -1089,7 +1089,7 @@ class RealSlideshowService: ObservableObject {
}
do {
- let decryptedFileKey = try Crypto.secretBoxOpen(cipherText: encryptedKeyData, nonce: nonceData, key: collectionKeyData)
+ let decryptedFileKey = try openSecretBox(ciphertext: encryptedKeyData, nonce: nonceData, key: collectionKeyData)
return decryptedFileKey
} catch {
throw CastError.decryptionError("SecretBox decryption failed for file key: \(error)")
@@ -1106,7 +1106,7 @@ class RealSlideshowService: ObservableObject {
print("XChaCha20: encrypted=\(encryptedBytes.count)b, header=\(headerBytes.count)b, key=\(fileKey.count)b")
do {
- let decryptedData = try Crypto.decryptSecretStream(encryptedData: encryptedBytes, key: fileKey, header: headerBytes)
+ let decryptedData = try decryptSecretStream(encryptedData: encryptedBytes, header: headerBytes, key: fileKey)
print("Metadata decrypted using Rust crypto: \(decryptedData.count) bytes")
return decryptedData
} catch {
@@ -1123,7 +1123,7 @@ class RealSlideshowService: ObservableObject {
if verboseDecryptionLogging { print("File decryption: encrypted=\(encryptedData.count)b, header=\(headerBytes.count)b, key=\(fileKey.count)b") }
do {
- return try Crypto.decryptSecretStream(encryptedData: encryptedData, key: fileKey, header: headerBytes)
+ return try decryptSecretStream(encryptedData: encryptedData, header: headerBytes, key: fileKey)
} catch {
throw CastError.decryptionError("file content decryption failed: \(error)")
}