diff --git a/cli/tests/unit/webcrypto/encrypt_decrypt/aes_test.ts b/cli/tests/unit/webcrypto/encrypt_decrypt/aes_test.ts index bf187e0421fb30..28bf0e5a8f9b74 100644 --- a/cli/tests/unit/webcrypto/encrypt_decrypt/aes_test.ts +++ b/cli/tests/unit/webcrypto/encrypt_decrypt/aes_test.ts @@ -11,15 +11,15 @@ import { } from "./aes_vectors.ts"; unitTest(async function webCryptoEncryptDecryptAesCbc() { - testAesEncryptDecrypt(getAesCbcTestVectors()); + await testAesEncryptDecrypt(getAesCbcTestVectors()); }); unitTest(async function webCryptoEncryptDecryptAesCtr() { - testAesEncryptDecrypt(getAesCtrTestVectors()); + await testAesEncryptDecrypt(getAesCtrTestVectors()); }); unitTest(async function webCryptoEncryptDecryptAesGcm() { - testAesEncryptDecrypt(getAesGcmTestVectors()); + await testAesEncryptDecrypt(getAesGcmTestVectors()); }); const subtle = crypto.subtle; @@ -42,12 +42,12 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { const result = await subtle.encrypt( vector.algorithm, vector.key, - vector.plaintext + vector.plaintext, ); assertEquals( result, vector.result, - `encrypt() for ${vector.name} resolved an unexpected result` + `encrypt() for ${vector.name} resolved an unexpected result`, ); } @@ -60,7 +60,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { assertEquals( result, vector.result, - `encrypt() for ${vector.name} resolved an unexpected result with an altered plaintext after call` + `encrypt() for ${vector.name} resolved an unexpected result with an altered plaintext after call`, ); } @@ -69,12 +69,12 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { const result = await subtle.decrypt( vector.algorithm, vector.key, - vector.result + vector.result, ); assertEquals( result, vector.plaintext, - `decrypt() for ${vector.name} resolved an unexpected result` + `decrypt() for ${vector.name} resolved an unexpected result`, ); } @@ -87,7 +87,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { assertEquals( result, vector.plaintext, - `decrypt() for ${vector.name} resolved an unexpected result with an altered ciphertext after call` + `decrypt() for ${vector.name} resolved an unexpected result with an altered ciphertext after call`, ); } @@ -100,7 +100,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "InvalidAccessError", - `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided key is not allowed to be used for encryption` + `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided key is not allowed to be used for encryption`, ); } @@ -124,7 +124,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "InvalidAccessError", - `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided algorithm does not match ${vector.algorithm.name}` + `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided algorithm does not match ${vector.algorithm.name}`, ); } @@ -137,7 +137,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "InvalidAccessError", - `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided key is not allowed to be used for decryption` + `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided key is not allowed to be used for decryption`, ); } } @@ -155,7 +155,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "OperationError", - `encrypt() for ${vector.name} should have rejected with an OperationError` + `encrypt() for ${vector.name} should have rejected with an OperationError`, ); // Check for OperationError due to data lengths for decryption, too. @@ -165,7 +165,7 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "OperationError", - `decrypt() for ${vector.name} should have rejected with an OperationError` + `decrypt() for ${vector.name} should have rejected with an OperationError`, ); } @@ -183,21 +183,21 @@ async function testAesEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "OperationError", - `decrypt() for ${vector.name} should have rejected with an OperationError for an algorithm-specific reason` + `decrypt() for ${vector.name} should have rejected with an OperationError for an algorithm-specific reason`, ); } } async function importVectorKey( testVector: TestVectorWithoutKey, - usages: KeyUsage[] + usages: KeyUsage[], ): Promise { const key = await subtle.importKey( "raw", testVector.keyBuffer, { name: testVector.algorithm.name }, false, - usages + usages, ); return { ...testVector, key }; } diff --git a/cli/tests/unit/webcrypto/encrypt_decrypt/aes_vectors.ts b/cli/tests/unit/webcrypto/encrypt_decrypt/aes_vectors.ts index 2aba58ed251b1a..62c1091786d829 100644 --- a/cli/tests/unit/webcrypto/encrypt_decrypt/aes_vectors.ts +++ b/cli/tests/unit/webcrypto/encrypt_decrypt/aes_vectors.ts @@ -2295,7 +2295,7 @@ export function getAesCbcTestVectors(): TestVectorSet { return paddingProblems.map((paddingProblem) => { const badCiphertext = new Uint8Array(ciphertext[keyLength].byteLength); badCiphertext.set( - ciphertext[keyLength].slice(0, ciphertext[keyLength].byteLength - 16) + ciphertext[keyLength].slice(0, ciphertext[keyLength].byteLength - 16), ); badCiphertext.set(badPadding[keyLength][paddingProblem]); @@ -2307,7 +2307,7 @@ export function getAesCbcTestVectors(): TestVectorSet { result: badCiphertext, }; }); - } + }, ); return { passing, failing, decryptionFailing }; @@ -5488,27 +5488,26 @@ export function getAesGcmTestVectors(): TestVectorSet { const byteCount = tagLength / 8; const result = new Uint8Array( - ciphertext[keyLength].byteLength + byteCount + ciphertext[keyLength].byteLength + byteCount, ); result.set(ciphertext[keyLength], 0); result.set( tag[keyLength].slice(0, byteCount), - ciphertext[keyLength].byteLength + ciphertext[keyLength].byteLength, ); const noadresult = new Uint8Array( - ciphertext[keyLength].byteLength + byteCount + ciphertext[keyLength].byteLength + byteCount, ); noadresult.set(ciphertext[keyLength], 0); noadresult.set( tagWithEmptyAd[keyLength].slice(0, byteCount), - ciphertext[keyLength].byteLength + ciphertext[keyLength].byteLength, ); return [ { - name: - "AES-GCM " + + name: "AES-GCM " + keyLength.toString() + "-bit key, " + tagLength.toString() + @@ -5524,8 +5523,7 @@ export function getAesGcmTestVectors(): TestVectorSet { result, }, { - name: - "AES-GCM " + + name: "AES-GCM " + keyLength.toString() + "-bit key, no additional data, " + tagLength.toString() + @@ -5545,8 +5543,7 @@ export function getAesGcmTestVectors(): TestVectorSet { const failing: TestVectorWithoutKey[] = keyLengths.flatMap((keyLength) => { return badTagLengths.map((badTagLength) => { return { - name: - "AES-GCM " + + name: "AES-GCM " + keyLength.toString() + "-bit key, illegal tag length " + badTagLength.toString() + diff --git a/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_test.ts b/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_test.ts index 774ea4713ec7d4..1eabb2af05fb5a 100644 --- a/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_test.ts +++ b/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_test.ts @@ -14,7 +14,7 @@ import { } from "./rsa_vectors.ts"; unitTest(async function webCryptoEncryptDecryptRsaOaep() { - testRsaEncryptDecrypt(getRsaOaepTestVectors()); + await testRsaEncryptDecrypt(getRsaOaepTestVectors()); }); const subtle = crypto.subtle; @@ -26,7 +26,7 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const vector = await importVectorKeys( vectorWithoutKeys, ["encrypt"], - ["decrypt"] + ["decrypt"], ); // Test decryption, first, because encryption tests rely on that working. @@ -34,12 +34,12 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const result = await subtle.decrypt( vector.algorithm, vector.privateKey, - vector.ciphertext + vector.ciphertext, ); assertEquals( result, vector.plaintext, - `decrypt() for ${vector.name} resolved an unexpected result` + `decrypt() for ${vector.name} resolved an unexpected result`, ); } @@ -49,14 +49,14 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const promise = subtle.decrypt( vector.algorithm, vector.privateKey, - ciphertext + ciphertext, ); ciphertext[0] = 255 - ciphertext[0]; const result = await promise; assertEquals( result, vector.plaintext, - `decrypt() for ${vector.name} resolved an unexpected result with an altered ciphertext after call` + `decrypt() for ${vector.name} resolved an unexpected result with an altered ciphertext after call`, ); } @@ -67,12 +67,12 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { await subtle.decrypt( vector.algorithm, vector.publicKey, - vector.ciphertext + vector.ciphertext, ); }, undefined, "InvalidAccessError", - `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided private key is actually a public key` + `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided private key is actually a public key`, ); } @@ -81,19 +81,19 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const vector = await importVectorKeys( vectorWithoutKeys, ["encrypt"], - ["unwrapKey"] + ["unwrapKey"], ); assertThrowsAsync( async () => { await subtle.decrypt( vector.algorithm, vector.privateKey, - vector.ciphertext + vector.ciphertext, ); }, undefined, "InvalidAccessError", - `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided private key is not allowed to be used for decryption` + `decrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided private key is not allowed to be used for decryption`, ); } @@ -102,32 +102,32 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const firstCiphertext = await subtle.encrypt( vector.algorithm, vector.publicKey, - vector.plaintext + vector.plaintext, ); assertEquals( firstCiphertext.byteLength * 8, (vector.privateKey.algorithm as RsaKeyGenParams).modulusLength, - `encrypt() for ${vector.name} resolved a result that does not match the modulus length with an altered plaintext after call` + `encrypt() for ${vector.name} resolved a result that does not match the modulus length with an altered plaintext after call`, ); const result = await subtle.decrypt( vector.algorithm, vector.privateKey, - firstCiphertext + firstCiphertext, ); assertEquals( result, vector.plaintext, - `The roundtrip encrypt() / decrypt() for ${vector.name} did not return the original plaintext` + `The roundtrip encrypt() / decrypt() for ${vector.name} did not return the original plaintext`, ); const secondCiphertext = await subtle.encrypt( vector.algorithm, vector.publicKey, - vector.plaintext + vector.plaintext, ); assertNotEquals( firstCiphertext, secondCiphertext, - `encrypt() for ${vector.name} resolved the same ciphertext twice` + `encrypt() for ${vector.name} resolved the same ciphertext twice`, ); } @@ -137,34 +137,34 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const promise = subtle.encrypt( vector.algorithm, vector.publicKey, - plaintext + plaintext, ); plaintext[0] = 255 - plaintext[0]; const firstCiphertext = await promise; assertEquals( firstCiphertext.byteLength * 8, (vector.privateKey.algorithm as RsaKeyGenParams).modulusLength, - `encrypt() for ${vector.name} resolved a result that does not match the modulus length` + `encrypt() for ${vector.name} resolved a result that does not match the modulus length`, ); const result = await subtle.decrypt( vector.algorithm, vector.privateKey, - firstCiphertext + firstCiphertext, ); assertEquals( result, vector.plaintext, - `The roundtrip encrypt() / decrypt() for ${vector.name} did not return the original plaintext` + `The roundtrip encrypt() / decrypt() for ${vector.name} did not return the original plaintext`, ); const secondCiphertext = await subtle.encrypt( vector.algorithm, vector.publicKey, - vector.plaintext + vector.plaintext, ); assertNotEquals( firstCiphertext, secondCiphertext, - `encrypt() for ${vector.name} resolved the same ciphertext twice` + `encrypt() for ${vector.name} resolved the same ciphertext twice`, ); } @@ -180,7 +180,7 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { }, undefined, "OperationError", - `encryt() for ${vector.name} should have rejected with an OperationError because the plaintext is too long` + `encryt() for ${vector.name} should have rejected with an OperationError because the plaintext is too long`, ); } @@ -191,12 +191,12 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { await subtle.encrypt( vector.algorithm, vector.privateKey, - vector.plaintext + vector.plaintext, ); }, undefined, "InvalidAccessError", - `encrypt() for ${vector.name} should have rejected with an OperationError because the provided public key is actually a private key` + `encrypt() for ${vector.name} should have rejected with an OperationError because the provided public key is actually a private key`, ); } @@ -205,18 +205,15 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { const vector = await importVectorKeys(vectorWithoutKeys, [], ["decrypt"]); assertThrowsAsync( async () => { - async () => { - await subtle.encrypt( - vector.algorithm, - vector.publicKey, - vector.plaintext - ); - }; + await subtle.encrypt( + vector.algorithm, + vector.publicKey, + vector.plaintext, + ); }, undefined, "InvalidAccessError", - - `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided public key is not allowed to be used for encryption` + `encrypt() for ${vector.name} should have rejected with an InvalidAccessError because the provided public key is not allowed to be used for encryption`, ); } } @@ -225,7 +222,7 @@ async function testRsaEncryptDecrypt(testVectorSet: TestVectorSet) { async function importVectorKeys( vector: TestVectorWithoutKeys, publicKeyUsages: KeyUsage[], - privateKeyUsages: KeyUsage[] + privateKeyUsages: KeyUsage[], ): Promise { const [publicKey, privateKey] = await Promise.all([ subtle.importKey( @@ -233,14 +230,14 @@ async function importVectorKeys( vector.publicKeyBuffer, { name: vector.algorithm.name, hash: vector.hash }, false, - publicKeyUsages + publicKeyUsages, ), subtle.importKey( vector.privateKeyFormat, vector.privateKeyBuffer, { name: vector.algorithm.name, hash: vector.hash }, false, - privateKeyUsages + privateKeyUsages, ), ]); diff --git a/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_vectors.ts b/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_vectors.ts index 656e1177c27432..0cff72ee864044 100644 --- a/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_vectors.ts +++ b/cli/tests/unit/webcrypto/encrypt_decrypt/rsa_vectors.ts @@ -15,7 +15,7 @@ export interface TestVectorWithoutKeys { privateKeyFormat: "pkcs8" | "jwk"; /** The value of the AlgorithmIdentifier parameter to provide to encrypt */ algorithm: RsaOaepParams; - hash: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512", + hash: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512"; /** The text to encrypt */ plaintext: Uint8Array; /** The expected result */ diff --git a/op_crates/crypto/01_crypto.js b/op_crates/crypto/01_crypto.js index c0c153993d11a3..2eec49b3801b94 100644 --- a/op_crates/crypto/01_crypto.js +++ b/op_crates/crypto/01_crypto.js @@ -21,9 +21,11 @@ const subtle = { async decrypt(algorithm, key, data) { + await undefined; throw new Error("Not implemented"); }, async deriveBits(algorithm, baseKey, length) { + await undefined; throw new Error("Not implemented"); }, async deriveKey( @@ -33,24 +35,31 @@ extractable, keyUsages, ) { + await undefined; throw new Error("Not implemented"); }, async digest(algorithm, data) { + await undefined; throw new Error("Not implemented"); }, async encrypt(algorithm, key, data) { + await undefined; throw new Error("Not implemented"); }, async exportKey(format, key) { + await undefined; throw new Error("Not implemented"); }, async generateKey(algorithm, extractable, keyUsages) { + await undefined; throw new Error("Not implemented"); }, async importKey(format, keyData, algorithm, extractable, keyUsages) { + await undefined; throw new Error("Not implemented"); }, async sign(algorithm, key, data) { + await undefined; throw new Error("Not implemented"); }, async unwrapKey( @@ -62,9 +71,11 @@ extractable, keyUsages, ) { + await undefined; throw new Error("Not implemented"); }, async verify(algorithm, key, signature, data) { + await undefined; throw new Error("Not implemented"); }, async wrapKey( @@ -73,8 +84,9 @@ wrappingKey, wrapAlgorithm, ) { + await undefined; throw new Error("Not implemented"); - } + }, }; window.crypto = {