From c6a33d6bf06e2417fa22fd6613e5e3d646effb6e Mon Sep 17 00:00:00 2001
From: Andrew Bulhak <andrew.bulhak@mullvad.net>
Date: Tue, 5 Mar 2024 15:20:41 +0100
Subject: [PATCH] Define the PostQuantumKeyReceiving protocol, along with an
 extension to decode Data

---
 .../Protocols/PostQuantumKeyReceiving.swift   | 27 +++++++++++++++++++
 ios/MullvadVPN.xcodeproj/project.pbxproj      | 12 +++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 ios/MullvadTypes/Protocols/PostQuantumKeyReceiving.swift

diff --git a/ios/MullvadTypes/Protocols/PostQuantumKeyReceiving.swift b/ios/MullvadTypes/Protocols/PostQuantumKeyReceiving.swift
new file mode 100644
index 000000000000..577e2f3d63a8
--- /dev/null
+++ b/ios/MullvadTypes/Protocols/PostQuantumKeyReceiving.swift
@@ -0,0 +1,27 @@
+//
+//  PostQuantumKeyReceiving.swift
+//  MullvadTypes
+//
+//  Created by Andrew Bulhak on 2024-03-05.
+//  Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import WireGuardKitTypes
+
+protocol PostQuantumKeyReceiving {
+    func receivePostQuantumKey(_ key: PrivateKey)
+}
+
+enum PostQuantumKeyReceivingError: Error {
+    case invalidKey
+}
+
+extension PostQuantumKeyReceiving {
+    func receivePostQuantumKey(_ keyData: Data) throws {
+        guard let key = PrivateKey(rawValue: keyData) else {
+            throw PostQuantumKeyReceivingError.invalidKey
+        }
+        receivePostQuantumKey(key)
+    }
+}
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 95361429333c..ca2ba8b21114 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -44,6 +44,7 @@
 		449872E42B7CB96300094DDC /* TunnelSettingsUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449872E32B7CB96300094DDC /* TunnelSettingsUpdateTests.swift */; };
 		449EB9FD2B95F8AD00DFA4EB /* DeviceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449EB9FC2B95F8AD00DFA4EB /* DeviceMock.swift */; };
 		449EB9FF2B95FF2500DFA4EB /* AccountMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449EB9FE2B95FF2500DFA4EB /* AccountMock.swift */; };
+		449EBA262B975B9700DFA4EB /* PostQuantumKeyReceiving.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449EBA252B975B9700DFA4EB /* PostQuantumKeyReceiving.swift */; };
 		44DD7D242B6CFFD70005F67F /* StartTunnelOperationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */; };
 		44DD7D272B6D18FB0005F67F /* MockTunnelInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D262B6D18FB0005F67F /* MockTunnelInteractor.swift */; };
 		44DD7D292B7113CA0005F67F /* MockTunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D282B7113CA0005F67F /* MockTunnel.swift */; };
@@ -1298,6 +1299,7 @@
 		449872E32B7CB96300094DDC /* TunnelSettingsUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelSettingsUpdateTests.swift; sourceTree = "<group>"; };
 		449EB9FC2B95F8AD00DFA4EB /* DeviceMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceMock.swift; sourceTree = "<group>"; };
 		449EB9FE2B95FF2500DFA4EB /* AccountMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountMock.swift; sourceTree = "<group>"; };
+		449EBA252B975B9700DFA4EB /* PostQuantumKeyReceiving.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostQuantumKeyReceiving.swift; sourceTree = "<group>"; };
 		44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartTunnelOperationTests.swift; sourceTree = "<group>"; };
 		44DD7D262B6D18FB0005F67F /* MockTunnelInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTunnelInteractor.swift; sourceTree = "<group>"; };
 		44DD7D282B7113CA0005F67F /* MockTunnel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTunnel.swift; sourceTree = "<group>"; };
@@ -2203,6 +2205,14 @@
 			path = MullvadSettings;
 			sourceTree = "<group>";
 		};
+		449EBA242B975B7C00DFA4EB /* Protocols */ = {
+			isa = PBXGroup;
+			children = (
+				449EBA252B975B9700DFA4EB /* PostQuantumKeyReceiving.swift */,
+			);
+			path = Protocols;
+			sourceTree = "<group>";
+		};
 		44DD7D252B6D18E90005F67F /* Mocks */ = {
 			isa = PBXGroup;
 			children = (
@@ -2229,6 +2239,7 @@
 		581943F228F8014500B0CB5E /* MullvadTypes */ = {
 			isa = PBXGroup;
 			children = (
+				449EBA242B975B7C00DFA4EB /* Protocols */,
 				584D26BE270C550B004EA533 /* AnyIPAddress.swift */,
 				586A951329013235007BAF2B /* AnyIPEndpoint.swift */,
 				06AC113628F83FD70037AF9A /* Cancellable.swift */,
@@ -5451,6 +5462,7 @@
 				7AF9BE8C2A321D1F00DBFEDB /* RelayFilter.swift in Sources */,
 				58D22414294C90210029F5F8 /* RelayLocation.swift in Sources */,
 				581DA2732A1E227D0046ED47 /* RESTTypes.swift in Sources */,
+				449EBA262B975B9700DFA4EB /* PostQuantumKeyReceiving.swift in Sources */,
 				58D22417294C90210029F5F8 /* FixedWidthInteger+Arithmetics.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;