OLD | NEW |
1 function logError(error) | 1 function logError(error) |
2 { | 2 { |
3 debug("error is: " + error.toString()); | 3 debug("error is: " + error.toString()); |
4 } | 4 } |
5 | 5 |
6 // Verifies that the given "bytes" holds the same value as "expectedHexString". | 6 // Verifies that the given "bytes" holds the same value as "expectedHexString". |
7 // "bytes" can be anything recognized by "bytesToHexString()". | 7 // "bytes" can be anything recognized by "bytesToHexString()". |
8 function bytesShouldMatchHexString(testDescription, expectedHexString, bytes) | 8 function bytesShouldMatchHexString(testDescription, expectedHexString, bytes) |
9 { | 9 { |
10 expectedHexString = "[" + expectedHexString.toLowerCase() + "]"; | 10 expectedHexString = "[" + expectedHexString.toLowerCase() + "]"; |
(...skipping 21 matching lines...) Expand all Loading... |
32 for (var i = 0; i < bytes.length; ++i) { | 32 for (var i = 0; i < bytes.length; ++i) { |
33 var byteString = bytes[i].toString(16); | 33 var byteString = bytes[i].toString(16); |
34 if (byteString.length < 2) | 34 if (byteString.length < 2) |
35 byteString = "0" + byteString; | 35 byteString = "0" + byteString; |
36 hexBytes.push(byteString); | 36 hexBytes.push(byteString); |
37 } | 37 } |
38 | 38 |
39 return hexBytes.join(""); | 39 return hexBytes.join(""); |
40 } | 40 } |
41 | 41 |
| 42 function bytesToASCIIString(bytes) |
| 43 { |
| 44 return String.fromCharCode.apply(null, new Uint8Array(bytes)); |
| 45 } |
| 46 |
42 function hexStringToUint8Array(hexString) | 47 function hexStringToUint8Array(hexString) |
43 { | 48 { |
44 if (hexString.length % 2 != 0) | 49 if (hexString.length % 2 != 0) |
45 throw "Invalid hexString"; | 50 throw "Invalid hexString"; |
46 var arrayBuffer = new Uint8Array(hexString.length / 2); | 51 var arrayBuffer = new Uint8Array(hexString.length / 2); |
47 | 52 |
48 for (var i = 0; i < hexString.length; i += 2) { | 53 for (var i = 0; i < hexString.length; i += 2) { |
49 var byteValue = parseInt(hexString.substr(i, 2), 16); | 54 var byteValue = parseInt(hexString.substr(i, 2), 16); |
50 if (byteValue == NaN) | 55 if (byteValue == NaN) |
51 throw "Invalid hexString"; | 56 throw "Invalid hexString"; |
52 arrayBuffer[i/2] = byteValue; | 57 arrayBuffer[i/2] = byteValue; |
53 } | 58 } |
54 | 59 |
55 return arrayBuffer; | 60 return arrayBuffer; |
56 } | 61 } |
57 | 62 |
58 function asciiToUint8Array(str) | 63 function asciiToUint8Array(str) |
59 { | 64 { |
60 var chars = []; | 65 var chars = []; |
61 for (var i = 0; i < str.length; ++i) | 66 for (var i = 0; i < str.length; ++i) |
62 chars.push(str.charCodeAt(i)); | 67 chars.push(str.charCodeAt(i)); |
63 return new Uint8Array(chars); | 68 return new Uint8Array(chars); |
64 } | 69 } |
65 | 70 |
| 71 var Base64URL = { |
| 72 stringify: function (a) { |
| 73 var base64string = btoa(String.fromCharCode.apply(0, a)); |
| 74 return base64string.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g,
"_"); |
| 75 }, |
| 76 parse: function (s) { |
| 77 s = s.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, ''); |
| 78 return new Uint8Array(Array.prototype.map.call(atob(s), function (c) { r
eturn c.charCodeAt(0) })); |
| 79 } |
| 80 }; |
| 81 |
66 function failAndFinishJSTest(error) | 82 function failAndFinishJSTest(error) |
67 { | 83 { |
68 testFailed('' + error); | 84 testFailed('' + error); |
69 finishJSTest(); | 85 finishJSTest(); |
70 } | 86 } |
71 | 87 |
72 // Returns a Promise for the cloned key. | 88 // Returns a Promise for the cloned key. |
73 function cloneKey(key) | 89 function cloneKey(key) |
74 { | 90 { |
75 // Sending an object through a MessagePort implicitly clones it. | 91 // Sending an object through a MessagePort implicitly clones it. |
(...skipping 25 matching lines...) Expand all Loading... |
101 debug("Serialized key bytes: " + bytesToHexString(serializedWithoutVersi
on)); | 117 debug("Serialized key bytes: " + bytesToHexString(serializedWithoutVersi
on)); |
102 } | 118 } |
103 } | 119 } |
104 | 120 |
105 function shouldEvaluateAs(actual, expectedValue) | 121 function shouldEvaluateAs(actual, expectedValue) |
106 { | 122 { |
107 if (typeof expectedValue == "string") | 123 if (typeof expectedValue == "string") |
108 return shouldBeEqualToString(actual, expectedValue); | 124 return shouldBeEqualToString(actual, expectedValue); |
109 return shouldEvaluateTo(actual, expectedValue); | 125 return shouldEvaluateTo(actual, expectedValue); |
110 } | 126 } |
OLD | NEW |