|
@@ -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")
|
|
|
}
|