diff --git a/src/config/localStorage.js b/src/config/localStorage.js index 08de17f8..b4ecb8b8 100644 --- a/src/config/localStorage.js +++ b/src/config/localStorage.js @@ -6,7 +6,7 @@ /** * @constructor */ -module.exports = function () { +module.exports = function localStorage() { /** * Reads the config out of the HTML5 local storage diff --git a/src/packet/compressed.js b/src/packet/compressed.js index 61ab6e10..0cde6263 100644 --- a/src/packet/compressed.js +++ b/src/packet/compressed.js @@ -34,7 +34,7 @@ var enums = require('../enums.js'), /** * @constructor */ -module.exports = function () { +module.exports = function compressed() { /** * List of packets * @type {module:packet/packetlist} diff --git a/src/packet/literal.js b/src/packet/literal.js index a9455eae..209b99e2 100644 --- a/src/packet/literal.js +++ b/src/packet/literal.js @@ -31,7 +31,7 @@ var util = require('../util'), /** * @constructor */ -module.exports = function () { +module.exports = function literal() { this.format = 'utf8'; // default format for literal data packets this.data = ''; // literal data representation as native JavaScript string or bytes this.date = new Date(); @@ -42,7 +42,7 @@ module.exports = function () { * will be normalized to \r\n and by default text is converted to UTF8 * @param {String} text Any native javascript string */ - this.setText = function(text) { + this.setText = function (text) { // normalize EOL to \r\n text = text.replace(/\r/g, '').replace(/\n/g, '\r\n'); // encode UTF8 @@ -54,7 +54,7 @@ module.exports = function () { * with normalized end of line to \n * @return {String} literal data as text */ - this.getText = function() { + this.getText = function () { // decode UTF8 var text = util.decode_utf8(this.data); // normalize EOL to \n @@ -66,7 +66,7 @@ module.exports = function () { * @param {String} bytes The string of bytes * @param {utf8|binary|text} format The format of the string of bytes */ - this.setBytes = function(bytes, format) { + this.setBytes = function (bytes, format) { this.format = format; this.data = bytes; } @@ -76,7 +76,7 @@ module.exports = function () { * Get the byte sequence representing the literal packet data * @returns {String} A sequence of bytes */ - this.getBytes = function() { + this.getBytes = function () { return this.data; } @@ -92,7 +92,7 @@ module.exports = function () { * input at position * @return {module:packet/literal} object representation */ - this.read = function(bytes) { + this.read = function (bytes) { // - A one-octet field that describes how the data is formatted. var format = enums.read(enums.literal, bytes.charCodeAt(0)); @@ -113,7 +113,7 @@ module.exports = function () { * @param {String} data The data to be inserted as body * @return {String} string-representation of the packet */ - this.write = function() { + this.write = function () { var filename = util.encode_utf8("msg.txt"); var data = this.getBytes(); diff --git a/src/packet/marker.js b/src/packet/marker.js index d9f2f35e..ef93f390 100644 --- a/src/packet/marker.js +++ b/src/packet/marker.js @@ -31,7 +31,7 @@ /** * @constructor */ -module.exports = function () { +module.exports = function marker() { /** * Parsing function for a literal data packet (tag 10). * @@ -43,7 +43,7 @@ module.exports = function () { * input at position * @return {module:packet/marker} Object representation */ - this.read = function(bytes) { + this.read = function (bytes) { if (bytes.charCodeAt(0) == 0x50 && // P bytes.charCodeAt(1) == 0x47 && // G bytes.charCodeAt(2) == 0x50) // P diff --git a/src/packet/one_pass_signature.js b/src/packet/one_pass_signature.js index 12b056d5..5a546df4 100644 --- a/src/packet/one_pass_signature.js +++ b/src/packet/one_pass_signature.js @@ -35,7 +35,7 @@ var enums = require('../enums.js'), /** * @constructor */ -module.exports = function () { +module.exports = function one_pass_signature() { this.version = null; // A one-octet version number. The current version is 3. this.type = null; // A one-octet signature type. Signature types are described in RFC4880 Section 5.2.1. this.hashAlgorithm = null; // A one-octet number describing the hash algorithm used. (See RFC4880 9.4) @@ -48,7 +48,7 @@ module.exports = function () { * @param {String} bytes payload of a tag 4 packet * @return {module:packet/one_pass_signature} object representation */ - this.read = function(bytes) { + this.read = function (bytes) { var mypos = 0; // A one-octet version number. The current version is 3. this.version = bytes.charCodeAt(mypos++); @@ -80,7 +80,7 @@ module.exports = function () { * creates a string representation of a one-pass signature packet * @return {String} a string representation of a one-pass signature packet */ - this.write = function() { + this.write = function () { var result = ""; result += String.fromCharCode(3); diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index 9de92aa4..fdebc164 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -15,7 +15,7 @@ var packetParser = require('./packet.js'), /** * @constructor */ -module.exports = packetlist = function () { +module.exports = function packetlist() { /** The number of packets contained within the list. * @readonly * @type {Integer} */ @@ -25,7 +25,7 @@ module.exports = packetlist = function () { * Reads a stream of binary data and interprents it as a list of packets. * @param {String} A binary string of bytes. */ - this.read = function(bytes) { + this.read = function (bytes) { var i = 0; while (i < bytes.length) { @@ -46,7 +46,7 @@ module.exports = packetlist = function () { * class instance. * @returns {String} A binary string of bytes containing valid openpgp packets. */ - this.write = function() { + this.write = function () { var bytes = ''; for (var i = 0; i < this.length; i++) { @@ -62,7 +62,7 @@ module.exports = packetlist = function () { * Adds a packet to the list. This is the only supported method of doing so; * writing to packetlist[i] directly will result in an error. */ - this.push = function(packet) { + this.push = function (packet) { if (!packet) return; packet.packets = packet.packets || new packetlist(); @@ -74,7 +74,7 @@ module.exports = packetlist = function () { /** * Creates a new packetList with all packets that pass the test implemented by the provided function. */ - this.filter = function(callback) { + this.filter = function (callback) { var filtered = new packetlist(); @@ -90,7 +90,7 @@ module.exports = packetlist = function () { /** * Creates a new packetList with all packets from the given types */ - this.filterByTag = function() { + this.filterByTag = function () { var args = Array.prototype.slice.call(arguments); var filtered = new packetlist(); var that = this; @@ -107,7 +107,7 @@ module.exports = packetlist = function () { /** * Executes the provided callback once for each element */ - this.forEach = function(callback) { + this.forEach = function (callback) { for (var i = 0; i < this.length; i++) { callback(this[i]); } @@ -118,7 +118,7 @@ module.exports = packetlist = function () { * @param {module:enums.packet} type The packet type * @return {module:packet/packet|null} */ - this.findPacket = function(type) { + this.findPacket = function (type) { var packetlist = this.filterByTag(type); if (packetlist.length) { return packetlist[0]; @@ -137,7 +137,7 @@ module.exports = packetlist = function () { /** * Returns array of found indices by tag */ - this.indexOfTag = function() { + this.indexOfTag = function () { var args = Array.prototype.slice.call(arguments); var tagIndex = []; var that = this; @@ -152,7 +152,7 @@ module.exports = packetlist = function () { /** * Returns slice of packetlist */ - this.slice = function(begin, end) { + this.slice = function (begin, end) { if (!end) { end = this.length } @@ -166,7 +166,7 @@ module.exports = packetlist = function () { /** * Concatenates packetlist or array of packets */ - this.concat = function(packetlist) { + this.concat = function (packetlist) { if (packetlist) { for (var i = 0; i < packetlist.length; i++) { this.push(packetlist[i]); diff --git a/src/packet/public_key.js b/src/packet/public_key.js index 7f6f9c95..03b4e220 100644 --- a/src/packet/public_key.js +++ b/src/packet/public_key.js @@ -39,7 +39,7 @@ var util = require('../util'), /** * @constructor */ -module.exports = function () { +module.exports = function public_key() { this.version = 4; /** Key creation date. * @type {Date} */ @@ -61,7 +61,7 @@ module.exports = function () { * @param {String} input Input string to read the packet from * @return {Object} This object with attributes set by the parser */ - this.read = function(bytes) { + this.read = function (bytes) { var pos = 0; // A one-octet version number (3 or 4). this.version = bytes.charCodeAt(pos++); @@ -117,7 +117,7 @@ module.exports = function () { * @return {Object} {body: [string]OpenPGP packet body contents, * header: [string] OpenPGP packet header, string: [string] header+body} */ - this.write = function() { + this.write = function () { // Version var result = String.fromCharCode(this.version); result += util.writeDate(this.created); @@ -145,7 +145,7 @@ module.exports = function () { /** * Write an old version packet - it's used by some of the internal routines. */ - this.writeOld = function() { + this.writeOld = function () { var bytes = this.writePublicKey(); return String.fromCharCode(0x99) + @@ -157,7 +157,7 @@ module.exports = function () { * Calculates the key id of the key * @return {String} A 8 byte key id */ - this.getKeyId = function() { + this.getKeyId = function () { var keyid = new type_keyid(); if (this.version == 4) { keyid.read(this.getFingerprint().substr(12, 8)); @@ -171,7 +171,7 @@ module.exports = function () { * Calculates the fingerprint of the key * @return {String} A string containing the fingerprint */ - this.getFingerprint = function() { + this.getFingerprint = function () { var toHash = ''; if (this.version == 4) { toHash = this.writeOld(); diff --git a/src/packet/public_key_encrypted_session_key.js b/src/packet/public_key_encrypted_session_key.js index 9d14a8f3..dee89ecd 100644 --- a/src/packet/public_key_encrypted_session_key.js +++ b/src/packet/public_key_encrypted_session_key.js @@ -46,7 +46,7 @@ var type_keyid = require('../type/keyid.js'), /** * @constructor */ -module.exports = function () { +module.exports = function public_key_encrypted_session_key() { this.version = 3; this.publicKeyId = new type_keyid(); @@ -67,7 +67,7 @@ module.exports = function () { * input at position * @return {module:packet/public_key_encrypted_session_key} Object representation */ - this.read = function(bytes) { + this.read = function (bytes) { this.version = bytes.charCodeAt(0); this.publicKeyId.read(bytes.substr(1)); @@ -116,7 +116,7 @@ module.exports = function () { * A string of randombytes representing the session key * @return {String} The string representation */ - this.write = function() { + this.write = function () { var result = String.fromCharCode(this.version); result += this.publicKeyId.write(); @@ -130,7 +130,7 @@ module.exports = function () { return result; }; - this.encrypt = function(key) { + this.encrypt = function (key) { var data = String.fromCharCode( enums.write(enums.symmetric, this.sessionKeyAlgorithm)); @@ -157,7 +157,7 @@ module.exports = function () { * Private key with secMPIs unlocked * @return {String} The unencrypted session key */ - this.decrypt = function(key) { + this.decrypt = function (key) { var result = crypto.publicKeyDecrypt( this.publicKeyAlgorithm, key.mpi, diff --git a/src/packet/public_subkey.js b/src/packet/public_subkey.js index 0b94870f..cfea0376 100644 --- a/src/packet/public_subkey.js +++ b/src/packet/public_subkey.js @@ -26,6 +26,6 @@ var publicKey = require('./public_key.js'); * @constructor * @extends module:packet/public_key */ -module.exports = function () { +module.exports = function public_subkey() { publicKey.call(this); } diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index 03dcd12e..3b864057 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -42,7 +42,7 @@ var publicKey = require('./public_key.js'), * @constructor * @extends module:packet/public_key */ -module.exports = function () { +module.exports = function secret_key() { publicKey.call(this); // encrypted secret-key data this.encrypted = null; @@ -114,7 +114,7 @@ module.exports = function () { * Internal parser for private keys as specified in RFC 4880 section 5.5.3 * @param {String} bytes Input string to read the packet from */ - this.read = function(bytes) { + this.read = function (bytes) { // - A Public-Key or Public-Subkey packet, as described above. var len = this.readPublicKey(bytes); @@ -146,7 +146,7 @@ module.exports = function () { /** Creates an OpenPGP key packet for the given key. * @return {String} A string of bytes containing the secret key OpenPGP packet */ - this.write = function() { + this.write = function () { var bytes = this.writePublicKey(); if (!this.encrypted) { @@ -167,7 +167,7 @@ module.exports = function () { * to key specifier * @param {String} passphrase */ - this.encrypt = function(passphrase) { + this.encrypt = function (passphrase) { var s2k = new type_s2k(), symmetric = 'aes256', @@ -201,7 +201,7 @@ module.exports = function () { * @return {Boolean} True if the passphrase was correct or MPI already * decrypted; false if not */ - this.decrypt = function(passphrase) { + this.decrypt = function (passphrase) { if (this.isDecrypted) return true; @@ -256,7 +256,7 @@ module.exports = function () { return true; }; - this.generate = function(bits) { + this.generate = function (bits) { this.mpi = crypto.generateMpi(this.algorithm, bits); this.isDecrypted = true; }; diff --git a/src/packet/secret_subkey.js b/src/packet/secret_subkey.js index 97a69fee..5f00b1b3 100644 --- a/src/packet/secret_subkey.js +++ b/src/packet/secret_subkey.js @@ -26,6 +26,6 @@ var secretKey = require('./secret_key.js'); * @constructor * @extends module:packet/secret_key */ -module.exports = function () { +module.exports = function secret_subkey() { secretKey.call(this); } diff --git a/src/packet/signature.js b/src/packet/signature.js index fa2d3f8a..3115f2d6 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -41,7 +41,7 @@ var util = require('../util'), /** * @constructor */ -module.exports = packetSignature = function () { +module.exports = function signature() { this.version = 4; this.signatureType = null; @@ -93,7 +93,7 @@ module.exports = packetSignature = function () { * @param {Integer} len length of the packet or the remaining length of bytes at position * @return {module:packet/signature} object representation */ - this.read = function(bytes) { + this.read = function (bytes) { var i = 0; this.version = bytes.charCodeAt(i++); @@ -181,7 +181,7 @@ module.exports = packetSignature = function () { this.signature = bytes.substr(i); }; - this.write = function() { + this.write = function () { return this.signatureData + util.writeNumber(0, 2) + // Number of unsigned subpackets. this.signedHashValue + @@ -193,7 +193,7 @@ module.exports = packetSignature = function () { * @param {module:packet/secret_key} key private key used to sign the message. * @param {Object} data Contains packets to be signed. */ - this.sign = function(key, data) { + this.sign = function (key, data) { var signatureType = enums.write(enums.signature, this.signatureType), publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm), hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm); @@ -227,7 +227,7 @@ module.exports = packetSignature = function () { * Creates string of bytes with all subpacket data * @return {String} a string-representation of a all subpacket data */ - this.write_all_sub_packets = function() { + this.write_all_sub_packets = function () { var sub = enums.signatureSubpacket; var result = ''; var bytes = ''; @@ -350,7 +350,7 @@ module.exports = packetSignature = function () { // V4 signature sub packets - this.read_sub_packet = function(bytes) { + this.read_sub_packet = function (bytes) { var mypos = 0; function read_array(prop, bytes) { @@ -499,7 +499,7 @@ module.exports = packetSignature = function () { break; case 32: // Embedded Signature - this.embeddedSignature = new packetSignature(); + this.embeddedSignature = new signature(); this.embeddedSignature.read(bytes.substr(mypos)); break; default: @@ -509,7 +509,7 @@ module.exports = packetSignature = function () { }; // Produces data to produce signature on - this.toSign = function(type, data) { + this.toSign = function (type, data) { var t = enums.signature; switch (type) { @@ -575,7 +575,7 @@ module.exports = packetSignature = function () { } - this.calculateTrailer = function() { + this.calculateTrailer = function () { // calculating the trailer var trailer = ''; // V3 signatures don't have a trailer @@ -593,7 +593,7 @@ module.exports = packetSignature = function () { * @param {module:packet/public_subkey|module:packet/public_key} key the public key to verify the signature * @return {boolean} True if message is verified, else false. */ - this.verify = function(key, data) { + this.verify = function (key, data) { var signatureType = enums.write(enums.signature, this.signatureType), publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm), hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm); @@ -631,7 +631,7 @@ module.exports = packetSignature = function () { * Verifies signature expiration date * @return {Boolean} true if expired */ - this.isExpired = function() { + this.isExpired = function () { if (!this.signatureNeverExpires) { return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000); } diff --git a/src/packet/sym_encrypted_integrity_protected.js b/src/packet/sym_encrypted_integrity_protected.js index 5a2998bb..249069d6 100644 --- a/src/packet/sym_encrypted_integrity_protected.js +++ b/src/packet/sym_encrypted_integrity_protected.js @@ -35,7 +35,7 @@ var util = require('../util'), /** * @constructor */ -module.exports = function () { +module.exports = function sym_encrypted_integrity_protected() { /** The encrypted payload. */ this.encrypted = null; // string /** @@ -48,7 +48,7 @@ module.exports = function () { this.packets = null; - this.read = function(bytes) { + this.read = function (bytes) { // - A one-octet version number. The only currently defined value is 1. var version = bytes.charCodeAt(0); @@ -62,13 +62,13 @@ module.exports = function () { this.encrypted = bytes.substr(1); }; - this.write = function() { + this.write = function () { return String.fromCharCode(1) // Version + this.encrypted; }; - this.encrypt = function(sessionKeyAlgorithm, key) { + this.encrypt = function (sessionKeyAlgorithm, key) { var bytes = this.packets.write() var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm); @@ -100,7 +100,7 @@ module.exports = function () { * @param {String} key The key of cipher blocksize length to be used * @return {String} The decrypted data of this packet */ - this.decrypt = function(sessionKeyAlgorithm, key) { + this.decrypt = function (sessionKeyAlgorithm, key) { var decrypted = crypto.cfb.decrypt( sessionKeyAlgorithm, key, this.encrypted, false); diff --git a/src/packet/sym_encrypted_session_key.js b/src/packet/sym_encrypted_session_key.js index 0fb88ff3..825c4db7 100644 --- a/src/packet/sym_encrypted_session_key.js +++ b/src/packet/sym_encrypted_session_key.js @@ -42,7 +42,7 @@ var type_s2k = require('../type/s2k.js'), /** * @constructor */ -module.exports = function () { +module.exports = function sym_encrypted_session_key() { this.tag = 3; this.sessionKeyEncryptionAlgorithm = null; this.sessionKeyAlgorithm = 'aes256'; diff --git a/src/packet/symmetrically_encrypted.js b/src/packet/symmetrically_encrypted.js index 8f50b76a..cc949d93 100644 --- a/src/packet/symmetrically_encrypted.js +++ b/src/packet/symmetrically_encrypted.js @@ -32,7 +32,7 @@ var crypto = require('../crypto'); /** * @constructor */ -module.exports = function () { +module.exports = function symmetrically_encrypted() { this.encrypted = null; /** Decrypted packets contained within. * @type {module:packet/packetlist} */ diff --git a/src/packet/trust.js b/src/packet/trust.js index d3a3ec9a..f35ce337 100644 --- a/src/packet/trust.js +++ b/src/packet/trust.js @@ -5,6 +5,6 @@ /** * @constructor */ -module.exports = function () { +module.exports = function trust() { }; diff --git a/src/packet/user_attribute.js b/src/packet/user_attribute.js index 2f8b8631..fc344d21 100644 --- a/src/packet/user_attribute.js +++ b/src/packet/user_attribute.js @@ -41,7 +41,7 @@ var util = require('../util'), /** * @constructor */ -module.exports = function () { +module.exports = function user_attribute() { this.tag = 17; this.attributes = []; diff --git a/src/packet/userid.js b/src/packet/userid.js index 74df385e..5d3bdff2 100644 --- a/src/packet/userid.js +++ b/src/packet/userid.js @@ -32,7 +32,7 @@ var util = require('../util'); /** * @constructor */ -module.exports = function () { +module.exports = function userid() { /** A string containing the user id. Usually in the form * John Doe * @type {String} diff --git a/src/type/keyid.js b/src/type/keyid.js index 4d36956f..b5835b77 100644 --- a/src/type/keyid.js +++ b/src/type/keyid.js @@ -31,7 +31,7 @@ var util = require('../util'); /** * @constructor */ -module.exports = function () { +module.exports = function keyid() { this.bytes = ''; diff --git a/src/type/mpi.js b/src/type/mpi.js index 03834823..98c70cb0 100644 --- a/src/type/mpi.js +++ b/src/type/mpi.js @@ -49,7 +49,7 @@ module.exports = function mpi() { * @param {String} input Payload of mpi data * @return {Integer} Length of data read */ - this.read = function(bytes) { + this.read = function (bytes) { var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1); // Additional rules: @@ -70,15 +70,15 @@ module.exports = function mpi() { return 2 + bytelen; }; - this.fromBytes = function(bytes) { + this.fromBytes = function (bytes) { this.data = new BigInteger(util.hexstrdump(bytes), 16); }; - this.toBytes = function() { + this.toBytes = function () { return this.write().substr(2); }; - this.byteLength = function() { + this.byteLength = function () { return this.toBytes().length; }; @@ -86,15 +86,15 @@ module.exports = function mpi() { * Converts the mpi object to a string as specified in RFC4880 3.2 * @return {String} mpi Byte representation */ - this.write = function() { + this.write = function () { return this.data.toMPI(); }; - this.toBigInteger = function() { + this.toBigInteger = function () { return this.data.clone(); }; - this.fromBigInteger = function(bn) { + this.fromBigInteger = function (bn) { this.data = bn.clone(); }; } diff --git a/src/type/s2k.js b/src/type/s2k.js index f29f5849..11138e8a 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -51,7 +51,7 @@ module.exports = function s2k() { // Exponent bias, defined in RFC4880 var expbias = 6; - this.get_count = function() { + this.get_count = function () { return (16 + (this.c & 15)) << ((this.c >> 4) + expbias); }; @@ -60,7 +60,7 @@ module.exports = function s2k() { * @param {String} input Payload of string-to-key specifier * @return {Integer} Actual length of the object */ - this.read = function(bytes) { + this.read = function (bytes) { var i = 0; this.type = enums.read(enums.s2k, bytes.charCodeAt(i++)); this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++)); @@ -110,7 +110,7 @@ module.exports = function s2k() { * writes an s2k hash based on the inputs. * @return {String} Produced key of hashAlgorithm hash length */ - this.write = function() { + this.write = function () { var bytes = String.fromCharCode(enums.write(enums.s2k, this.type)); bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm)); @@ -136,7 +136,7 @@ module.exports = function s2k() { * @return {String} Produced key with a length corresponding to * hashAlgorithm hash length */ - this.produce_key = function(passphrase, numBytes) { + this.produce_key = function (passphrase, numBytes) { passphrase = util.encode_utf8(passphrase); function round(prefix, s2k) {