Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypto): Renaming CryptorModule with CryptoModule #145

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
name: swift
scm: github.com/pubnub/swift
version: "6.2.0"
version: "6.2.1"
schema: 1
changelog:
- date: 2023-10-23
version: 6.2.1
changes:
- type: bug
text: "Align on namings across all supported platforms."
- date: 2023-10-16
version: v6.2.0
changes:
Expand Down Expand Up @@ -497,7 +502,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNub
location: https://github.com/pubnub/swift/archive/refs/tags/6.2.0.zip
location: https://github.com/pubnub/swift/archive/refs/tags/6.2.1.zip
supported-platforms:
supported-operating-systems:
macOS:
Expand Down
2 changes: 1 addition & 1 deletion Examples/Sources/ConfigDetailTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ConfigDetailTableViewController: UITableViewController {
case .subscribeKey:
return config.subscribeKey
case .cipherKey:
return config.cryptorModule?.description ?? "CryptorModule Not Found"
return config.cryptoModule?.description ?? "CryptoModule Not Found"
case .authKey:
return config.authKey
case .uuid:
Expand Down
24 changes: 12 additions & 12 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
35FE941B22EFE5400051C455 /* EventStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35FE941A22EFE5400051C455 /* EventStreamTests.swift */; };
35FE941F22F0929A0051C455 /* RequestRetrierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35FE941E22F0929A0051C455 /* RequestRetrierTests.swift */; };
3D6265D72ABCA79100FDD5E6 /* CryptorUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D6265D62ABCA79100FDD5E6 /* CryptorUtils.swift */; };
3D758DBF2AAA1C49005D2B36 /* CryptorModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DBE2AAA1C49005D2B36 /* CryptorModule.swift */; };
3D758DBF2AAA1C49005D2B36 /* CryptoModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DBE2AAA1C49005D2B36 /* CryptoModule.swift */; };
3D758DC82AB06A12005D2B36 /* CryptoInputStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DC62AB06A12005D2B36 /* CryptoInputStream.swift */; };
3D758DC92AB06A12005D2B36 /* CryptoStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DC72AB06A12005D2B36 /* CryptoStream.swift */; };
3D758DCB2AB06A2D005D2B36 /* Cryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D758DCA2AB06A2D005D2B36 /* Cryptor.swift */; };
Expand Down Expand Up @@ -911,7 +911,7 @@
35FE941A22EFE5400051C455 /* EventStreamTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventStreamTests.swift; sourceTree = "<group>"; };
35FE941E22F0929A0051C455 /* RequestRetrierTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestRetrierTests.swift; sourceTree = "<group>"; };
3D6265D62ABCA79100FDD5E6 /* CryptorUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptorUtils.swift; sourceTree = "<group>"; };
3D758DBE2AAA1C49005D2B36 /* CryptorModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptorModule.swift; sourceTree = "<group>"; };
3D758DBE2AAA1C49005D2B36 /* CryptoModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptoModule.swift; sourceTree = "<group>"; };
3D758DC62AB06A12005D2B36 /* CryptoInputStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoInputStream.swift; sourceTree = "<group>"; };
3D758DC72AB06A12005D2B36 /* CryptoStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoStream.swift; sourceTree = "<group>"; };
3D758DCA2AB06A2D005D2B36 /* Cryptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cryptor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1091,7 +1091,7 @@
isa = PBXGroup;
children = (
3595120F2301DCAB00C9D3AE /* Crypto.swift */,
3D758DBE2AAA1C49005D2B36 /* CryptorModule.swift */,
3D758DBE2AAA1C49005D2B36 /* CryptoModule.swift */,
3D758DCC2AB06B98005D2B36 /* Header */,
3D758DC52AB06983005D2B36 /* Cryptors */,
3D758DC42AB06977005D2B36 /* Miscellaneous */,
Expand Down Expand Up @@ -3078,7 +3078,7 @@
35D0615F2304830600FDB2F9 /* GenericServicePayloadResponse.swift in Sources */,
3D758DD62AB48A6A005D2B36 /* CryptorHeaderWithinStreamFinder.swift in Sources */,
35A66A8E22F911DB00AC67A9 /* SubscribeSessionFactory.swift in Sources */,
3D758DBF2AAA1C49005D2B36 /* CryptorModule.swift in Sources */,
3D758DBF2AAA1C49005D2B36 /* CryptoModule.swift in Sources */,
3D758DD02AB0A8C6005D2B36 /* CryptorVector.swift in Sources */,
3D6265D72ABCA79100FDD5E6 /* CryptorUtils.swift in Sources */,
35D8D4C522EB4600001B07D9 /* AnyJSON.swift in Sources */,
Expand Down Expand Up @@ -3436,7 +3436,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubUser;
Expand Down Expand Up @@ -3483,7 +3483,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubUser;
Expand Down Expand Up @@ -3583,7 +3583,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubSpace;
Expand Down Expand Up @@ -3632,7 +3632,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubSpace;
Expand Down Expand Up @@ -3745,7 +3745,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubMembership;
Expand Down Expand Up @@ -3793,7 +3793,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.pubnub.swift.PubNubMembership;
Expand Down Expand Up @@ -4253,7 +4253,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -4292,7 +4292,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 6.2.0;
MARKETING_VERSION = 6.2.1;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '6.2.0'
s.version = '6.2.1'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => '[email protected]' }
Expand Down
8 changes: 4 additions & 4 deletions Sources/PubNub/APIs/File+PubNub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public extension PubNub {
switch result {
case let .success(response):
do {
let cryptorModule = requestConfig.customConfiguration?.cryptorModule ?? configuration.cryptorModule
let cryptoModule = requestConfig.customConfiguration?.cryptoModule ?? configuration.cryptoModule
completion?(.success((
try URLRequest(from: response.payload, uploading: content, cryptorModule: cryptorModule),
try URLRequest(from: response.payload, uploading: content, cryptoModule: cryptoModule),
response.payload.fileId,
response.payload.filename
)))
Expand Down Expand Up @@ -450,7 +450,7 @@ public extension PubNub {
/// - downloadTo: The async `Result` of the method call
/// - Returns: The new file download task. The `urlSessionTask` property can be used to access the underlying `URLSessionDownloadTask`
func createFileURLSessionDownloadTask(
_ taskType: FileDownloadTaskType, session: URLSessionReplaceable, downloadTo url: URL, decrypt: CryptorModule? = nil
_ taskType: FileDownloadTaskType, session: URLSessionReplaceable, downloadTo url: URL, decrypt: CryptoModule? = nil
) -> HTTPFileDownloadTask {
let downloadTask: URLSessionDownloadTask
switch taskType {
Expand All @@ -464,7 +464,7 @@ public extension PubNub {
task: downloadTask,
session: session.configuration.identifier,
downloadTo: url,
cryptorModule: decrypt ?? configuration.cryptorModule
cryptoModule: decrypt ?? configuration.cryptoModule
)

// Create task map inside Delegate
Expand Down
6 changes: 3 additions & 3 deletions Sources/PubNub/Extensions/URLRequest+PubNub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public extension URLRequest {
internal init(
from response: GenerateUploadURLResponse,
uploading content: PubNub.FileUploadContent,
cryptorModule: CryptorModule? = nil
cryptoModule: CryptoModule? = nil
) throws {
self.init(url: response.uploadRequestURL)
method = response.uploadMethod
Expand All @@ -73,8 +73,8 @@ public extension URLRequest {
let contentLength: Int

// If we were given a Crypto module we should convert the stream to a secure stream
if let cryptorModule = cryptorModule {
switch cryptorModule.encrypt(stream: contentStream, contentLength: content.contentLength) {
if let cryptoModule = cryptoModule {
switch cryptoModule.encrypt(stream: contentStream, contentLength: content.contentLength) {
case .success(let encryptingResult):
finalStream = encryptingResult
contentLength = prefixData.count + ((encryptingResult as? MultipartInputStream)?.length ?? 0) + postfixData.count
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Helpers/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum Constant {

static let pubnubSwiftSDKName: String = "PubNubSwift"

static let pubnubSwiftSDKVersion: String = "6.2.0"
static let pubnubSwiftSDKVersion: String = "6.2.1"

static let appBundleId: String = {
if let info = Bundle.main.infoDictionary,
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Helpers/Crypto/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Foundation

/// Object capable of encryption/decryption
///
/// - Warning: This struct is deprecated. Use ``CryptorModule`` instead.
/// - Warning: This struct is deprecated. Use ``CryptoModule`` instead.
public struct Crypto: Hashable {
/// Key initially provided by the user
let key: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CryptorModule.swift
// CryptoModule.swift
//
// PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks
// Copyright © 2023 PubNub Inc.
Expand Down Expand Up @@ -27,19 +27,29 @@

import Foundation

@available(*, unavailable, renamed: "CryptoModule")
public class CryptorModule {
public static func aesCbcCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptoModule {
preconditionFailure("This method is no longer available")
}
public static func legacyCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptoModule {
preconditionFailure("This method is no longer available")
}
}

/// Object capable of encryption/decryption
public struct CryptorModule {
public struct CryptoModule {
private let defaultCryptor: Cryptor
private let cryptors: [Cryptor]
private let legacyCryptorId: CryptorId = []

typealias Base64EncodedString = String

/// Initializes `CryptorModule` with custom ``Cryptor`` objects capable of encryption and decryption
/// Initializes `CryptoModule` with custom ``Cryptor`` objects capable of encryption and decryption
///
/// Use this constructor if you would like to provide **custom** objects for decryption and encryption and don't want to use PubNub's built-in `Cryptors`.
/// Otherwise, refer to convenience static factory methods such as ``aesCbcCryptoModule(with:withRandomIV:)``
/// and ``legacyCryptoModule(with:withRandomIV:)`` that return `CryptorModule` configured for you.
/// and ``legacyCryptoModule(with:withRandomIV:)`` that return `CryptoModule` configured for you.
///
/// - Parameters:
/// - default: Primary ``Cryptor`` instance used for encryption and decryption
Expand Down Expand Up @@ -251,10 +261,10 @@ public struct CryptorModule {
}
}

/// Convenience methods for creating `CryptorModule`
public extension CryptorModule {
/// Convenience methods for creating `CryptoModule`
public extension CryptoModule {

/// Returns **recommended** `CryptorModule` for encryption/decryption
/// Returns **recommended** `CryptoModule` for encryption/decryption
///
/// - Parameters:
/// - key: Key used for encryption/decryption
Expand All @@ -263,40 +273,40 @@ public extension CryptorModule {
/// This method sets ``AESCBCCryptor`` as the primary object for decryption and encryption. It also
/// instantiates ``LegacyCryptor``under the hood with `withRandomIV`. This way, you can interact with historical
/// messages or messages sent from older clients
static func aesCbcCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptorModule {
CryptorModule(default: AESCBCCryptor(key: key), cryptors: [LegacyCryptor(key: key, withRandomIV: withRandomIV)])
static func aesCbcCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptoModule {
CryptoModule(default: AESCBCCryptor(key: key), cryptors: [LegacyCryptor(key: key, withRandomIV: withRandomIV)])
}

/// Returns legacy `CryptorModule` for encryption/decryption
/// Returns legacy `CryptoModule` for encryption/decryption
///
/// - Parameters:
/// - key: Key used for encryption/decryption
/// - withRandomIV: A flag describing whether random initialization vector should be used
/// - Warning: It's highly recommended to always use ``aesCbcCryptoModule(with:withRandomIV:)``
static func legacyCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptorModule {
CryptorModule(default: LegacyCryptor(key: key, withRandomIV: withRandomIV), cryptors: [AESCBCCryptor(key: key)])
static func legacyCryptoModule(with key: String, withRandomIV: Bool = true) -> CryptoModule {
CryptoModule(default: LegacyCryptor(key: key, withRandomIV: withRandomIV), cryptors: [AESCBCCryptor(key: key)])
}
}

extension CryptorModule: Equatable {
public static func ==(lhs: CryptorModule, rhs: CryptorModule) -> Bool {
extension CryptoModule: Equatable {
public static func ==(lhs: CryptoModule, rhs: CryptoModule) -> Bool {
lhs.cryptors.map { $0.id } == rhs.cryptors.map { $0.id }
}
}

extension CryptorModule: Hashable {
extension CryptoModule: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(cryptors.map { $0.id })
}
}

extension CryptorModule: CustomStringConvertible {
extension CryptoModule: CustomStringConvertible {
public var description: String {
"Default cryptor: \(defaultCryptor.id), others: \(cryptors.map { $0.id })"
}
}

internal extension CryptorModule {
internal extension CryptoModule {
func encrypt(string: String) -> Result<Base64EncodedString, PubNubError> {
guard let data = string.data(using: .utf8) else {
return .failure(PubNubError(
Expand Down
14 changes: 7 additions & 7 deletions Sources/PubNub/Networking/HTTPFileTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public class HTTPFileDownloadTask: HTTPFileTask {
/// The block that is called when the task completes
public var completionBlock: ((Result<URL, Error>) -> Void)?
/// The crypto object that will attempt to decrypt the file
public var cryptorModule: CryptorModule?
public var cryptoModule: CryptoModule?

/// The location where the temporary downloaded file should be copied
public private(set) var destinationURL: URL
Expand All @@ -250,21 +250,21 @@ public class HTTPFileDownloadTask: HTTPFileTask {
(urlSessionTask as? URLSessionDownloadTask)?.cancel(byProducingResumeData: byProducingResumeData)
}

init(task: URLSessionDownloadTask, session identifier: String?, downloadTo url: URL, cryptorModule: CryptorModule?) {
init(task: URLSessionDownloadTask, session identifier: String?, downloadTo url: URL, cryptoModule: CryptoModule?) {
self.destinationURL = url
self.cryptorModule = cryptorModule
self.cryptoModule = cryptoModule

super.init(task: task, session: identifier)
}

func decrypt(_ encryptedURL: URL, to outpuURL: URL, using cryptorModule: CryptorModule) throws {
func decrypt(_ encryptedURL: URL, to outpuURL: URL, using cryptoModule: CryptoModule) throws {
// If we were provided a Crypto object we should try and decrypt the file

guard let inputStream = InputStream(url: encryptedURL) else {
throw PubNubError(.streamCouldNotBeInitialized, additional: [encryptedURL.absoluteString])
}

cryptorModule.decrypt(
cryptoModule.decrypt(
stream: inputStream,
contentLength: encryptedURL.sizeOf,
to: outpuURL
Expand Down Expand Up @@ -324,15 +324,15 @@ public class HTTPFileDownloadTask: HTTPFileTask {
// Update destination to be a unique file
destinationURL = fileManager.makeUniqueFilename(destinationURL)

if let cryptorModule = cryptorModule {
if let cryptoModule = cryptoModule {
// Set the encrypted in case something goes wrong
encryptedURL = url

guard let stream = InputStream(url: url) else {
throw PubNubError(.streamCouldNotBeInitialized, additional: [url.absoluteString])
}

cryptorModule.decrypt(
cryptoModule.decrypt(
stream: stream,
contentLength: url.sizeOf,
to: destinationURL
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Networking/HTTPRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public protocol RouterConfiguration {
/// If Access Manager (PAM) is enabled, client will use `authToken` instead of `authKey` on all requests
var authToken: String? { get }
/// If set, all communication will be encrypted with this module
var cryptorModule: CryptorModule? { get }
var cryptoModule: CryptoModule? { get }
/// Whether a request identifier should be included on outgoing requests
var useRequestId: Bool { get }
/// Ordered list of key-value pairs which identify various consumers.
Expand Down
Loading
Loading