Explorar el Código

Update to new API in tests

Marcin Krzyzanowski hace 3 años
padre
commit
c4df3b2bbd

+ 3 - 3
Tests/CryptoSwiftTests/HKDFTests.swift

@@ -25,7 +25,7 @@ class HKDFTests: XCTestCase {
     let salt = Array<UInt8>(hex: "0x000102030405060708090a0b0c")
     let salt = Array<UInt8>(hex: "0x000102030405060708090a0b0c")
     let info = Array<UInt8>(hex: "0xf0f1f2f3f4f5f6f7f8f9")
     let info = Array<UInt8>(hex: "0xf0f1f2f3f4f5f6f7f8f9")
     let keyLength = 42
     let keyLength = 42
-    let variant = HMAC.Variant.sha256
+    let variant = HMAC.Variant.sha2(.sha256)
     let reference = Array<UInt8>(hex: "0x3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865")
     let reference = Array<UInt8>(hex: "0x3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865")
 
 
     XCTAssertEqual(reference, try HKDF(password: password, salt: salt, info: info, keyLength: keyLength, variant: variant).calculate())
     XCTAssertEqual(reference, try HKDF(password: password, salt: salt, info: info, keyLength: keyLength, variant: variant).calculate())
@@ -36,7 +36,7 @@ class HKDFTests: XCTestCase {
     let salt = Array<UInt8>(hex: "0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf")
     let salt = Array<UInt8>(hex: "0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf")
     let info = Array<UInt8>(hex: "0xb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")
     let info = Array<UInt8>(hex: "0xb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")
     let keyLength = 82
     let keyLength = 82
-    let variant = HMAC.Variant.sha256
+    let variant = HMAC.Variant.sha2(.sha256)
     let reference = Array<UInt8>(hex: "0xb11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87")
     let reference = Array<UInt8>(hex: "0xb11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87")
 
 
     XCTAssertEqual(reference, try HKDF(password: password, salt: salt, info: info, keyLength: keyLength, variant: variant).calculate())
     XCTAssertEqual(reference, try HKDF(password: password, salt: salt, info: info, keyLength: keyLength, variant: variant).calculate())
@@ -45,7 +45,7 @@ class HKDFTests: XCTestCase {
   func testHKDF3() {
   func testHKDF3() {
     let password = Array<UInt8>(hex: "0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
     let password = Array<UInt8>(hex: "0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
     let keyLength = 42
     let keyLength = 42
-    let variant = HMAC.Variant.sha256
+    let variant = HMAC.Variant.sha2(.sha256)
     let reference = Array<UInt8>(hex: "0x8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8")
     let reference = Array<UInt8>(hex: "0x8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8")
 
 
     XCTAssertEqual(reference, try HKDF(password: password, keyLength: keyLength, variant: variant).calculate())
     XCTAssertEqual(reference, try HKDF(password: password, keyLength: keyLength, variant: variant).calculate())

+ 3 - 3
Tests/CryptoSwiftTests/HMACTests.swift

@@ -39,7 +39,7 @@ final class HMACTests: XCTestCase {
     let msg: Array<UInt8> = []
     let msg: Array<UInt8> = []
     let expectedMac: Array<UInt8> = [0xb6, 0x13, 0x67, 0x9a, 0x08, 0x14, 0xd9, 0xec, 0x77, 0x2f, 0x95, 0xd7, 0x78, 0xc3, 0x5f, 0xc5, 0xff, 0x16, 0x97, 0xc4, 0x93, 0x71, 0x56, 0x53, 0xc6, 0xc7, 0x12, 0x14, 0x42, 0x92, 0xc5, 0xad]
     let expectedMac: Array<UInt8> = [0xb6, 0x13, 0x67, 0x9a, 0x08, 0x14, 0xd9, 0xec, 0x77, 0x2f, 0x95, 0xd7, 0x78, 0xc3, 0x5f, 0xc5, 0xff, 0x16, 0x97, 0xc4, 0x93, 0x71, 0x56, 0x53, 0xc6, 0xc7, 0x12, 0x14, 0x42, 0x92, 0xc5, 0xad]
 
 
-    let hmac = try! HMAC(key: key, variant: .sha256).authenticate(msg)
+    let hmac = try! HMAC(key: key, variant: .sha2(.sha256)).authenticate(msg)
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
   }
   }
 
 
@@ -48,7 +48,7 @@ final class HMACTests: XCTestCase {
     let msg: Array<UInt8> = []
     let msg: Array<UInt8> = []
     let expectedMac: Array<UInt8> = [0x6c, 0x1f, 0x2e, 0xe9, 0x38, 0xfa, 0xd2, 0xe2, 0x4b, 0xd9, 0x12, 0x98, 0x47, 0x43, 0x82, 0xca, 0x21, 0x8c, 0x75, 0xdb, 0x3d, 0x83, 0xe1, 0x14, 0xb3, 0xd4, 0x36, 0x77, 0x76, 0xd1, 0x4d, 0x35, 0x51, 0x28, 0x9e, 0x75, 0xe8, 0x20, 0x9c, 0xd4, 0xb7, 0x92, 0x30, 0x28, 0x40, 0x23, 0x4a, 0xdc]
     let expectedMac: Array<UInt8> = [0x6c, 0x1f, 0x2e, 0xe9, 0x38, 0xfa, 0xd2, 0xe2, 0x4b, 0xd9, 0x12, 0x98, 0x47, 0x43, 0x82, 0xca, 0x21, 0x8c, 0x75, 0xdb, 0x3d, 0x83, 0xe1, 0x14, 0xb3, 0xd4, 0x36, 0x77, 0x76, 0xd1, 0x4d, 0x35, 0x51, 0x28, 0x9e, 0x75, 0xe8, 0x20, 0x9c, 0xd4, 0xb7, 0x92, 0x30, 0x28, 0x40, 0x23, 0x4a, 0xdc]
 
 
-    let hmac = try! HMAC(key: key, variant: .sha384).authenticate(msg)
+    let hmac = try! HMAC(key: key, variant: .sha2(.sha384)).authenticate(msg)
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
   }
   }
 
 
@@ -57,7 +57,7 @@ final class HMACTests: XCTestCase {
     let msg: Array<UInt8> = []
     let msg: Array<UInt8> = []
     let expectedMac: Array<UInt8> = [0xb9, 0x36, 0xce, 0xe8, 0x6c, 0x9f, 0x87, 0xaa, 0x5d, 0x3c, 0x6f, 0x2e, 0x84, 0xcb, 0x5a, 0x42, 0x39, 0xa5, 0xfe, 0x50, 0x48, 0x0a, 0x6e, 0xc6, 0x6b, 0x70, 0xab, 0x5b, 0x1f, 0x4a, 0xc6, 0x73, 0x0c, 0x6c, 0x51, 0x54, 0x21, 0xb3, 0x27, 0xec, 0x1d, 0x69, 0x40, 0x2e, 0x53, 0xdf, 0xb4, 0x9a, 0xd7, 0x38, 0x1e, 0xb0, 0x67, 0xb3, 0x38, 0xfd, 0x7b, 0x0c, 0xb2, 0x22, 0x47, 0x22, 0x5d, 0x47]
     let expectedMac: Array<UInt8> = [0xb9, 0x36, 0xce, 0xe8, 0x6c, 0x9f, 0x87, 0xaa, 0x5d, 0x3c, 0x6f, 0x2e, 0x84, 0xcb, 0x5a, 0x42, 0x39, 0xa5, 0xfe, 0x50, 0x48, 0x0a, 0x6e, 0xc6, 0x6b, 0x70, 0xab, 0x5b, 0x1f, 0x4a, 0xc6, 0x73, 0x0c, 0x6c, 0x51, 0x54, 0x21, 0xb3, 0x27, 0xec, 0x1d, 0x69, 0x40, 0x2e, 0x53, 0xdf, 0xb4, 0x9a, 0xd7, 0x38, 0x1e, 0xb0, 0x67, 0xb3, 0x38, 0xfd, 0x7b, 0x0c, 0xb2, 0x22, 0x47, 0x22, 0x5d, 0x47]
 
 
-    let hmac = try! HMAC(key: key, variant: .sha512).authenticate(msg)
+    let hmac = try! HMAC(key: key, variant: .sha2(.sha512)).authenticate(msg)
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
     XCTAssertEqual(hmac, expectedMac, "Invalid authentication result")
   }
   }