Recent web browsers tend to place significant security restrictions on the use
of file: URLs. These restrictions can prevent JSCoverage from
working properly. To avoid problems, it is recommended that you do either of the
following:
- If you are using the
jscoverageprogram to instrument your JavaScript code, install the instrumented files on a web server. - Use the
jscoverage-serverprogram (which itself acts as a web server).
See the manual for further details.
Recent web browsers tend to place significant security restrictions on the use
of file: URLs. These restrictions can prevent JSCoverage from
working properly. To avoid problems, it is recommended that you view coverage
reports stored to the filesystem by serving them from a web server.
See the manual for further details.
Browser 
Summary 
Source 
About 
| 1 | // GPG4Browsers - An OpenPGP implementation in javascript | |
| 2 | // Copyright (C) 2011 Recurity Labs GmbH | |
| 3 | // | |
| 4 | // This library is free software; you can redistribute it and/or | |
| 5 | // modify it under the terms of the GNU Lesser General Public | |
| 6 | // License as published by the Free Software Foundation; either | |
| 7 | // version 2.1 of the License, or (at your option) any later version. | |
| 8 | // | |
| 9 | // This library is distributed in the hope that it will be useful, | |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | // Lesser General Public License for more details. | |
| 13 | // | |
| 14 | // You should have received a copy of the GNU Lesser General Public | |
| 15 | // License along with this library; if not, write to the Free Software | |
| 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | ||
| 18 | 1 | function openpgp_keyring() { |
| 19 | ||
| 20 | /** | |
| 21 | * Initialization routine for the keyring. This method reads the | |
| 22 | * keyring from HTML5 local storage and initializes this instance. | |
| 23 | * This method is called by openpgp.init(). | |
| 24 | * @return [null] undefined | |
| 25 | */ | |
| 26 | 1 | function init() { |
| 27 | 1 | var sprivatekeys = JSON.parse(window.localStorage.getItem("privatekeys")); |
| 28 | 1 | var spublickeys = JSON.parse(window.localStorage.getItem("publickeys")); |
| 29 | 1 | if (sprivatekeys == null || sprivatekeys.length == 0) { |
| 30 | 1 | sprivatekeys = new Array(); |
| 31 | } | |
| 32 | ||
| 33 | 1 | if (spublickeys == null || spublickeys.length == 0) { |
| 34 | 1 | spublickeys = new Array(); |
| 35 | } | |
| 36 | 1 | this.publicKeys = new Array(); |
| 37 | 1 | this.privateKeys = new Array(); |
| 38 | 1 | var k = 0; |
| 39 | 1 | for (var i =0; i < sprivatekeys.length; i++) { |
| 40 | 0 | var r = openpgp.read_privateKey(sprivatekeys[i]); |
| 41 | 0 | this.privateKeys[k] = { armored: sprivatekeys[i], obj: r[0], keyId: r[0].getKeyId()}; |
| 42 | 0 | k++; |
| 43 | } | |
| 44 | 1 | k = 0; |
| 45 | 1 | for (var i =0; i < spublickeys.length; i++) { |
| 46 | 0 | var r = openpgp.read_publicKey(spublickeys[i]); |
| 47 | 0 | if (r[0] != null) { |
| 48 | 0 | this.publicKeys[k] = { armored: spublickeys[i], obj: r[0], keyId: r[0].getKeyId()}; |
| 49 | 0 | k++; |
| 50 | } | |
| 51 | } | |
| 52 | } | |
| 53 | 1 | this.init = init; |
| 54 | ||
| 55 | /** | |
| 56 | * Checks if at least one private key is in the keyring | |
| 57 | * @return | |
| 58 | */ | |
| 59 | 1 | function hasPrivateKey() { |
| 60 | 0 | return this.privateKeys.length > 0; |
| 61 | } | |
| 62 | 1 | this.hasPrivateKey = hasPrivateKey; |
| 63 | ||
| 64 | /** | |
| 65 | * Saves the current state of the keyring to HTML5 local storage. | |
| 66 | * The privateKeys array and publicKeys array gets Stringified using JSON | |
| 67 | * @return [null] undefined | |
| 68 | */ | |
| 69 | 1 | function store() { |
| 70 | 0 | var priv = new Array(); |
| 71 | 0 | for (var i = 0; i < this.privateKeys.length; i++) { |
| 72 | 0 | priv[i] = this.privateKeys[i].armored; |
| 73 | } | |
| 74 | 0 | var pub = new Array(); |
| 75 | 0 | for (var i = 0; i < this.publicKeys.length; i++) { |
| 76 | 0 | pub[i] = this.publicKeys[i].armored; |
| 77 | } | |
| 78 | 0 | window.localStorage.setItem("privatekeys",JSON.stringify(priv)); |
| 79 | 0 | window.localStorage.setItem("publickeys",JSON.stringify(pub)); |
| 80 | } | |
| 81 | 1 | this.store = store; |
| 82 | /** | |
| 83 | * searches all public keys in the keyring matching the address or address part of the user ids | |
| 84 | * @param email_address | |
| 85 | * @return | |
| 86 | */ | |
| 87 | 1 | function getPublicKeyForAddress(email_address) { |
| 88 | 0 | var results = new Array(); |
| 89 | 0 | var spl = string.split("<"); |
| 90 | 0 | var email = ""; |
| 91 | 0 | if (spl.length > 0) { |
| 92 | 0 | email = spl[1].split(">")[0]; |
| 93 | } else { | |
| 94 | 0 | email = string.trim(); |
| 95 | } | |
| 96 | 0 | for (var i =0; i < this.publicKeys.length; i++) { |
| 97 | ||
| 98 | 0 | for (var j = 0; j < this.publicKeys[i].userIds; j++) { |
| 99 | 0 | if (this.publicKeys[i].userIds[j].indexOf(email) >= 0) |
| 100 | 0 | results[results.length] = this.publicKeys[i]; |
| 101 | } | |
| 102 | } | |
| 103 | 0 | return result; |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Searches the keyring for a private key containing the specified email address | |
| 108 | * @param email_address [String] email address to search for | |
| 109 | * @return [Array[openpgp_msg_privatekey] private keys found | |
| 110 | */ | |
| 111 | 1 | function getPrivateKeyForAddress(email_address) { |
| 112 | 0 | var results = new Array(); |
| 113 | 0 | var spl = email_address.split("<"); |
| 114 | 0 | var email = ""; |
| 115 | 0 | if (spl.length > 1) { |
| 116 | 0 | email = spl[1].split(">")[0]; |
| 117 | } else { | |
| 118 | 0 | email = email_address.trim(); |
| 119 | } | |
| 120 | 0 | for (var i =0; i < this.privateKeys.length; i++) { |
| 121 | ||
| 122 | 0 | for (var j = 0; j < this.privateKeys[i].obj.userIds.length; j++) { |
| 123 | 0 | if (this.privateKeys[i].obj.userIds[j].text.indexOf(email) >= 0) |
| 124 | 0 | results[results.length] = this.privateKeys[i]; |
| 125 | } | |
| 126 | } | |
| 127 | 0 | return results; |
| 128 | } | |
| 129 | ||
| 130 | 1 | this.getPrivateKeyForAddress = getPrivateKeyForAddress; |
| 131 | /** | |
| 132 | * Searches the keyring for public keys having the specified key id | |
| 133 | * @param keyId provided as string of hex number (lowercase) | |
| 134 | * @return Array[openpgp_msg_privatekey] public keys found | |
| 135 | */ | |
| 136 | 1 | function getPublicKeysForKeyId(keyId) { |
| 137 | 0 | var result = new Array(); |
| 138 | 0 | for (var i=0; i < this.publicKeys.length; i++) |
| 139 | 0 | if (keyId == this.publicKeys[i].obj.getKeyId()) |
| 140 | 0 | result[result.length] = this.publicKeys[i]; |
| 141 | 0 | return result; |
| 142 | } | |
| 143 | 1 | this.getPublicKeysForKeyId = getPublicKeysForKeyId; |
| 144 | ||
| 145 | /** | |
| 146 | * Searches the keyring for private keys having the specified key id | |
| 147 | * @param keyId [String] 8 bytes as string containing the key id to look for | |
| 148 | * @return Array[openpgp_msg_privatekey] private keys found | |
| 149 | */ | |
| 150 | 1 | function getPrivateKeyForKeyId(keyId) { |
| 151 | 0 | var result = new Array(); |
| 152 | 0 | for (var i=0; i < this.privateKeys.length; i++) { |
| 153 | 0 | if (keyId == util.hexstrdump(this.privateKeys[i].obj.getKeyId())) { |
| 154 | 0 | result[result.length] = { key: this.privateKeys[i], keymaterial: this.privateKeys[i].obj.privateKeyPacket}; |
| 155 | } | |
| 156 | 0 | if (this.privateKeys[i].obj.subKeys != null) { |
| 157 | 0 | var subkeyids = this.privateKeys[i].obj.getSubKeyIds(); |
| 158 | 0 | for (var j=0; j < subkeyids.length; j++) |
| 159 | 0 | if (keyId == util.hexstrdump(subkeyids[j])) { |
| 160 | 0 | result[result.length] = { key: this.privateKeys[i], keymaterial: this.privateKeys[i].obj.subKeys[j]}; |
| 161 | } | |
| 162 | } | |
| 163 | } | |
| 164 | 0 | return result; |
| 165 | } | |
| 166 | 1 | this.getPrivateKeyForKeyId = getPrivateKeyForKeyId; |
| 167 | ||
| 168 | /** | |
| 169 | * Imports a public key from an exported ascii armored message | |
| 170 | * @param armored_text [String] PUBLIC KEY BLOCK message to read the public key from | |
| 171 | * @return [null] nothing | |
| 172 | */ | |
| 173 | 1 | function importPublicKey (armored_text) { |
| 174 | 0 | var result = openpgp.read_publicKey(armored_text); |
| 175 | 0 | for (var i = 0; i < result.length; i++) { |
| 176 | 0 | this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i]}; |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Imports a private key from an exported ascii armored message | |
| 182 | * @param armored_text [String] PRIVATE KEY BLOCK message to read the private key from | |
| 183 | * @return [null] nothing | |
| 184 | */ | |
| 185 | 1 | function importPrivateKey (armored_text) { |
| 186 | 0 | var result = openpgp.read_privateKey(armored_text); |
| 187 | 0 | for (var i = 0; i < result.length; i++) { |
| 188 | 0 | this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i]}; |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 192 | 1 | this.importPublicKey = importPublicKey; |
| 193 | 1 | this.importPrivateKey = importPrivateKey; |
| 194 | ||
| 195 | /** | |
| 196 | * returns the PUBLIC KEY BLOCK message representation of the public key at public key ring index | |
| 197 | * @param index [Integer] the index of the public key within the publicKeys array | |
| 198 | * @return [String] the PUBLIC KEY BLOCK message | |
| 199 | */ | |
| 200 | 1 | function exportPublicKey(index) { |
| 201 | 0 | return this.publicKey[index]; |
| 202 | } | |
| 203 | 1 | this.exportPublicKey = exportPublicKey; |
| 204 | ||
| 205 | ||
| 206 | /** | |
| 207 | * Removes a public key from the public key keyring at the specified index | |
| 208 | * @param index [Integer] the index of the public key within the publicKeys array | |
| 209 | * @return [String The public key object which has been removed | |
| 210 | */ | |
| 211 | 1 | function removePublicKey(index) { |
| 212 | 0 | var removed = this.publicKeys.splice(index,1); |
| 213 | 0 | this.store(); |
| 214 | 0 | return removed; |
| 215 | } | |
| 216 | 1 | this.removePublicKey = removePublicKey; |
| 217 | ||
| 218 | /** | |
| 219 | * returns the PRIVATE KEY BLOCK message representation of the private key at private key ring index | |
| 220 | * @param index [Integer] the index of the private key within the privateKeys array | |
| 221 | * @return [String] the PRIVATE KEY BLOCK message | |
| 222 | */ | |
| 223 | 1 | function exportPrivateKey(index) { |
| 224 | 0 | return this.privateKeys[index]; |
| 225 | } | |
| 226 | 1 | this.exportPrivateKey = exportPrivateKey; |
| 227 | } |
This is version 0.5.1 of JSCoverage, a program that calculates code coverage statistics for JavaScript.
See http://siliconforks.com/jscoverage/ for more information.
Copyright © 2007, 2008, 2009, 2010 siliconforks.com