Skip to content

Commit ea39225

Browse files
committed
Replace swift-sodium with TweetNacl
- This works around the fact that swift-sodium cannot build correctly on Carthage due to the lack of .xcframework support.
1 parent bfb385f commit ea39225

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
github "ashleymills/Reachability.swift" ~> 5.0.0
2-
github "jedisct1/swift-sodium" == 0.8.0
2+
github "bitmark-inc/tweetnacl-swiftwrap" ~> 1.0
33
github "pusher/NWWebSocket" ~> 0.3.0

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
github "ashleymills/Reachability.swift" "v5.0.0"
2-
github "jedisct1/swift-sodium" "0.8.0"
2+
github "bitmark-inc/tweetnacl-swiftwrap" "1.0.2"
33
github "pusher/NWWebSocket" "0.3.0"

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ let package = Package(
1111
dependencies: [
1212
.package(url: "https://github.com/ashleymills/Reachability.swift.git", .upToNextMajor(from: "5.0.0")),
1313
.package(url: "https://github.com/pusher/NWWebSocket.git", .upToNextMajor(from: "0.3.0")),
14-
.package(url: "https://github.com/jedisct1/swift-sodium", .upToNextMajor(from: "0.9.0")),
14+
.package(url: "https://github.com/bitmark-inc/tweetnacl-swiftwrap", .upToNextMajor(from: "1.0.0")),
1515
],
1616
targets: [
1717
.target(
1818
name: "PusherSwiftWithEncryption",
1919
dependencies: [
2020
"Reachability",
2121
"NWWebSocket",
22-
"Sodium",
22+
"TweetNacl",
2323
],
2424
path: "Sources",
2525
exclude: ["PusherSwift-Only"]

PusherSwiftWithEncryption.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Pod::Spec.new do |s|
1414
s.exclude_files = ['Sources/PusherSwift-Only/**/*.swift']
1515

1616
s.dependency 'ReachabilitySwift', '~> 5.0'
17-
s.dependency 'Sodium', '0.8.0'
17+
s.dependency 'TweetNacl', '~> 1.0.0'
1818
s.dependency 'NWWebSocket', '~> 0.3.0'
1919

2020
s.ios.deployment_target = '13.0'
2121
s.osx.deployment_target = '10.15'
22+
s.tvos.deployment_target = '13.0'
2223
end

Sources/PusherSwiftWithEncryption-Only/PusherDecryptor.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
import Sodium
2+
import TweetNacl
33

44
class PusherDecryptor {
55

@@ -9,8 +9,6 @@ class PusherDecryptor {
99

1010
}
1111

12-
private static let sodium = Sodium()
13-
1412
static func decrypt(data: String?, decryptionKey: String?) throws -> String? {
1513
guard let data = data else {
1614
return nil
@@ -25,9 +23,9 @@ class PusherDecryptor {
2523
let nonce = try self.decodedNonce(fromEncryptedData: encryptedData)
2624
let secretKey = try self.decodedDecryptionKey(fromDecryptionKey: decryptionKey)
2725

28-
guard let decryptedData = self.sodium.secretBox.open(authenticatedCipherText: cipherText,
29-
secretKey: secretKey,
30-
nonce: nonce),
26+
guard let decryptedData = try? NaclSecretBox.open(box: cipherText,
27+
nonce: nonce,
28+
key: secretKey),
3129
let decryptedString = String(bytes: decryptedData, encoding: .utf8) else {
3230
throw PusherEventError.invalidDecryptionKey
3331
}
@@ -44,28 +42,28 @@ class PusherDecryptor {
4442
return encryptedData
4543
}
4644

47-
private static func decodedCipherText(fromEncryptedData encryptedData: EncryptedData) throws -> Bytes {
45+
private static func decodedCipherText(fromEncryptedData encryptedData: EncryptedData) throws -> Data {
4846
guard let decodedCipherText = Data(base64Encoded: encryptedData.ciphertext) else {
4947
throw PusherEventError.invalidEncryptedData
5048
}
5149

52-
return Bytes(decodedCipherText)
50+
return decodedCipherText
5351
}
5452

55-
private static func decodedNonce(fromEncryptedData encryptedData: EncryptedData) throws -> SecretBox.Nonce {
53+
private static func decodedNonce(fromEncryptedData encryptedData: EncryptedData) throws -> Data {
5654
guard let decodedNonce = Data(base64Encoded: encryptedData.nonce) else {
5755
throw PusherEventError.invalidEncryptedData
5856
}
5957

60-
return SecretBox.Nonce(decodedNonce)
58+
return decodedNonce
6159
}
6260

63-
private static func decodedDecryptionKey(fromDecryptionKey decryptionKey: String) throws -> SecretBox.Key {
61+
private static func decodedDecryptionKey(fromDecryptionKey decryptionKey: String) throws -> Data {
6462
guard let decodedDecryptionKey = Data(base64Encoded: decryptionKey) else {
6563
throw PusherEventError.invalidDecryptionKey
6664
}
6765

68-
return SecretBox.Key(decodedDecryptionKey)
66+
return decodedDecryptionKey
6967
}
7068

7169
static func isDecryptionAvailable() -> Bool {

0 commit comments

Comments
 (0)