فهرست منبع

Drop ObjC bridging. Direct ObjC users to RNCryptor-ObjC

Rob Napier 7 سال پیش
والد
کامیت
641a0d5667
6فایلهای تغییر یافته به همراه15 افزوده شده و 254 حذف شده
  1. 4 2
      CHANGELOG.md
  2. 0 109
      RNCryptor-ObjC.swift
  3. 1 1
      RNCryptor.podspec
  4. 2 2
      RNCryptor.swift
  5. 8 6
      RNCryptor.xcodeproj/project.pbxproj
  6. 0 134
      Tests/ObjC.m

+ 4 - 2
CHANGELOG.md

@@ -4,11 +4,13 @@ All notable changes to this project will be documented in this file. This projec
 
 ## [Unreleased](https://github.com/RNCryptor/RNCryptor/tree/swift)
 
+## [5.0.0](https://github.com/RNCryptor/RNCryptor/releases/tag/5.0.0) Swift 3.0. Drop ObjC bridge.
+
+* Rework for Swift 3
+* Drops ObjC bridging. There are too many problems with the Swift compiler at this point to support this cleanly. ObjC code should use [RNCryptor-ObjC](https://github.com/RNCryptor/RNCryptor-ObjC).
 * #159 Add WatchOS support to Podspec
 * Better debugging output in case of unexpected cryptor failure
 * Added Examples/KeyDerivation to explain how to manually derive keys
-* Marked `RNCryptor` class as `final`. Techincally this could be considered a breaking change if someone derived a subclass of `RNCryptor`, but that wouldn't make any sense. It's not a real class; it's just a namespace.
-* Marked internal `OverflowingBuffer` class as `final` (the compiler likely already did that anyway).
 
 ## [4.0.0](https://github.com/RNCryptor/RNCryptor/releases/tag/4.0.0) - Complete rewrite in Swift with ObjC bridging
 

+ 0 - 109
RNCryptor-ObjC.swift

@@ -1,109 +0,0 @@
-//
-//  RNCryptor-ObjC.swift
-//  RNCryptor
-//
-//  Created by Rob Napier on 8/31/16.
-//  Copyright © 2016 Rob Napier. All rights reserved.
-//
-
-import Foundation
-
-// ObjC helper bridge for RNCryptor
-// If you're not calling RNCryptor from ObjC, you don't need this file
-
-//@objc public enum RNCryptorError: Int {
-//    /// Ciphertext was corrupt or password was incorrect.
-//    /// It is not possible to distinguish between these cases in the v3 data format.
-//    case hmacMismatch = 1
-//
-//    /// Unrecognized data format. Usually this means the data is corrupt.
-//    case unknownHeader = 2
-//
-//    /// `final()` was called before sufficient data was passed to `update(withData:)`
-//    case messageTooShort
-//
-//    /// Memory allocation failure. This should never happen.
-//    case memoryFailure
-//
-//    /// A password-based decryptor was used on a key-based ciphertext, or vice-versa.
-//    case invalidCredentialType
-//}
-
-public final class RNEncryptor: NSObject {
-    private let encryptor: RNCryptor.Encryptor
-    public init(password: String) {
-        encryptor = RNCryptor.Encryptor(password: password)
-    }
-    public func update(withData data: Data) -> Data {
-        return encryptor.update(withData: data)
-    }
-    public func finalData() -> Data {
-        return encryptor.finalData()
-    }
-    public func encrypt(data: Data) -> Data {
-        return encryptor.encrypt(data: data)
-    }
-}
-
-public final class RNDecryptor: NSObject {
-    private let decryptor: RNCryptor.Decryptor
-
-    public init(password: String) {
-        decryptor = RNCryptor.Decryptor(password: password)
-    }
-    public func decrypt(data: Data) throws -> Data {
-        return try decryptor.decrypt(data: data)
-    }
-    public func update(withData data: Data) throws -> Data {
-        return try decryptor.update(withData: data)
-    }
-    public func finalData() throws -> Data {
-        return try decryptor.finalData()
-    }
-}
-
-public final class RNCryptorFormatV3: NSObject {
-    public static let keySize = RNCryptor.FormatV3.keySize
-    public static let saltSize = RNCryptor.FormatV3.saltSize
-    public static func makeKey(forPassword password: String, withSalt salt: Data) -> Data {
-        return RNCryptor.FormatV3.makeKey(forPassword: password, withSalt: salt)
-    }
-}
-
-public final class RNEncryptorV3: NSObject {
-    private let encryptor: RNCryptor.EncryptorV3
-    public init(password: String) {
-        encryptor = RNCryptor.EncryptorV3(password: password)
-    }
-    public init(encryptionKey: Data, hmacKey: Data) {
-        encryptor = RNCryptor.EncryptorV3(encryptionKey: encryptionKey, hmacKey: hmacKey)
-    }
-    public func encrypt(data: Data) -> Data {
-        return encryptor.encrypt(data: data)
-    }
-    public func update(withData data: Data) -> Data {
-        return encryptor.update(withData: data)
-    }
-    public func finalData() -> Data {
-        return encryptor.finalData()
-    }
-}
-
-public final class RNDecryptorV3: NSObject {
-    private let decryptor: RNCryptor.DecryptorV3
-    public init(password: String) {
-        decryptor = RNCryptor.DecryptorV3(password: password)
-    }
-    public init(encryptionKey: Data, hmacKey: Data) {
-        decryptor = RNCryptor.DecryptorV3(encryptionKey: encryptionKey, hmacKey: hmacKey)
-    }
-    public func decrypt(data: Data) throws -> Data {
-        return try decryptor.decrypt(data: data)
-    }
-    public func update(withData data: Data) throws -> Data {
-        return try decryptor.update(withData: data)
-    }
-    public func finalData() throws -> Data {
-        return try decryptor.finalData()
-    }
-}

+ 1 - 1
RNCryptor.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
 	s.name = 'RNCryptor'
-	s.version = '4.0.0'
+	s.version = '5.0.0'
 	s.summary = 'Cross-language AES Encryptor/Decryptor data format.'
 	s.authors = {'Rob Napier' => 'robnapier@gmail.com'}
 	s.social_media_url = 'https://twitter.com/cocoaphony'

+ 2 - 2
RNCryptor.swift

@@ -77,10 +77,10 @@ public extension RNCryptorType {
 }
 
 /// RNCryptor encryption/decryption interface.
-public final class RNCryptor: NSObject {
+public enum RNCryptor {
 
     /// Errors thrown by `RNCryptorType`.
-    @objc(RNCryptorError) public enum Error: Int, Swift.Error {
+    public enum Error: Int, Swift.Error {
         /// Ciphertext was corrupt or password was incorrect.
         /// It is not possible to distinguish between these cases in the v3 data format.
         case hmacMismatch = 1

+ 8 - 6
RNCryptor.xcodeproj/project.pbxproj

@@ -18,8 +18,6 @@
 		FBBA73981BC089FA00400E65 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA738E1BC089FA00400E65 /* Data.swift */; };
 		FBBA73991BC089FA00400E65 /* RNCryptorGeneratedVectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73901BC089FA00400E65 /* RNCryptorGeneratedVectorTests.swift */; };
 		FBBA739A1BC089FA00400E65 /* RNCryptorGeneratedVectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73901BC089FA00400E65 /* RNCryptorGeneratedVectorTests.swift */; };
-		FBBA739F1BC089FA00400E65 /* ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73931BC089FA00400E65 /* ObjC.m */; };
-		FBBA73A01BC089FA00400E65 /* ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73931BC089FA00400E65 /* ObjC.m */; };
 		FBBA73A11BC089FA00400E65 /* OverfowingBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73941BC089FA00400E65 /* OverfowingBuffer.swift */; };
 		FBBA73A21BC089FA00400E65 /* OverfowingBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73941BC089FA00400E65 /* OverfowingBuffer.swift */; };
 		FBBA73A31BC089FA00400E65 /* RNCryptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBBA73951BC089FA00400E65 /* RNCryptorTests.swift */; };
