| OLD | NEW |
| 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.generateKey."); | 12 description("Tests cypto.subtle.generateKey."); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | |
| 15 | |
| 16 extractable = true; | 14 extractable = true; |
| 17 keyUsages = ['encrypt', 'decrypt']; | 15 keyUsages = ['encrypt', 'decrypt']; |
| 18 | 16 |
| 19 // Invalid keyUsages | 17 // Invalid keyUsages |
| 20 aesCbc = { name: 'aes-cbc', length: 1024 }; | 18 aesCbc = { name: 'aes-cbc', length: 1024 }; |
| 21 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, -1)"); | 19 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, -1)"); |
| 22 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, null)"); | 20 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, null)"); |
| 23 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, ['boo'])"); | 21 shouldThrow("crypto.subtle.generateKey(aesCbc, extractable, ['boo'])"); |
| 24 | 22 |
| 25 // --------------------------------------------------- | 23 // --------------------------------------------------- |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // --------------------------------------------------- | 64 // --------------------------------------------------- |
| 67 | 65 |
| 68 // Note: these are the same tests as for RSASSA-PKCS1-v1_5 above. | 66 // Note: these are the same tests as for RSASSA-PKCS1-v1_5 above. |
| 69 | 67 |
| 70 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
-30}, extractable , keyUsages)"); | 68 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
-30}, extractable , keyUsages)"); |
| 71 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
NaN}, extractable , keyUsages)"); | 69 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
NaN}, extractable , keyUsages)"); |
| 72 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5'}, extractable ,
keyUsages)"); | 70 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5'}, extractable ,
keyUsages)"); |
| 73 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10}, extractable , keyUsages)"); | 71 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10}, extractable , keyUsages)"); |
| 74 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10, publicExponent: 10}, extractable , keyUsages)"); | 72 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10, publicExponent: 10}, extractable , keyUsages)"); |
| 75 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10, publicExponent: null}, extractable , keyUsages)"); | 73 shouldThrow("crypto.subtle.generateKey({name: 'RSAES-PKCS1-v1_5', modulusLength:
10, publicExponent: null}, extractable , keyUsages)"); |
| 76 | |
| 77 // Note that fractional numbers are truncated, so this length should be | |
| 78 // interpreted as 1024. | |
| 79 crypto.subtle.generateKey({name: 'aes-cbc', length: 1024.9}, extractable, ['decr
ypt', 'encrypt']).then(function(result) { | |
| 80 key = result; | |
| 81 shouldBe("key.type", "'private'") | |
| 82 shouldBe("key.extractable", "true") | |
| 83 shouldBe("key.algorithm.name", "'AES-CBC'") | |
| 84 shouldBe("key.algorithm.length", "1024") | |
| 85 shouldBe("key.usages.join(',')", "'encrypt,decrypt'") | |
| 86 | |
| 87 return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256' }}, f
alse, ['sign']); | |
| 88 }).then(function(result) { | |
| 89 key = result; | |
| 90 shouldBe("key.type", "'private'") | |
| 91 shouldBe("key.extractable", "false") | |
| 92 shouldBe("key.algorithm.name", "'HMAC'") | |
| 93 shouldBe("key.algorithm.hash.name", "'SHA-256'") | |
| 94 shouldBe("key.algorithm.length", "null") | |
| 95 shouldBe("key.usages.join(',')", "'sign'") | |
| 96 | |
| 97 return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256' }, le
ngth:48 }, false, ['sign']); | |
| 98 }).then(function(result) { | |
| 99 key = result; | |
| 100 shouldBe("key.type", "'private'") | |
| 101 shouldBe("key.extractable", "false") | |
| 102 shouldBe("key.algorithm.name", "'HMAC'") | |
| 103 shouldBe("key.algorithm.hash.name", "'SHA-256'") | |
| 104 shouldBe("key.algorithm.length", "48") | |
| 105 shouldBe("key.usages.join(',')", "'sign'") | |
| 106 | |
| 107 return crypto.subtle.generateKey({name: 'RSASSA-PKCS1-v1_5', modulusLength:
10, publicExponent: new Uint8Array([0])}, false, ['sign']); | |
| 108 }).then(function(result) { | |
| 109 keyPair = result; | |
| 110 | |
| 111 shouldBeDefined("keyPair.publicKey"); | |
| 112 shouldBeDefined("keyPair.privateKey"); | |
| 113 | |
| 114 shouldBe("keyPair.publicKey.type", "'public'"); | |
| 115 shouldBe("keyPair.publicKey.algorithm.name", "'RSASSA-PKCS1-v1_5'"); | |
| 116 | |
| 117 shouldBe("keyPair.privateKey.type", "'private'"); | |
| 118 shouldBe("keyPair.privateKey.algorithm.name", "'RSASSA-PKCS1-v1_5'"); | |
| 119 | |
| 120 // KeyPair should return the same Key wrapper | |
| 121 keyPair.publicKey.foo = "bar"; | |
| 122 shouldBe("keyPair.publicKey.foo", "'bar'"); | |
| 123 if (window.gc) { | |
| 124 window.gc(); | |
| 125 window.gc(); | |
| 126 } | |
| 127 shouldBe("keyPair.publicKey.foo", "'bar'"); | |
| 128 | |
| 129 }).then(finishJSTest, failAndFinishJSTest); | |
| 130 | |
| 131 </script> | 74 </script> |
| 132 | 75 |
| 133 <script src="../fast/js/resources/js-test-post.js"></script> | 76 <script src="../fast/js/resources/js-test-post.js"></script> |
| 134 </body> | 77 </body> |
| 135 </html> | 78 </html> |
| OLD | NEW |