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

Side by Side Diff: LayoutTests/crypto/sign-verify.html

Issue 39093002: [webcrypto] Add some more layouttests for crypto.subtle.digest() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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/resources/common.js ('k') | LayoutTests/crypto/sign-verify-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script> 4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 <script src="resources/common.js"></script> 5 <script src="resources/common.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <p id="description"></p> 8 <p id="description"></p>
9 <div id="console"></div> 9 <div id="console"></div>
10 10
11 <script> 11 <script>
12 description("Tests cypto.subtle.sign and crypto.subtle.verify"); 12 description("Tests cypto.subtle.sign and crypto.subtle.verify");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}}; 16 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}};
17 data = asciiToArrayBuffer("hello"); 17 data = asciiToUint8Array("hello");
18 18
19 importTestKeys().then(function(importedKeys) { 19 importTestKeys().then(function(importedKeys) {
20 keys = importedKeys; 20 keys = importedKeys;
21 21
22 // Pass invalid signature parameters to verify() 22 // Pass invalid signature parameters to verify()
23 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)"); 23 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)");
24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)"); 24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)");
25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)"); 25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)");
26 26
27 // Operation does not support signing. 27 // Operation does not support signing.
(...skipping 11 matching lines...) Expand all
39 // --------------------------------------------------- 39 // ---------------------------------------------------
40 shouldThrow("crypto.subtle.sign({name: 'hmac'}, keys.hmacSha1, data)"); 40 shouldThrow("crypto.subtle.sign({name: 'hmac'}, keys.hmacSha1, data)");
41 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: 3}, keys.hmacSha1, data )"); 41 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: 3}, keys.hmacSha1, data )");
42 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: null}, keys.hmacSha1, d ata)"); 42 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: null}, keys.hmacSha1, d ata)");
43 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {}}, keys.hmacSha1, dat a)"); 43 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {}}, keys.hmacSha1, dat a)");
44 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'foo'}}, keys.hm acSha1, data)"); 44 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'foo'}}, keys.hm acSha1, data)");
45 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'AES-CBC'}}, key s.hmacSha1, data)"); 45 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'AES-CBC'}}, key s.hmacSha1, data)");
46 46
47 return crypto.subtle.sign(hmacSha1, keys.hmacSha1, data); 47 return crypto.subtle.sign(hmacSha1, keys.hmacSha1, data);
48 }).then(function(result) { 48 }).then(function(result) {
49 signResult = arrayBufferToHexString(result); 49 bytesShouldMatchHexString('HMAC SHA1 signature', "890d9b894b239769ac77250466 dce42af926ed76", result);
50 shouldBe("signResult", "'[89 0d 9b 89 4b 23 97 69 ac 77 25 04 66 dc e4 2a f9 26 ed 76]'");
51 50
52 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, new Uint8Array(result), data); 51 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, new Uint8Array(result), data);
53 }).then(function(result) { 52 }).then(function(result) {
54 verifyResult = result; 53 verifyResult = result;
55 shouldBe("verifyResult", "true"); 54 shouldBe("verifyResult", "true");
56 55
57 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, asciiToArrayBuffer("bad signature"), data); 56 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, asciiToUint8Array("bads ignature"), data);
58 }).then(function(result) { 57 }).then(function(result) {
59 verifyResult = result; 58 verifyResult = result;
60 shouldBe("verifyResult", "false"); 59 shouldBe("verifyResult", "false");
61 }).then(finishJSTest, failAndFinishJSTest); 60 }).then(finishJSTest, failAndFinishJSTest);
62 61
63 </script> 62 </script>
64 63
65 <script src="../fast/js/resources/js-test-post.js"></script> 64 <script src="../fast/js/resources/js-test-post.js"></script>
66 </body> 65 </body>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/resources/common.js ('k') | LayoutTests/crypto/sign-verify-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698