// // Access.swift // CryptoSwift // // Created by Marcin Krzyzanowski on 06/08/16. // Copyright © 2016 Marcin Krzyzanowski. All rights reserved. // import XCTest import CryptoSwift class Access: XCTestCase { let cipher = try! AES(key: "secret0key000000", iv: "0123456789012345") let authenticator = Authenticator.HMAC(key: Array(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1) func testChecksum() { let _ = Checksum.crc32([1,2,3]) let _ = Checksum.crc16([1,2,3]) } func testHash() { let _ = Hash.md5([1,2,3]) let _ = Hash.sha1([1,2,3]) let _ = Hash.sha224([1,2,3]) let _ = Hash.sha256([1,2,3]) let _ = Hash.sha384([1,2,3]) let _ = Hash.sha512([1,2,3]) } func testArrayExtension() { let array = Array(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3") let _ = array.toHexString() let _ = array.md5() let _ = array.sha1() let _ = array.sha256() let _ = array.sha384() let _ = array.sha512() let _ = array.crc32() let _ = array.crc16() do { let _ = try array.encrypt(cipher: cipher) let _ = try array.decrypt(cipher: cipher) let _ = try array.authenticate(with: authenticator) } catch { XCTFail(error.localizedDescription) } } func testCollectionExtension() { // nothing public } func testStringExtension() { let string = "foofoobarbar" let _ = string.md5() let _ = string.sha1() let _ = string.sha224() let _ = string.sha256() let _ = string.sha384() let _ = string.sha512() let _ = string.crc16() let _ = string.crc32() do { let _ = try string.encrypt(cipher: cipher) let _ = try string.authenticate(with: authenticator) } catch { XCTFail(error.localizedDescription) } } func testStringFoundationExtension() { let string = "aPf/i9th9iX+vf49eR7PYk2q7S5xmm3jkRLejgzHNJs=" do { let _ = try string.decryptBase64ToString(cipher: cipher) let _ = try string.decryptBase64(cipher: cipher) } catch { XCTFail(error.localizedDescription) } } func testIntExtension() { // nothing public } func testUInt16Extension() { // nothing public } func testUInt32Extension() { // nothing public } func testUInt64Extension() { // nothing public } func testUInt8Extension() { // nothing public } func testDataExtension() { let data = Data(bytes: [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8]) let _ = data.checksum() let _ = data.md5() let _ = data.sha1() let _ = data.sha224() let _ = data.sha256() let _ = data.sha384() let _ = data.sha512() let _ = data.crc16() let _ = data.crc32() let _ = data.bytes let _ = data.toHexString() do { let _ = try data.encrypt(cipher: cipher) let _ = try data.decrypt(cipher: cipher) let _ = try data.authenticate(with: authenticator) } catch { XCTFail(error.localizedDescription) } } func testPadding() { // PKCS7 let _ = PKCS7().add(to: [1,2,3], blockSize: 16) let _ = PKCS7().remove(from: [1,2,3], blockSize: 16) // NoPadding let _ = NoPadding().add(to: [1,2,3], blockSize: 16) let _ = NoPadding().remove(from: [1,2,3], blockSize: 16) // ZeroPadding let _ = ZeroPadding().add(to: [1,2,3], blockSize: 16) let _ = ZeroPadding().remove(from: [1,2,3], blockSize: 16) } func testPBKDF() { do { let _ = PKCS5.PBKDF1.Variant.md5 let _ = try PKCS5.PBKDF1(password: [1,2,3,4,5,6,7], salt: [1,2,3,4,5,6,7,8]).calculate() let _ = try PKCS5.PBKDF2(password: [1,2,3,4,5,6,7], salt: [1,2,3,4]).calculate() } catch { XCTFail(error.localizedDescription) } } func testAuthenticator() { // TODO } func testHMAC() { // TODO } func testPoly1305() { // TODO } func testAES() { // TODO } func testRabbit() { // TODO } func testChaCha20() { // TODO } func testUpdatable() { // TODO } }