Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: LayoutTests/crypto/resources/common.js

Issue 24467004: [webcrypto] Remove MockWebCrypto. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/crypto/importKey-expected.txt ('k') | LayoutTests/crypto/sign-verify.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function importTestKeys() 1 function importTestKeys()
2 { 2 {
3 var keyFormat = "spki"; 3 var keyFormat = "raw";
4 var data = new Uint8Array([]); 4 var data = asciiToArrayBuffer("16 bytes of key!");
5 var extractable = true; 5 var extractable = true;
6 var keyUsages = ['encrypt', 'decrypt', 'sign', 'verify']; 6 var keyUsages = ['encrypt', 'decrypt', 'sign', 'verify'];
7 7
8 var hmacPromise = crypto.subtle.importKey(keyFormat, data, {name: 'hmac', ha sh: {name: 'sha-1'}}, extractable, keyUsages); 8 var hmacPromise = crypto.subtle.importKey(keyFormat, data, {name: 'hmac', ha sh: {name: 'sha-1'}}, extractable, keyUsages);
9 var rsaSsaPromise = crypto.subtle.importKey(keyFormat, data, {name: 'RSASSA- PKCS1-v1_5', hash: {name: 'sha-1'}}, extractable, keyUsages);
10 var aesCbcPromise = crypto.subtle.importKey(keyFormat, data, {name: 'AES-CBC '}, extractable, keyUsages); 9 var aesCbcPromise = crypto.subtle.importKey(keyFormat, data, {name: 'AES-CBC '}, extractable, keyUsages);
11 var aesCbcJustDecrypt = crypto.subtle.importKey(keyFormat, data, {name: 'AES -CBC'}, false, ['decrypt']); 10 var aesCbcJustDecrypt = crypto.subtle.importKey(keyFormat, data, {name: 'AES -CBC'}, false, ['decrypt']);
12 11
13 return Promise.all([hmacPromise, rsaSsaPromise, aesCbcPromise, aesCbcJustDec rypt]).then(function(results) { 12 return Promise.all([hmacPromise, aesCbcPromise, aesCbcJustDecrypt]).then(fun ction(results) {
14 return { 13 return {
15 hmacSha1: results[0], 14 hmacSha1: results[0],
16 rsaSsaSha1: results[1], 15 aesCbc: results[1],
17 aesCbc: results[2], 16 aesCbcJustDecrypt: results[2],
18 aesCbcJustDecrypt: results[3],
19 }; 17 };
20 }); 18 });
21 } 19 }
22 20
23 // Builds a hex string representation of any array-like input (array or 21 // Builds a hex string representation of any array-like input (array or
24 // ArrayBufferView). The output looks like this: 22 // ArrayBufferView). The output looks like this:
25 // [ab 03 4c 99] 23 // [ab 03 4c 99]
26 function byteArrayToHexString(bytes) 24 function byteArrayToHexString(bytes)
27 { 25 {
28 var hexBytes = []; 26 var hexBytes = [];
29 27
30 for (var i = 0; i < bytes.length; ++i) { 28 for (var i = 0; i < bytes.length; ++i) {
31 var byteString = bytes[i].toString(16); 29 var byteString = bytes[i].toString(16);
32 if (byteString.length < 2) 30 if (byteString.length < 2)
33 byteString = "0" + byteString; 31 byteString = "0" + byteString;
34 hexBytes.push(byteString); 32 hexBytes.push(byteString);
35 } 33 }
36 34
37 return "[" + hexBytes.join(" ") + "]"; 35 return "[" + hexBytes.join(" ") + "]";
38 } 36 }
39 37
38 function arrayBufferToHexString(buffer)
39 {
40 return byteArrayToHexString(new Uint8Array(buffer));
41 }
42
40 function asciiToArrayBuffer(str) 43 function asciiToArrayBuffer(str)
41 { 44 {
42 var chars = []; 45 var chars = [];
43 for (var i = 0; i < str.length; ++i) 46 for (var i = 0; i < str.length; ++i)
44 chars.push(str.charCodeAt(i)); 47 chars.push(str.charCodeAt(i));
45 return new Uint8Array(chars); 48 return new Uint8Array(chars);
46 } 49 }
47 50
48 function failAndFinishJSTest(error) 51 function failAndFinishJSTest(error)
49 { 52 {
50 if (error) 53 if (error)
51 debug(error); 54 debug(error);
52 finishJSTest(); 55 finishJSTest();
53 } 56 }
OLDNEW
« no previous file with comments | « LayoutTests/crypto/importKey-expected.txt ('k') | LayoutTests/crypto/sign-verify.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698