@@ -66,7 +64,6 @@
 		FBBA73901BC089FA00400E65 /* RNCryptorGeneratedVectorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNCryptorGeneratedVectorTests.swift; sourceTree = "<group>"; };
 		FBBA73911BC089FA00400E65 /* GenVectorTests */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GenVectorTests; sourceTree = "<group>"; };
 		FBBA73921BC089FA00400E65 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
-		FBBA73931BC089FA00400E65 /* ObjC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjC.m; sourceTree = "<group>"; };
 		FBBA73941BC089FA00400E65 /* OverfowingBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverfowingBuffer.swift; sourceTree = "<group>"; };
 		FBBA73951BC089FA00400E65 /* RNCryptorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNCryptorTests.swift; sourceTree = "<group>"; };
 		FBBA73961BC089FA00400E65 /* VectorTestHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VectorTestHelpers.swift; sourceTree = "<group>"; };
@@ -149,7 +146,6 @@
 				FBBA738F1BC089FA00400E65 /* Generated */,
 				FBBA73911BC089FA00400E65 /* GenVectorTests */,
 				FBBA73921BC089FA00400E65 /* Info.plist */,
-				FBBA73931BC089FA00400E65 /* ObjC.m */,
 				FBBA73941BC089FA00400E65 /* OverfowingBuffer.swift */,
 				FBBA73951BC089FA00400E65 /* RNCryptorTests.swift */,
 				FBBA73961BC089FA00400E65 /* VectorTestHelpers.swift */,
