Skip to content

Commit

Permalink
lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
yacinehmito committed Jan 4, 2021
1 parent 0ba6f42 commit d94ec0c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 69 deletions.
34 changes: 17 additions & 17 deletions cli/tests/unit/webcrypto/encrypt_decrypt/aes_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`,
);
}

Expand All @@ -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`,
);
}

Expand All @@ -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`,
);
}

Expand All @@ -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`,
);
}

Expand All @@ -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`,
);
}

Expand All @@ -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}`,
);
}

Expand All @@ -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`,
);
}
}
Expand All @@ -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.
Expand All @@ -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`,
);
}

Expand All @@ -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<TestVector> {
const key = await subtle.importKey(
"raw",
testVector.keyBuffer,
{ name: testVector.algorithm.name },
false,
usages
usages,
);
return { ...testVector, key };
}
21 changes: 9 additions & 12 deletions cli/tests/unit/webcrypto/encrypt_decrypt/aes_vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -2307,7 +2307,7 @@ export function getAesCbcTestVectors(): TestVectorSet {
result: badCiphertext,
};
});
}
},
);

return { passing, failing, decryptionFailing };
Expand Down Expand Up @@ -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() +
Expand All @@ -5524,8 +5523,7 @@ export function getAesGcmTestVectors(): TestVectorSet {
result,
},
{
name:
"AES-GCM " +
name: "AES-GCM " +
keyLength.toString() +
"-bit key, no additional data, " +
tagLength.toString() +
Expand All @@ -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() +
Expand Down
Loading

0 comments on commit d94ec0c

Please sign in to comment.