Эх сурвалжийг харах

Fixes after merge and update to Swift 3 Preview 4

Marcin Krzyżanowski 9 жил өмнө
parent
commit
eeafdb6a72

+ 1 - 1
.swift-version

@@ -1 +1 @@
-DEVELOPMENT-SNAPSHOT-2016-07-29-a
+3.0

+ 0 - 25
CryptoSwiftTests/AESTests.swift

@@ -211,31 +211,6 @@ final class AESTests: XCTestCase {
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
     }
 
-    // https://github.com/krzyzanowskim/CryptoSwift/pull/289
-    func testAES_encrypt_ctr_irregular_length_incremental_update() {
-        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-        let iv:Array<UInt8> = [0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff]
-        let plaintext:Array<UInt8> = [0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0x01,0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,0x01]
-        let expected:Array<UInt8> = [0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,0x1b,0xef,0x68,0x64,0x99,0xd,0xb6,0xce,0x37,0x40,0xbd,0x82,0x85,0x5d,0x11,0xfc,0x8e,0x49,0x4a,0xa9,0xed,0x23,0xe0,0xb9,0x40,0x2d]
-
-        let aes = try! AES(key: key, iv:iv, blockMode: .CTR, padding: NoPadding())
-        var encryptor = aes.makeEncryptor()
-        var encrypted = Array<UInt8>()
-        encrypted += try! encryptor.update(withBytes: Array(plaintext[0..<5]))
-        encrypted += try! encryptor.update(withBytes: Array(plaintext[5..<15]))
-        encrypted += try! encryptor.update(withBytes: Array(plaintext[15..<plaintext.count]))
-        encrypted += try! encryptor.finish()
-        XCTAssertEqual(encrypted, expected, "encryption failed")
-        
-        var decryptor = aes.makeDecryptor()
-        var decrypted = Array<UInt8>()
-        decrypted += try! decryptor.update(withBytes: Array(expected[0..<5]))
-        decrypted += try! decryptor.update(withBytes: Array(expected[5..<15]))
-        decrypted += try! decryptor.update(withBytes: Array(expected[15..<plaintext.count]))
-        decrypted += try! decryptor.finish()
-        XCTAssertEqual(decrypted, plaintext, "decryption failed")
-    }
-
     // https://github.com/krzyzanowskim/CryptoSwift/pull/290
     func testAES_decrypt_ctr_seek() {
         let key:Array<UInt8> = [0x52, 0x72, 0xb5, 0x9c, 0xab, 0x07, 0xc5, 0x01, 0x11, 0x7a, 0x39, 0xb6, 0x10, 0x35, 0x87, 0x02];

+ 2 - 2
Sources/CryptoSwift/AES.swift

@@ -403,7 +403,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
         }
 
-        mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
             self.accumulated += bytes
 
             if isLast {
@@ -448,7 +448,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired);
         }
 
-        mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
             // prepend "offset" number of bytes at the begining
             if self.offset > 0 {
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes

+ 2 - 2
Sources/CryptoSwift/ChaCha20.swift

@@ -150,7 +150,7 @@ extension ChaCha20 {
             self.chacha = chacha
         }
 
-        mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false) throws -> Array<UInt8> {
             self.accumulated += bytes
 
             var encrypted = Array<UInt8>()
@@ -179,7 +179,7 @@ extension ChaCha20 {
             self.chacha = chacha
         }
 
-        mutating public func update(withBytes bytes:Array<UInt8>, isLast: Bool = false) throws -> Array<UInt8> {
+        mutating public func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool = true) throws -> Array<UInt8> {
             // prepend "offset" number of bytes at the begining
             if self.offset > 0 {
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes

+ 7 - 7
Sources/CryptoSwift/Updatable.swift

@@ -12,7 +12,7 @@ public protocol Updatable {
     /// - parameter bytes: Bytes to process
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - returns: Processed data or empty array.
-    mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool) throws -> Array<UInt8>
+    mutating func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool) throws -> Array<UInt8>
 
     /// Update given bytes in chunks.
     ///
@@ -20,29 +20,29 @@ public protocol Updatable {
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter output: Resulting data
     /// - returns: Processed data or empty array.
-    mutating func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool, output: (Array<UInt8>) -> Void) throws
+    mutating func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool, output: (Array<UInt8>) -> Void) throws
 
     /// Finish updates. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - returns: Processed data.
-    mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8>
+    mutating func finish<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8>
 
     /// Finish updates. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter output: Resulting data
     /// - returns: Processed data.
-    mutating func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws
+    mutating func finish<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws
 }
 
 extension Updatable {
-    mutating public func update<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
+    mutating public func update<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         if (!processed.isEmpty) {
             output(processed)
         }
     }
 
-    mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8> {
+    mutating public func finish<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T) throws -> Array<UInt8> {
         return try self.update(withBytes: bytes, isLast: true)
     }
     
@@ -50,7 +50,7 @@ extension Updatable {
         return try self.update(withBytes: [], isLast: true)
     }
 
-    mutating public func finish<T: SequenceType where T.Generator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws {
+    mutating public func finish<T: Sequence where T.Iterator.Element == UInt8>(withBytes bytes:T, output: (Array<UInt8>) -> Void) throws {
         let processed = try self.update(withBytes: bytes, isLast: true)
         if (!processed.isEmpty) {
             output(processed)