@@ -393,7 +389,6 @@
 				FBBA73971BC089FA00400E65 /* Data.swift in Sources */,
 				FBBA73A31BC089FA00400E65 /* RNCryptorTests.swift in Sources */,
 				FBBA73A51BC089FA00400E65 /* VectorTestHelpers.swift in Sources */,
-				FBBA739F1BC089FA00400E65 /* ObjC.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -422,7 +417,6 @@
 				FBBA73981BC089FA00400E65 /* Data.swift in Sources */,
 				FBBA73A41BC089FA00400E65 /* RNCryptorTests.swift in Sources */,
 				FBBA73A61BC089FA00400E65 /* VectorTestHelpers.swift in Sources */,
-				FBBA73A01BC089FA00400E65 /* ObjC.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -489,6 +483,7 @@
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = iphoneos;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				VERSIONING_SYSTEM = "apple-generic";
 				VERSION_INFO_PREFIX = "";
@@ -529,6 +524,7 @@
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = iphoneos;
+				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				VALIDATE_PRODUCT = YES;
 				VERSIONING_SYSTEM = "apple-generic";
@@ -611,6 +607,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = net.robnapier.RNCryptorTests;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 3.0;
 			};
 			name = Debug;
 		};
@@ -624,6 +621,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = net.robnapier.RNCryptorTests;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 3.0;
 			};
 			name = Release;
 		};
@@ -645,6 +643,7 @@
 				PRODUCT_NAME = RNCryptor;
 				SDKROOT = macosx;
 				SKIP_INSTALL = YES;
+				SWIFT_VERSION = 3.0;
 			};
 			name = Debug;
 		};
@@ -667,6 +666,7 @@
 				SDKROOT = macosx;
 				SKIP_INSTALL = YES;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 3.0;
 			};
 			name = Release;
 		};
@@ -683,6 +683,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SDKROOT = macosx;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 3.0;
 			};
 			name = Debug;
 		};
@@ -699,6 +700,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SDKROOT = macosx;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 3.0;
 			};
 			name = Release;
 		};

+ 0 - 134
Tests/ObjC.m

@@ -1,134 +0,0 @@
-//
-//  ObjC.m
-//
-//  Copyright © 2015 Rob Napier. All rights reserved.
-//
-//  Permission is hereby granted, free of charge, to any person obtaining a
-//  copy of this software and associated documentation files (the "Software"),
-//  to deal in the Software without restriction, including without limitation
-//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
-//  and/or sell copies of the Software, and to permit persons to whom the
-//  Software is furnished to do so, subject to the following conditions:
-//
-//  The above copyright notice and this permission notice shall be included in
-//  all copies or substantial portions of the Software.
-//
-//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-//  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
-//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-//  DEALINGS IN THE SOFTWARE.
-//
-
-#import <Foundation/Foundation.h>
-#import <XCTest/XCTest.h>
-@import RNCryptor;
-#import <CommonCrypto/CommonCryptor.h>
-
-@interface ObjC : XCTestCase
-
-@end
-
-@implementation ObjC
-
-// FIXME: ObjC unavailable pending https://openradar.appspot.com/radar?id=4974177417166848
-
-NSData *randomDataOfLength(NSInteger length) {
-    NSMutableData *data = [[NSMutableData alloc] initWithLength:length];
-    int result = SecRandomCopyBytes(kSecRandomDefault, length, data.mutableBytes);
-    NSCAssert(result == errSecSuccess, @"SecRandomCopyBytes must succeed");
-    return data;
-}
-
-- (void)testOneShotKey {
-    NSData *encryptionKey = randomDataOfLength(kCCKeySizeAES256);
-    NSData *hmacKey = randomDataOfLength(kCCKeySizeAES256);
-    NSData *data = randomDataOfLength(1024);
-
-    NSData *ciphertext = [[[RNEncryptorV3 alloc] initWithEncryptionKey:encryptionKey hmacKey:hmacKey] encryptWithData:data];
-    XCTAssertNotNil(ciphertext);
-
-    NSError *error = nil;
-    NSData *plaintext = [[[RNDecryptorV3 alloc] initWithEncryptionKey:encryptionKey hmacKey:hmacKey] decryptWithData:ciphertext error:&error];
-    XCTAssertNil(error);
-    XCTAssertEqualObjects(plaintext, data);
-}
-
-- (void)testOneShotPassword {
-    NSString *password = @"PASSWORD";
-    NSData *data = randomDataOfLength(1024);
-
-    NSData *ciphertext = [[[RNEncryptor alloc] initWithPassword:password] encryptWithData:data];
-    XCTAssertNotNil(ciphertext);
-
-    NSError *error = nil;
-    NSData *plaintext = [[[RNDecryptor alloc] initWithPassword:password] decryptWithData:ciphertext error:&error];
-    XCTAssertNil(error);
-    XCTAssertEqualObjects(plaintext, data);
-}
-
-- (void)testOneShotPasswordV3 {
-    NSString *password = @"PASSWORD";
-    NSData *data = randomDataOfLength(1024);
-
-    NSData *ciphertext = [[[RNEncryptorV3 alloc] initWithPassword:password] encryptWithData:data];
-    XCTAssertNotNil(ciphertext);
-
-    NSError *error = nil;
-    NSData *plaintext = [[[RNDecryptorV3 alloc] initWithPassword:password] decryptWithData:ciphertext error:&error];
-    XCTAssertNil(error);
-    XCTAssertEqualObjects(plaintext, data);
-}
-
-- (void)testUpdatesPassword {
-    NSString *password = @"PASSWORD";
-    NSData *data = randomDataOfLength(1024);
-
-    RNEncryptor *cryptor = [[RNEncryptor alloc] initWithPassword:password];
-    XCTAssertNotNil(cryptor);
-
-    NSMutableData *ciphertext = [NSMutableData new];
-    [ciphertext appendData:[cryptor updateWithData:data]];
-    [ciphertext appendData:[cryptor finalData]];
-    XCTAssertGreaterThan(ciphertext.length, data.length);
-
-
-    NSError *error = nil;
-    RNDecryptor *decryptor = [[RNDecryptor alloc] initWithPassword:password];
-    XCTAssertNotNil(decryptor);
-
-    NSMutableData *plaintext = [NSMutableData new];
-    [plaintext appendData:[decryptor updateWithData:ciphertext error:&error]];
-    XCTAssertNil(error);
-    [plaintext appendData:[decryptor finalDataAndReturnError:&error]];
-    XCTAssertNil(error);
-
-    XCTAssertEqualObjects(plaintext, data);
-}
-
-- (void)testBadFormat {
-    NSData *data = [[NSMutableData alloc] initWithLength:1024];
-    NSString *password = @"PASSWORD";
-
-    NSError *error = nil;
-    NSData *plaintext = [RNCryptor decryptWithData:data withPassword:password error:&error];
-    XCTAssertNil(plaintext);
-    XCTAssertEqual(error.code, RNCryptorErrorUnknownHeader);
-}
-
-- (void)testClass {
-    NSString *password = @"PASSWORD";
-    NSData *data = randomDataOfLength(1024);
-
-    NSData *ciphertext = [RNCryptor encryptWithData:data withPassword:password];
-    XCTAssertNotNil(ciphertext);
-
-    NSError *error = nil;
-    NSData *plaintext = [RNCryptor decryptWithData:ciphertext withPassword:password error:&error];
-    XCTAssertNil(error);
-    XCTAssertEqualObjects(plaintext, data);
-}
-
-@end