Explorar o código

Update tests for UpdatableCryptor

Marcin Krzyżanowski %!s(int64=9) %!d(string=hai) anos
pai
achega
57bb360bb6
Modificáronse 2 ficheiros con 13 adicións e 13 borrados
  1. 1 1
      CryptoSwift.playground/Contents.swift
  2. 12 12
      CryptoSwiftTests/AESTests.swift

+ 1 - 1
CryptoSwift.playground/Contents.swift

@@ -64,7 +64,7 @@ do {
     while (inputStream.hasBytesAvailable) {
         let readCount = inputStream.read(&buffer, maxLength: buffer.count)
         if (readCount > 0) {
-            try encryptor.update(withBytes: Array(buffer[0..<readCount])) { (bytes) in
+            try encryptor.update(withBytes: buffer[0..<readCount]) { (bytes) in
                 writeToStream(outputStream, bytes: bytes)
             }
         }

+ 12 - 12
CryptoSwiftTests/AESTests.swift

@@ -85,9 +85,9 @@ final class AESTests: XCTestCase {
 
         var ciphertext = Array<UInt8>()
         var encryptor = aes.makeEncryptor()
-        ciphertext += try! encryptor.update(withBytes: Array(plaintext[0..<8]))
-        ciphertext += try! encryptor.update(withBytes: Array(plaintext[8..<16]))
-        ciphertext += try! encryptor.update(withBytes: Array(plaintext[16..<32]))
+        ciphertext += try! encryptor.update(withBytes: plaintext[0..<8])
+        ciphertext += try! encryptor.update(withBytes: plaintext[8..<16])
+        ciphertext += try! encryptor.update(withBytes: plaintext[16..<32])
         ciphertext += try! encryptor.finish()
         XCTAssertEqual(try! aes.encrypt(plaintext), ciphertext, "encryption failed")
     }
@@ -114,9 +114,9 @@ final class AESTests: XCTestCase {
         let aes = try! AES(key: key, iv:iv, blockMode: .CBC, padding: PKCS7())
         var plaintext = Array<UInt8>()
         var decryptor = aes.makeDecryptor()
-        plaintext += try! decryptor.update(withBytes: Array(ciphertext[0..<8]))
-        plaintext += try! decryptor.update(withBytes: Array(ciphertext[8..<16]))
-        plaintext += try! decryptor.update(withBytes: Array(ciphertext[16..<32]))
+        plaintext += try! decryptor.update(withBytes: ciphertext[0..<8])
+        plaintext += try! decryptor.update(withBytes: ciphertext[8..<16])
+        plaintext += try! decryptor.update(withBytes: ciphertext[16..<32])
         plaintext += try! decryptor.finish()
         XCTAssertEqual(try! aes.decrypt(ciphertext), plaintext, "encryption failed")
     }
@@ -279,17 +279,17 @@ final class AESTests: XCTestCase {
         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.update(withBytes: plaintext[0..<5])
+        encrypted += try! encryptor.update(withBytes: plaintext[5..<15])
+        encrypted += try! encryptor.update(withBytes: 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.update(withBytes: expected[0..<5])
+        decrypted += try! decryptor.update(withBytes: expected[5..<15])
+        decrypted += try! decryptor.update(withBytes: expected[15..<plaintext.count])
         decrypted += try! decryptor.finish()
         XCTAssertEqual(decrypted, plaintext, "decryption failed")
     }