diff --git a/doc/JXG.Util.html b/doc/JXG.Util.html
index 0f48c66f..25b72756 100644
--- a/doc/JXG.Util.html
+++ b/doc/JXG.Util.html
@@ -554,13 +554,13 @@ EXAMPLES:
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/aes.html b/doc/aes.html
index 4fe8f0a7..b7d1eaf0 100644
--- a/doc/aes.html
+++ b/doc/aes.html
@@ -111,13 +111,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/aes.js.html b/doc/aes.js.html
index 3bb76d96..de604b8e 100644
--- a/doc/aes.js.html
+++ b/doc/aes.js.html
@@ -546,13 +546,13 @@ for (var i in types) {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/all_packets.js.html b/doc/all_packets.js.html
index b31690df..13e71365 100644
--- a/doc/all_packets.js.html
+++ b/doc/all_packets.js.html
@@ -35,41 +35,58 @@ var enums = require('../enums.js');
module.exports = {
/** @see module:packet/compressed */
- compressed: require('./compressed.js'),
+ Compressed: require('./compressed.js'),
/** @see module:packet/sym_encrypted_integrity_protected */
- sym_encrypted_integrity_protected: require('./sym_encrypted_integrity_protected.js'),
+ SymEncryptedIntegrityProtected: require('./sym_encrypted_integrity_protected.js'),
/** @see module:packet/public_key_encrypted_session_key */
- public_key_encrypted_session_key: require('./public_key_encrypted_session_key.js'),
+ PublicKeyEncryptedSessionKey: require('./public_key_encrypted_session_key.js'),
/** @see module:packet/sym_encrypted_session_key */
- sym_encrypted_session_key: require('./sym_encrypted_session_key.js'),
+ SymEncryptedSessionKey: require('./sym_encrypted_session_key.js'),
/** @see module:packet/literal */
- literal: require('./literal.js'),
+ Literal: require('./literal.js'),
/** @see module:packet/public_key */
- public_key: require('./public_key.js'),
+ PublicKey: require('./public_key.js'),
/** @see module:packet/symmetrically_encrypted */
- symmetrically_encrypted: require('./symmetrically_encrypted.js'),
+ SymmetricallyEncrypted: require('./symmetrically_encrypted.js'),
/** @see module:packet/marker */
- marker: require('./marker.js'),
+ Marker: require('./marker.js'),
/** @see module:packet/public_subkey */
- public_subkey: require('./public_subkey.js'),
+ PublicSubkey: require('./public_subkey.js'),
/** @see module:packet/user_attribute */
- user_attribute: require('./user_attribute.js'),
+ UserAttribute: require('./user_attribute.js'),
/** @see module:packet/one_pass_signature */
- one_pass_signature: require('./one_pass_signature.js'),
+ OnePassSignature: require('./one_pass_signature.js'),
/** @see module:packet/secret_key */
- secret_key: require('./secret_key.js'),
+ SecretKey: require('./secret_key.js'),
/** @see module:packet/userid */
- userid: require('./userid.js'),
+ Userid: require('./userid.js'),
/** @see module:packet/secret_subkey */
- secret_subkey: require('./secret_subkey.js'),
+ SecretSubkey: require('./secret_subkey.js'),
/** @see module:packet/signature */
- signature: require('./signature.js'),
+ Signature: require('./signature.js'),
/** @see module:packet/trust */
- trust: require('./trust.js')
+ Trust: require('./trust.js'),
+ /**
+ * Allocate a new packet
+ * @param {String} tag property name from {@link module:enums.packet}
+ * @returns {Object} new packet object with type based on tag
+ */
+ newPacketFromTag: function (tag) {
+ return new this[packetClassFromTagName(tag)]();
+ }
};
+/**
+ * Convert tag name to class name
+ * @param {String} tag property name from {@link module:enums.packet}
+ * @returns {String}
+ */
+function packetClassFromTagName(tag) {
+ return tag.substr(0, 1).toUpperCase() + tag.substr(1);
+}
+
for (var i in enums.packet) {
- var packetClass = module.exports[i];
+ var packetClass = module.exports[packetClassFromTagName(i)];
if (packetClass !== undefined)
packetClass.prototype.tag = enums.packet[i];
@@ -84,13 +101,13 @@ for (var i in enums.packet) {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/armor.html b/doc/armor.html
index 03b119e1..303fdd98 100644
--- a/doc/armor.html
+++ b/doc/armor.html
@@ -1358,13 +1358,13 @@ given base64 encoded checksum
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/armor.js.html b/doc/armor.js.html
index ef43062f..9bdac14a 100644
--- a/doc/armor.js.html
+++ b/doc/armor.js.html
@@ -413,13 +413,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/base64.html b/doc/base64.html
index 1a43e276..1c3f7c7e 100644
--- a/doc/base64.html
+++ b/doc/base64.html
@@ -387,13 +387,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/base64.js.html b/doc/base64.js.html
index f6a0bdad..122c1304 100644
--- a/doc/base64.js.html
+++ b/doc/base64.js.html
@@ -136,13 +136,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/blowfish.html b/doc/blowfish.html
index d14c8a00..eb4aebf5 100644
--- a/doc/blowfish.html
+++ b/doc/blowfish.html
@@ -105,13 +105,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/blowfish.js.html b/doc/blowfish.js.html
index bb45b0fa..09beb23d 100644
--- a/doc/blowfish.js.html
+++ b/doc/blowfish.js.html
@@ -451,13 +451,13 @@ module.exports.blockSize = BF.prototype.blockSize = 16;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/cast5.html b/doc/cast5.html
index 61899838..2a338c69 100644
--- a/doc/cast5.html
+++ b/doc/cast5.html
@@ -105,13 +105,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/cast5.js.html b/doc/cast5.js.html
index 6e543d96..480e6be0 100644
--- a/doc/cast5.js.html
+++ b/doc/cast5.js.html
@@ -642,13 +642,13 @@ module.exports.keySize = cast5.prototype.keySize = 16;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/cfb.html b/doc/cfb.html
index 2dad5ea4..98c74c64 100644
--- a/doc/cfb.html
+++ b/doc/cfb.html
@@ -164,7 +164,7 @@ blockcipher to decrypt a message
the algorithm cipher class to decrypt
- data in one block_size encryption, @see module:crypto/cipher.
+ data in one block_size encryption, module:crypto/cipher .
@@ -402,7 +402,7 @@ using the specified blockcipher to encrypt a message
the algorithm cipher class to encrypt
- data in one block_size encryption, @see module:crypto/cipher.
+ data in one block_size encryption, module:crypto/cipher .
@@ -762,13 +762,13 @@ This will be passed to the cipherfn
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/cfb.js.html b/doc/cfb.js.html
index 3883d646..946447c1 100644
--- a/doc/cfb.js.html
+++ b/doc/cfb.js.html
@@ -59,7 +59,7 @@ module.exports = {
* @param {String} prefixrandom random bytes of block_size length provided
* as a string to be used in prefixing the data
* @param {String} cipherfn the algorithm cipher class to encrypt
- * data in one block_size encryption, @see module:crypto/cipher.
+ * data in one block_size encryption, {@link module:crypto/cipher}.
* @param {String} plaintext data to be encrypted provided as a string
* @param {String} key binary string representation of key to be used to encrypt the plaintext.
* This will be passed to the cipherfn
@@ -201,7 +201,7 @@ module.exports = {
* This function decrypts a given plaintext using the specified
* blockcipher to decrypt a message
* @param {String} cipherfn the algorithm cipher class to decrypt
- * data in one block_size encryption, @see module:crypto/cipher.
+ * data in one block_size encryption, {@link module:crypto/cipher}.
* @param {String} key binary string representation of key to be used to decrypt the ciphertext.
* This will be passed to the cipherfn
* @param {String} ciphertext to be decrypted provided as a string
@@ -335,13 +335,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/cipher.html b/doc/cipher.html
index 7b17a810..8159cb23 100644
--- a/doc/cipher.html
+++ b/doc/cipher.html
@@ -406,13 +406,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/cleartext.js.html b/doc/cleartext.js.html
index 7a870c14..166e3419 100644
--- a/doc/cleartext.js.html
+++ b/doc/cleartext.js.html
@@ -58,7 +58,7 @@ var config = require('./config'),
/**
* @class
* @classdesc Class that represents an OpenPGP cleartext signed message.
- * See http://tools.ietf.org/html/rfc4880#section-7
+ * See {@link http://tools.ietf.org/html/rfc4880#section-7}
* @param {String} text The cleartext of the signed message
* @param {module:packet/packetlist} packetlist The packetlist with signature packets or undefined
* if message not yet signed
@@ -70,7 +70,7 @@ function CleartextMessage(text, packetlist) {
}
// normalize EOL to canonical form <CR><LF>
this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n");
- this.packets = packetlist || new packet.list();
+ this.packets = packetlist || new packet.List();
}
/**
@@ -91,11 +91,11 @@ CleartextMessage.prototype.getSigningKeyIds = function() {
* @param {Array<module:key~Key>} privateKeys private keys with decrypted secret key data for signing
*/
CleartextMessage.prototype.sign = function(privateKeys) {
- var packetlist = new packet.list();
- var literalDataPacket = new packet.literal();
+ var packetlist = new packet.List();
+ var literalDataPacket = new packet.Literal();
literalDataPacket.setText(this.text);
for (var i = 0; i < privateKeys.length; i++) {
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = enums.signature.text;
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
var signingKeyPacket = privateKeys[i].getSigningKeyPacket();
@@ -115,7 +115,7 @@ CleartextMessage.prototype.sign = function(privateKeys) {
CleartextMessage.prototype.verify = function(publicKeys) {
var result = [];
var signatureList = this.packets.filterByTag(enums.packet.signature);
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
// we assume that cleartext signature is generated based on UTF8 cleartext
literalDataPacket.setText(this.text);
publicKeys.forEach(function(pubKey) {
@@ -167,7 +167,7 @@ function readArmored(armoredText) {
if (input.type !== enums.armor.signed) {
throw new Error('No cleartext signed message.');
}
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input.data);
var newMessage = new CleartextMessage(input.text, packetlist);
return newMessage;
@@ -185,13 +185,13 @@ exports.readArmored = readArmored;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/compressed-Compressed.html b/doc/compressed-Compressed.html
new file mode 100644
index 00000000..babcb3eb
--- /dev/null
+++ b/doc/compressed-Compressed.html
@@ -0,0 +1,695 @@
+
+
+
+
+ JSDoc: Class: Compressed
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Compressed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Compressed()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+ algorithm :compression
+
+
+
+
+
+
+ Compression algorithm
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ compressed :String
+
+
+
+
+
+
+ Compressed packet data
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ List of packets
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ compress()
+
+
+
+
+
+
+
+ Compress the packet data (member decompressedData)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ decompress()
+
+
+
+
+
+
+
+ Decompression method for decompressing the compressed data
+read by read_packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ read(bytes)
+
+
+
+
+
+
+
+ Parsing function for the packet.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ bytes
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of a tag 8 packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ Return the compressed packet.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ binary compressed packet
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/compressed.html b/doc/compressed.html
index ef04efc7..61feb4b7 100644
--- a/doc/compressed.html
+++ b/doc/compressed.html
@@ -35,82 +35,16 @@
+
+
Implementation of the Compressed Data Packet (Tag 8)
-RFC4880 5.6: The Compressed Data packet contains compressed data. Typically,
+
RFC4880 5.6 : The Compressed Data packet contains compressed data. Typically,
this packet is found as the contents of an encrypted packet, or following
a Signature or One-Pass Signature packet, and contains a literal data packet.
-
- new (require("packet/compressed"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -167,559 +101,19 @@ a Signature or One-Pass Signature packet, and contains a literal data packet.Members
+ Classes
-
-
- algorithm :compression
-
-
-
-
-
-
- Compression algorithm
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- compressed :String
-
-
-
-
-
-
- Compressed packet data
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- List of packets
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Compressed
+
- Methods
-
-
-
-
- compress()
-
-
-
- Compress the packet data (member decompressedData)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- decompress()
-
-
-
-
-
-
-
- Decompression method for decompressing the compressed data
-read by read_packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(bytes)
-
-
-
-
-
-
-
- Parsing function for the packet.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of a tag 8 packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Return the compressed packet.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- binary compressed packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -734,13 +128,13 @@ read by read_packet
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/compressed.js.html b/doc/compressed.js.html
index a3f77506..c8b340e9 100644
--- a/doc/compressed.js.html
+++ b/doc/compressed.js.html
@@ -45,7 +45,7 @@
/**
* Implementation of the Compressed Data Packet (Tag 8)<br/>
* <br/>
- * RFC4880 5.6: The Compressed Data packet contains compressed data. Typically,
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.6|RFC4880 5.6}: The Compressed Data packet contains compressed data. Typically,
* this packet is found as the contents of an encrypted packet, or following
* a Signature or One-Pass Signature packet, and contains a literal data packet.
* @requires compression/jxg
@@ -54,6 +54,8 @@
* @module packet/compressed
*/
+module.exports = Compressed;
+
var enums = require('../enums.js'),
JXG = require('../compression/jxg.js'),
base64 = require('../encoding/base64.js');
@@ -61,7 +63,7 @@ var enums = require('../enums.js'),
/**
* @constructor
*/
-module.exports = function compressed() {
+function Compressed() {
/**
* List of packets
* @type {module:packet/packetlist}
@@ -78,120 +80,119 @@ module.exports = function compressed() {
* @type {String}
*/
this.compressed = null;
+}
+/**
+ * Parsing function for the packet.
+ * @param {String} bytes Payload of a tag 8 packet
+ */
+Compressed.prototype.read = function (bytes) {
+ // One octet that gives the algorithm used to compress the packet.
+ this.algorithm = enums.read(enums.compression, bytes.charCodeAt(0));
- /**
- * Parsing function for the packet.
- * @param {String} bytes Payload of a tag 8 packet
- */
- this.read = function(bytes) {
- // One octet that gives the algorithm used to compress the packet.
- this.algorithm = enums.read(enums.compression, bytes.charCodeAt(0));
+ // Compressed data, which makes up the remainder of the packet.
+ this.compressed = bytes.substr(1);
- // Compressed data, which makes up the remainder of the packet.
- this.compressed = bytes.substr(1);
-
- this.decompress();
- };
+ this.decompress();
+};
- /**
- * Return the compressed packet.
- * @return {String} binary compressed packet
- */
- this.write = function() {
- if (this.compressed === null)
- this.compress();
+/**
+ * Return the compressed packet.
+ * @return {String} binary compressed packet
+ */
+Compressed.prototype.write = function () {
+ if (this.compressed === null)
+ this.compress();
- return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
- };
+ return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
+};
- /**
- * Decompression method for decompressing the compressed data
- * read by read_packet
- */
- this.decompress = function() {
- var decompressed, compdata, radix;
+/**
+ * Decompression method for decompressing the compressed data
+ * read by read_packet
+ */
+Compressed.prototype.decompress = function () {
+ var decompressed, compdata, radix;
- switch (this.algorithm) {
- case 'uncompressed':
- decompressed = this.compressed;
- break;
+ switch (this.algorithm) {
+ case 'uncompressed':
+ decompressed = this.compressed;
+ break;
- case 'zip':
- compData = this.compressed;
+ case 'zip':
+ compData = this.compressed;
+ radix = base64.encode(compData).replace(/\n/g, "");
+ // no header in this case, directly call deflate
+ var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
+
+ decompressed = unescape(jxg_obj.deflate()[0][0]);
+ break;
+
+ case 'zlib':
+ //RFC 1950. Bits 0-3 Compression Method
+ var compressionMethod = this.compressed.charCodeAt(0) % 0x10;
+
+ //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size.
+ // 2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary
+ // (how is this defined). Basic checksum, and compression level.
+
+ if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
+ // remove 4 bytes ADLER32 checksum from the end
+ compData = this.compressed.substring(0, this.compressed.length - 4);
radix = base64.encode(compData).replace(/\n/g, "");
- // no header in this case, directly call deflate
- var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
-
- decompressed = unescape(jxg_obj.deflate()[0][0]);
+ //TODO check ADLER32 checksum
+ decompressed = JXG.decompress(radix);
break;
- case 'zlib':
- //RFC 1950. Bits 0-3 Compression Method
- var compressionMethod = this.compressed.charCodeAt(0) % 0x10;
+ } else {
+ throw new Error("Compression algorithm ZLIB only supports " +
+ "DEFLATE compression method.");
+ }
+ break;
- //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size.
- // 2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary
- // (how is this defined). Basic checksum, and compression level.
+ case 'bzip2':
+ // TODO: need to implement this
+ throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
- if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
- // remove 4 bytes ADLER32 checksum from the end
- compData = this.compressed.substring(0, this.compressed.length - 4);
- radix = base64.encode(compData).replace(/\n/g, "");
- //TODO check ADLER32 checksum
- decompressed = JXG.decompress(radix);
- break;
+ default:
+ throw new Error("Compression algorithm unknown :" + this.alogrithm);
+ }
- } else {
- throw new Error("Compression algorithm ZLIB only supports " +
- "DEFLATE compression method.");
- }
- break;
+ this.packets.read(decompressed);
+};
- case 'bzip2':
- // TODO: need to implement this
- throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
+/**
+ * Compress the packet data (member decompressedData)
+ */
+Compressed.prototype.compress = function () {
+ switch (this.algorithm) {
- default:
- throw new Error("Compression algorithm unknown :" + this.alogrithm);
- }
+ case 'uncompressed':
+ // - Uncompressed
+ this.compressed = this.packets.write();
+ break;
- this.packets.read(decompressed);
- };
+ case 'zip':
+ // - ZIP [RFC1951]
+ throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
- /**
- * Compress the packet data (member decompressedData)
- */
- this.compress = function() {
- switch (this.algorithm) {
+ case 'zlib':
+ // - ZLIB [RFC1950]
+ // TODO: need to implement this
+ throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
- case 'uncompressed':
- // - Uncompressed
- this.compressed = this.packets.write();
- break;
+ case 'bzip2':
+ // - BZip2 [BZ2]
+ // TODO: need to implement this
+ throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
- case 'zip':
- // - ZIP [RFC1951]
- throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
-
- case 'zlib':
- // - ZLIB [RFC1950]
- // TODO: need to implement this
- throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
-
- case 'bzip2':
- // - BZip2 [BZ2]
- // TODO: need to implement this
- throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
-
- default:
- throw new Error("Compression algorithm unknown :" + this.type);
- }
- };
+ default:
+ throw new Error("Compression algorithm unknown :" + this.type);
+ }
};
@@ -203,13 +204,13 @@ module.exports = function compressed() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/config.html b/doc/config.html
index 42f31947..c77683e7 100644
--- a/doc/config.html
+++ b/doc/config.html
@@ -325,13 +325,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/config.js.html b/doc/config.js.html
index 1628075f..bb17bf30 100644
--- a/doc/config.js.html
+++ b/doc/config.js.html
@@ -82,13 +82,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/crypto.html b/doc/crypto.html
index 41ac73ff..31e380a1 100644
--- a/doc/crypto.html
+++ b/doc/crypto.html
@@ -156,7 +156,7 @@
-Integer
+module:enums.symmetric
@@ -166,7 +166,7 @@
- Algorithm to use (see RFC4880 9.2)
+ Algorithm to use (see RFC 4880 9.2 )
@@ -295,7 +295,7 @@
-Integer
+module:enums.symmetric
@@ -305,7 +305,7 @@
- Algorithm to use (see RFC4880 9.2)
+ Algorithm to use (see RFC 4880 9.2 )
@@ -575,7 +575,7 @@ the specified secretMPIs of the private key and the specified algorithm.
-Integer
+module:enums.publicKey
@@ -585,7 +585,7 @@ the specified secretMPIs of the private key and the specified algorithm.
- Algorithm to be used (See RFC4880 9.1)
+ Algorithm to be used (See RFC 4880 9.1 )
@@ -786,7 +786,7 @@ and the specified algorithm.
-Integer
+module:enums.publicKey
@@ -796,7 +796,7 @@ and the specified algorithm.
- Algorithm to be used (See RFC4880 9.1)
+ Algorithm to be used (See RFC 4880 9.1 )
@@ -937,13 +937,13 @@ if elgamal encryption an array of two module:type/mpi is returned; otherwise nul
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/crypto.js.html b/doc/crypto.js.html
index ebbadf74..b2f1304c 100644
--- a/doc/crypto.js.html
+++ b/doc/crypto.js.html
@@ -61,7 +61,7 @@ module.exports = {
/**
* Encrypts data using the specified public key multiprecision integers
* and the specified algorithm.
- * @param {Integer} algo Algorithm to be used (See RFC4880 9.1)
+ * @param {module:enums.publicKey} algo Algorithm to be used (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array<module:type/mpi>} publicMPIs Algorithm dependent multiprecision integers
* @param {module:type/mpi} data Data to be encrypted as MPI
* @return {Array<module:type/mpi>} if RSA an module:type/mpi;
@@ -102,7 +102,7 @@ module.exports = {
/**
* Decrypts data using the specified public key multiprecision integers of the private key,
* the specified secretMPIs of the private key and the specified algorithm.
- * @param {Integer} algo Algorithm to be used (See RFC4880 9.1)
+ * @param {module:enums.publicKey} algo Algorithm to be used (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array<module:type/mpi>} publicMPIs Algorithm dependent multiprecision integers
* of the public key part of the private key
* @param {Array<module:type/mpi>} secretMPIs Algorithm dependent multiprecision integers
@@ -234,7 +234,7 @@ module.exports = {
/**
* generate random byte prefix as string for the specified algorithm
- * @param {Integer} algo Algorithm to use (see RFC4880 9.2)
+ * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2})
* @return {String} Random bytes with length equal to the block
* size of the cipher
*/
@@ -244,7 +244,7 @@ module.exports = {
/**
* Generating a session key for the specified symmetric algorithm
- * @param {Integer} algo Algorithm to use (see RFC4880 9.2)
+ * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2})
* @return {String} Random bytes as a string to be used as a key
*/
generateSessionKey: function(algo) {
@@ -261,13 +261,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/des.html b/doc/des.html
index f13b674f..6192b860 100644
--- a/doc/des.html
+++ b/doc/des.html
@@ -209,13 +209,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/des.js.html b/doc/des.js.html
index f1a1fef1..216b859c 100644
--- a/doc/des.js.html
+++ b/doc/des.js.html
@@ -444,13 +444,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/dsa.html b/doc/dsa.html
index 0d898a6b..ca24462e 100644
--- a/doc/dsa.html
+++ b/doc/dsa.html
@@ -117,13 +117,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/dsa.js.html b/doc/dsa.js.html
index 324f4488..3905bc8b 100644
--- a/doc/dsa.js.html
+++ b/doc/dsa.js.html
@@ -206,13 +206,13 @@ module.exports = DSA;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/elgamal.html b/doc/elgamal.html
index 1a1ec552..2220019e 100644
--- a/doc/elgamal.html
+++ b/doc/elgamal.html
@@ -115,13 +115,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/elgamal.js.html b/doc/elgamal.js.html
index 57c3f548..bc160517 100644
--- a/doc/elgamal.js.html
+++ b/doc/elgamal.js.html
@@ -95,13 +95,13 @@ module.exports = Elgamal;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/enums.js.html b/doc/enums.js.html
index eb6d106a..d0a03000 100644
--- a/doc/enums.js.html
+++ b/doc/enums.js.html
@@ -42,7 +42,7 @@ module.exports = {
gnu: 101
},
- /** RFC4880, section 9.1
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880, section 9.1}
* @enum {Integer}
* @readonly
*/
@@ -54,7 +54,7 @@ module.exports = {
dsa: 17
},
- /** RFC4880, section 9.2
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
* @enum {Integer}
* @readonly
*/
@@ -71,7 +71,7 @@ module.exports = {
twofish: 10
},
- /** RFC4880, section 9.3
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
* @enum {Integer}
* @readonly
*/
@@ -84,7 +84,7 @@ module.exports = {
bzip2: 3
},
- /** RFC4880, section 9.4
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
* @enum {Integer}
* @readonly
*/
@@ -103,23 +103,23 @@ module.exports = {
* @readonly
*/
packet: {
- public_key_encrypted_session_key: 1,
+ publicKeyEncryptedSessionKey: 1,
signature: 2,
- sym_encrypted_session_key: 3,
- one_pass_signature: 4,
- secret_key: 5,
- public_key: 6,
- secret_subkey: 7,
+ symEncryptedSessionKey: 3,
+ onePassSignature: 4,
+ secretKey: 5,
+ publicKey: 6,
+ secretSubkey: 7,
compressed: 8,
- symmetrically_encrypted: 9,
+ symmetricallyEncrypted: 9,
marker: 10,
literal: 11,
trust: 12,
userid: 13,
- public_subkey: 14,
- user_attribute: 17,
- sym_encrypted_integrity_protected: 18,
- modification_detection_code: 19
+ publicSubkey: 14,
+ userAttribute: 17,
+ symEncryptedIntegrityProtected: 18,
+ modificationDetectionCode: 19
},
/** Data types in the literal packet
@@ -352,13 +352,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/hash.html b/doc/hash.html
index 8b729b6e..fb3c2dc6 100644
--- a/doc/hash.html
+++ b/doc/hash.html
@@ -553,7 +553,7 @@
-Integer
+module:enums.hash
@@ -563,7 +563,7 @@
- Hash algorithm type (see RFC4880 9.4)
+ Hash algorithm type (see RFC 4880 9.4 )
@@ -715,7 +715,7 @@
-Integer
+module:enums.hash
@@ -725,7 +725,7 @@
- Hash algorithm type (See RFC4880 9.4)
+ Hash algorithm type (See RFC 4880 9.4 )
@@ -819,13 +819,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/index.html b/doc/index.html
index 3cbe0f03..13512b54 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -41,37 +41,50 @@
- OpenPGP.js
+ OpenPGP.js [](http://travis-ci.org/openpgpjs/openpgpjs)
+
OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880 .
+
How do I use it?
+
You can download a prebuilt minified version of the library under releases .
+
You can also build a current version yourself:
+
npm install && grunt
+
Then take the resulting file from resources/openpgp.min.js
to use in your project.
+
I need some help
+
Mailing List
-You can sign up for our mailing list and ask for help there. We've recently worked on getting our archive up and running .
+
+You can sign up for our mailing list and ask for help there. We've recently worked on getting our archive up and running .
+
Documentation
+
A jsdoc build of our code comments is available at doc/index.html . Public calls should generally be made through the OpenPGP object doc/openpgp.html .
+
How do I get involved?
+
You want to help, great! Go ahead and fork our repo, make your changes
and make a pull request.
+
It is extra awesome if you write tests for the code you change. Our test coverage is relatively weak, so if you can add cases that is great.
+
What License do you use?
+
GNU Lesser General Public License (2.1). Please take a look at the LICENSE file for more information.
+
What are the requirements to use it?
+
OpenPGP.js currently only fully supports Chrome. Firefox support should be coming soon with the advent of Firefox 23 with native javascript support for window.crypto.getRandomValues
. If you can help us support more browsers and situations, please chip in!
+
Resources
-Below is a collection of resources, many of these were projects that were in someway a precursor to the current OpenPGP.js project. If you'd like to add your link here, please do so in a pull request or email to the list.
-
+
+Below is a collection of resources, many of these were projects that were in someway a precursor to the current OpenPGP.js project. If you'd like to add your link here, please do so in a pull request or email to the list.
+
+
@@ -167,13 +180,13 @@ for extending and developing on top of the base library.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/index.js.html b/doc/index.js.html
index 747e923f..8f611610 100644
--- a/doc/index.js.html
+++ b/doc/index.js.html
@@ -74,13 +74,13 @@ module.exports.crypto = require('./crypto');
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/index.js_.html b/doc/index.js_.html
index e1a4023c..3a94be90 100644
--- a/doc/index.js_.html
+++ b/doc/index.js_.html
@@ -60,13 +60,13 @@ for (var i in crypto)
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/index.js__.html b/doc/index.js__.html
index 520441dd..f187a574 100644
--- a/doc/index.js__.html
+++ b/doc/index.js__.html
@@ -63,13 +63,13 @@ for (var i in aes) {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/index.js___.html b/doc/index.js___.html
index 5b2ce05d..fd66deee 100644
--- a/doc/index.js___.html
+++ b/doc/index.js___.html
@@ -49,7 +49,7 @@ module.exports = {
/**
* Create a hash on the specified data using the specified algorithm
- * @param {Integer} algo Hash algorithm type (see RFC4880 9.4)
+ * @param {module:enums.hash} algo Hash algorithm type (see {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
* @param {String} data Data to be hashed
* @return {String} hash value
*/
@@ -83,7 +83,7 @@ module.exports = {
/**
* Returns the hash size in bytes of the specified hash algorithm type
- * @param {Integer} algo Hash algorithm type (See RFC4880 9.4)
+ * @param {module:enums.hash} algo Hash algorithm type (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
* @return {Integer} Size in bytes of the resulting hash
*/
getHashByteLength: function(algo) {
@@ -123,13 +123,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/index.js____.html b/doc/index.js____.html
index 91283e08..8b63b07e 100644
--- a/doc/index.js____.html
+++ b/doc/index.js____.html
@@ -49,13 +49,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/index.js_____.html b/doc/index.js_____.html
new file mode 100644
index 00000000..043c1539
--- /dev/null
+++ b/doc/index.js_____.html
@@ -0,0 +1,64 @@
+
+
+
+
+ JSDoc: Source: packet/index.js
+
+
+
+
+
+
+
+
+
+
+
+
+
Source: packet/index.js
+
+
+
+
+
+
+
+ var enums = require('../enums.js');
+
+module.exports = {
+ /**
+ * @name module:packet.List
+ * @see module:packet/packetlist
+ */
+ List: require('./packetlist.js')
+};
+
+var packets = require('./all_packets.js');
+
+for (var i in packets)
+ module.exports[i] = packets[i];
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
+
+
+
+
+
+
diff --git a/doc/jsbn.html b/doc/jsbn.html
index 1609810e..2ed0a419 100644
--- a/doc/jsbn.html
+++ b/doc/jsbn.html
@@ -111,13 +111,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/jsbn.js.html b/doc/jsbn.js.html
index 6d7da935..43f83b7f 100644
--- a/doc/jsbn.js.html
+++ b/doc/jsbn.js.html
@@ -1745,13 +1745,13 @@ BigInteger.prototype.square = bnSquare;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/jxg.js.html b/doc/jxg.js.html
index f051f105..d4b61bcf 100644
--- a/doc/jxg.js.html
+++ b/doc/jxg.js.html
@@ -1297,13 +1297,13 @@ module.exports = JXG;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/key.js.html b/doc/key.js.html
index 80b1ddc0..b9ad2baf 100644
--- a/doc/key.js.html
+++ b/doc/key.js.html
@@ -86,19 +86,19 @@ Key.prototype.packetlist2structure = function(packetlist) {
var user, primaryKeyId, subKey;
for (var i = 0; i < packetlist.length; i++) {
switch (packetlist[i].tag) {
- case enums.packet.public_key:
- case enums.packet.secret_key:
+ case enums.packet.publicKey:
+ case enums.packet.secretKey:
this.primaryKey = packetlist[i];
primaryKeyId = this.primaryKey.getKeyId();
break;
case enums.packet.userid:
- case enums.packet.user_attribute:
+ case enums.packet.userAttribute:
user = new User(packetlist[i]);
if (!this.users) this.users = [];
this.users.push(user);
break;
- case enums.packet.public_subkey:
- case enums.packet.secret_subkey:
+ case enums.packet.publicSubkey:
+ case enums.packet.secretSubkey:
user = null;
if (!this.subKeys) this.subKeys = [];
subKey = new SubKey(packetlist[i]);
@@ -151,7 +151,7 @@ Key.prototype.packetlist2structure = function(packetlist) {
* @return {module:packet/packetlist} The packets that form a key
*/
Key.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.primaryKey);
packetlist.push(this.revocationSignature);
packetlist.concat(this.directSignatures);
@@ -228,7 +228,7 @@ function findKey(keys, keyIds) {
* @return {(module:packet/public_subkey|module:packet/public_key|null)}
*/
Key.prototype.getPublicKeyPacket = function(keyIds) {
- if (this.primaryKey.tag == enums.packet.public_key) {
+ if (this.primaryKey.tag == enums.packet.publicKey) {
return findKey(this.getAllKeyPackets(), keyIds);
} else {
return null;
@@ -241,7 +241,7 @@ Key.prototype.getPublicKeyPacket = function(keyIds) {
* @return {(module:packet/secret_subkey|module:packet/secret_key|null)}
*/
Key.prototype.getPrivateKeyPacket = function(keyIds) {
- if (this.primaryKey.tag == enums.packet.secret_key) {
+ if (this.primaryKey.tag == enums.packet.secretKey) {
return findKey(this.getAllKeyPackets(), keyIds);
} else {
return null;
@@ -267,7 +267,7 @@ Key.prototype.getUserIds = function() {
* @return {Boolean}
*/
Key.prototype.isPublic = function() {
- return this.primaryKey.tag == enums.packet.public_key;
+ return this.primaryKey.tag == enums.packet.publicKey;
};
/**
@@ -275,7 +275,7 @@ Key.prototype.isPublic = function() {
* @return {Boolean}
*/
Key.prototype.isPrivate = function() {
- return this.primaryKey.tag == enums.packet.secret_key;
+ return this.primaryKey.tag == enums.packet.secretKey;
};
/**
@@ -283,20 +283,20 @@ Key.prototype.isPrivate = function() {
* @return {module:key~Key} new public Key
*/
Key.prototype.toPublic = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
var keyPackets = this.toPacketlist();
var bytes;
for (var i = 0; i < keyPackets.length; i++) {
switch (keyPackets[i].tag) {
- case enums.packet.secret_key:
+ case enums.packet.secretKey:
bytes = keyPackets[i].writePublicKey();
- var pubKeyPacket = new packet.public_key();
+ var pubKeyPacket = new packet.PublicKey();
pubKeyPacket.read(bytes);
packetlist.push(pubKeyPacket);
break;
- case enums.packet.secret_subkey:
+ case enums.packet.secretSubkey:
bytes = keyPackets[i].writePublicKey();
- var pubSubkeyPacket = new packet.public_subkey();
+ var pubSubkeyPacket = new packet.PublicSubkey();
pubSubkeyPacket.read(bytes);
packetlist.push(pubSubkeyPacket);
break;
@@ -450,7 +450,7 @@ Key.prototype.verifyPrimaryKey = function() {
return enums.keyStatus.expired;
}
// check for at least one self signature. Self signature of user ID not mandatory
- // See http://tools.ietf.org/html/rfc4880#section-11.1
+ // See {@link http://tools.ietf.org/html/rfc4880#section-11.1}
var selfSigned = false;
for (var i = 0; i < this.users.length; i++) {
if (this.users[i].userId && this.users[i].selfCertifications) {
@@ -514,7 +514,7 @@ function User(userPacket) {
return new User(userPacket);
}
this.userId = userPacket.tag == enums.packet.userid ? userPacket : null;
- this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null;
+ this.userAttribute = userPacket.tag == enums.packet.userAttribute ? userPacket : null;
this.selfCertifications = null;
this.otherCertifications = null;
this.revocationCertifications = null;
@@ -525,7 +525,7 @@ function User(userPacket) {
* @return {module:packet/packetlist}
*/
User.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.userId || this.userAttribute);
packetlist.concat(this.revocationCertifications);
packetlist.concat(this.selfCertifications);
@@ -631,7 +631,7 @@ function SubKey(subKeyPacket) {
* @return {module:packet/packetlist}
*/
SubKey.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.subKey);
packetlist.push(this.revocationSignature);
packetlist.push(this.bindingSignature);
@@ -709,9 +709,9 @@ function readArmored(armoredText) {
if (!(input.type == enums.armor.public_key || input.type == enums.armor.private_key)) {
throw new Error('Armored text not of type key');
}
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input.data);
- var keyIndex = packetlist.indexOfTag(enums.packet.public_key, enums.packet.secret_key);
+ var keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
if (keyIndex.length === 0) {
throw new Error('No key packet found in armored text');
}
@@ -735,8 +735,8 @@ function readArmored(armoredText) {
/**
* Generates a new OpenPGP key. Currently only supports RSA keys.
* Primary and subkey will be of same type.
- * @param {Integer} keyType to indicate what type of key to make.
- * RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ * @param {module:enums.publicKey} keyType to indicate what type of key to make.
+ * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1}
* @param {Integer} numBits number of bits for the key creation.
* @param {String} userId assumes already in form of "User Name <username@email.com>"
* @param {String} passphrase The passphrase used to encrypt the resulting private key
@@ -744,20 +744,20 @@ function readArmored(armoredText) {
* @static
*/
function generate(keyType, numBits, userId, passphrase) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
- var secretKeyPacket = new packet.secret_key();
+ var secretKeyPacket = new packet.SecretKey();
secretKeyPacket.algorithm = enums.read(enums.publicKey, keyType);
secretKeyPacket.generate(numBits);
secretKeyPacket.encrypt(passphrase);
- var userIdPacket = new packet.userid();
+ var userIdPacket = new packet.Userid();
userIdPacket.read(userId);
var dataToSign = {};
dataToSign.userid = userIdPacket;
dataToSign.key = secretKeyPacket;
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = enums.signature.cert_generic;
signaturePacket.publicKeyAlgorithm = keyType;
//TODO we should load preferred hash from config, or as input to this function
@@ -765,7 +765,7 @@ function generate(keyType, numBits, userId, passphrase) {
signaturePacket.keyFlags = [enums.keyFlags.certify_keys | enums.keyFlags.sign_data];
signaturePacket.sign(secretKeyPacket, dataToSign);
- var secretSubkeyPacket = new packet.secret_subkey();
+ var secretSubkeyPacket = new packet.SecretSubkey();
secretSubkeyPacket.algorithm = enums.read(enums.publicKey, keyType);
secretSubkeyPacket.generate(numBits);
secretSubkeyPacket.encrypt(passphrase);
@@ -773,7 +773,7 @@ function generate(keyType, numBits, userId, passphrase) {
dataToSign = {};
dataToSign.key = secretKeyPacket;
dataToSign.bind = secretSubkeyPacket;
- var subkeySignaturePacket = new packet.signature();
+ var subkeySignaturePacket = new packet.Signature();
subkeySignaturePacket.signatureType = enums.signature.subkey_binding;
subkeySignaturePacket.publicKeyAlgorithm = keyType;
//TODO we should load preferred hash from config, or as input to this function
@@ -803,13 +803,13 @@ exports.generate = generate;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/keyid-Keyid.html b/doc/keyid-Keyid.html
new file mode 100644
index 00000000..77db7f6c
--- /dev/null
+++ b/doc/keyid-Keyid.html
@@ -0,0 +1,269 @@
+
+
+
+
+ JSDoc: Class: Keyid
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Keyid
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Keyid()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ read(input)
+
+
+
+
+
+
+
+ Parsing method for a key id
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Input to read the key id from
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/keyid.html b/doc/keyid.html
index 6504fa99..ec65962e 100644
--- a/doc/keyid.html
+++ b/doc/keyid.html
@@ -35,8 +35,10 @@
+
+
-
Implementation of type key id (RFC4880 3.3)
+
Implementation of type key id (
RFC4880 3.3 )
A Key ID is an eight-octet scalar that identifies a key.
Implementations SHOULD NOT assume that Key IDs are unique. The
@@ -44,74 +46,6 @@ section "Enhanced Key Formats" below describes how Key IDs are
formed.
-
- new (require("type/keyid"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -164,137 +98,23 @@ formed.
-
-
-
-
-
-
-
Methods
+
Classes
-
-
- read(input)
-
-
-
-
-
-
-
- Parsing method for a key id
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Input to read the key id from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Keyid
+
+
+
+
+
+
+
@@ -305,13 +125,13 @@ formed.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/keyid.js.html b/doc/keyid.js.html
index 9eb2f42c..5de27049 100644
--- a/doc/keyid.js.html
+++ b/doc/keyid.js.html
@@ -43,7 +43,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
- * Implementation of type key id (RFC4880 3.3)<br/>
+ * Implementation of type key id ({@link http://tools.ietf.org/html/rfc4880#section-3.3|RFC4880 3.3})<br/>
* <br/>
* A Key ID is an eight-octet scalar that identifies a key.
* Implementations SHOULD NOT assume that Key IDs are unique. The
@@ -53,42 +53,43 @@
* @module type/keyid
*/
+module.exports = Keyid;
+
var util = require('../util');
/**
* @constructor
*/
-module.exports = function keyid() {
+function Keyid() {
this.bytes = '';
+}
-
- /**
- * Parsing method for a key id
- * @param {String} input Input to read the key id from
- */
- this.read = function(bytes) {
- this.bytes = bytes.substr(0, 8);
- };
-
- this.write = function() {
- return this.bytes;
- };
-
- this.toHex = function() {
- return util.hexstrdump(this.bytes);
- };
-
- this.equals = function(keyid) {
- return this.bytes == keyid.bytes;
- };
-
- this.isNull = function() {
- return this.bytes === '';
- };
+/**
+ * Parsing method for a key id
+ * @param {String} input Input to read the key id from
+ */
+Keyid.prototype.read = function(bytes) {
+ this.bytes = bytes.substr(0, 8);
};
-module.exports.mapToHex = function(keyId) {
+Keyid.prototype.write = function() {
+ return this.bytes;
+};
+
+Keyid.prototype.toHex = function() {
+ return util.hexstrdump(this.bytes);
+};
+
+Keyid.prototype.equals = function(keyid) {
+ return this.bytes == keyid.bytes;
+};
+
+Keyid.prototype.isNull = function() {
+ return this.bytes === '';
+};
+
+module.exports.mapToHex = function (keyId) {
return keyId.toHex();
};
@@ -101,13 +102,13 @@ module.exports.mapToHex = function(keyId) {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/keyring-Keyring.html b/doc/keyring-Keyring.html
new file mode 100644
index 00000000..d59571e2
--- /dev/null
+++ b/doc/keyring-Keyring.html
@@ -0,0 +1,1306 @@
+
+
+
+
+ JSDoc: Class: Keyring
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Keyring
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Keyring(storeHandler )
+
+
+
+
+
+
+
+ Initialization routine for the keyring. This method reads the
+keyring from HTML5 local storage and initializes this instance.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+ Argument
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ storeHandler
+
+
+
+
+
+class
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+ class implementing load() and store() methods
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ clear()
+
+
+
+
+
+
+
+ Clear the keyring - erase all the keys
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ exportKey(index) → {String}
+
+
+
+
+
+
+
+ returns the armored message representation of the key at key ring index
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ index
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ the index of the key within the array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ armored message representing the key object
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ exportPublicKey(index) → {String}
+
+
+
+
+
+
+
+ returns the armored message representation of the public key portion of the key at key ring index
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ index
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ the index of the key within the array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ armored message representing the public key object
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getKeysForKeyId(keyId) → {Array.<module:key~Key >}
+
+
+
+
+
+
+
+ Searches the keyring for public keys having the specified key id
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ keyId
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ provided as string of hex number (lowercase)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ public keys found
+
+
+
+
+
+
+ Type
+
+
+
+Array.<module:key~Key >
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getPrivateKeyForAddress(email) → {Array.<module:key~Key >}
+
+
+
+
+
+
+
+ Searches the keyring for a private key containing the specified email address
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ email
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ email address to search for
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ private keys found
+
+
+
+
+
+
+ Type
+
+
+
+Array.<module:key~Key >
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getPublicKeyForAddress(email) → {Array.<module:key~Key >}
+
+
+
+
+
+
+
+ searches all public keys in the keyring matching the address or address part of the user ids
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ email
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ email address to search for
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The public keys associated with provided email address.
+
+
+
+
+
+
+ Type
+
+
+
+Array.<module:key~Key >
+
+
+
+
+
+
+
+
+
+
+
+
+
+ importKey(armored)
+
+
+
+
+
+
+
+ Imports a key from an ascii armored message
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ armored
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ message to read the keys/key from
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Removes a public key from the public key keyring at the specified index
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ index
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ the index of the public key within the publicKeys array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The public key object which has been removed
+
+
+
+
+
+
+ Type
+
+
+
+module:key~Key
+
+
+
+
+
+
+
+
+
+
+
+
+
+ store()
+
+
+
+
+
+
+
+ Calls the storeHandler to save the keys
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/keyring.html b/doc/keyring.html
index defc598a..be33a345 100644
--- a/doc/keyring.html
+++ b/doc/keyring.html
@@ -35,143 +35,12 @@
+
+
The class that deals with storage of the keyring. Currently the only option is to use HTML5 local storage.
-
- new (require("keyring/keyring"))(storeHandler )
-
-
-
-
-
-
-
- Initialization routine for the keyring. This method reads the
-keyring from HTML5 local storage and initializes this instance.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
- Argument
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- storeHandler
-
-
-
-
-
-class
-
-
-
-
-
-
-
-
- <optional>
-
-
-
-
-
-
-
-
-
-
- class implementing load() and store() methods
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -224,6 +93,13 @@ keyring from HTML5 local storage and initializes this instance.
+ Classes
+
+
+ Keyring
+
+
+
@@ -234,1095 +110,6 @@ keyring from HTML5 local storage and initializes this instance.
-
- clear()
-
-
-
-
-
-
-
- Clear the keyring - erase all the keys
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- exportKey(index) → {String}
-
-
-
-
-
-
-
- returns the armored message representation of the key at key ring index
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- index
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- the index of the key within the array
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- armored message representing the key object
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- exportPublicKey(index) → {String}
-
-
-
-
-
-
-
- returns the armored message representation of the public key portion of the key at key ring index
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- index
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- the index of the key within the array
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- armored message representing the public key object
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getKeysForKeyId(keyId) → {Array.<module:key~Key >}
-
-
-
-
-
-
-
- Searches the keyring for public keys having the specified key id
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- keyId
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- provided as string of hex number (lowercase)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- public keys found
-
-
-
-
-
-
- Type
-
-
-
-Array.<module:key~Key >
-
-
-
-
-
-
-
-
-
-
-
-
-
- getPrivateKeyForAddress(email) → {Array.<module:key~Key >}
-
-
-
-
-
-
-
- Searches the keyring for a private key containing the specified email address
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- email
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- email address to search for
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- private keys found
-
-
-
-
-
-
- Type
-
-
-
-Array.<module:key~Key >
-
-
-
-
-
-
-
-
-
-
-
-
-
- getPublicKeyForAddress(email) → {Array.<module:key~Key >}
-
-
-
-
-
-
-
- searches all public keys in the keyring matching the address or address part of the user ids
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- email
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- email address to search for
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The public keys associated with provided email address.
-
-
-
-
-
-
- Type
-
-
-
-Array.<module:key~Key >
-
-
-
-
-
-
-
-
-
-
-
-
-
- importKey(armored)
-
-
-
-
-
-
-
- Imports a key from an ascii armored message
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- armored
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- message to read the keys/key from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Removes a public key from the public key keyring at the specified index
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- index
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- the index of the public key within the publicKeys array
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The public key object which has been removed
-
-
-
-
-
-
- Type
-
-
-
-module:key~Key
-
-
-
-
-
-
-
-
-
-
-
-
-
- store()
-
-
-
-
-
-
-
- Calls the storeHandler to save the keys
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
<inner> checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) → {Array.<module:key~Key >}
@@ -2035,13 +822,13 @@ keyring from HTML5 local storage and initializes this instance.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/keyring.js.html b/doc/keyring.js.html
index 21303cda..98121e66 100644
--- a/doc/keyring.js.html
+++ b/doc/keyring.js.html
@@ -58,162 +58,161 @@ var openpgp = require('openpgp');
* @return {Boolean} True if the input matches the specified key
*/
-/**
+module.exports = Keyring;
+
+ /**
* Initialization routine for the keyring. This method reads the
* keyring from HTML5 local storage and initializes this instance.
* @constructor
* @param {class} [storeHandler] class implementing load() and store() methods
*/
-module.exports = function(storeHandler) {
- if (!storeHandler) {
- storeHandler = new (require('./localstore.js'))();
- }
- this.storeHandler = storeHandler;
+function Keyring(storeHandler) {
+ this.storeHandler = storeHandler || new (require('./localstore.js'))();
this.keys = this.storeHandler.load();
+};
- /**
- * Calls the storeHandler to save the keys
- */
- this.store = function () {
- this.storeHandler.store(this.keys);
- };
+/**
+ * Calls the storeHandler to save the keys
+ */
+Keyring.prototype.store = function () {
+ this.storeHandler.store(this.keys);
+};
- /**
- * Clear the keyring - erase all the keys
- */
- this.clear = function() {
- this.keys = [];
- };
+/**
+ * Clear the keyring - erase all the keys
+ */
+Keyring.prototype.clear = function() {
+ this.keys = [];
+};
- /**
- * Checks a key to see if it matches the specified email address
- * @param {String} email email address to search for
- * @param {module:key~Key} key The key to be checked.
- * @return {Boolean} True if the email address is defined in the specified key
- */
- function emailCheck(email, key) {
- email = email.toLowerCase();
- var keyEmails = key.getUserIds();
- for (var i; i < keyEmails.length; i++) {
- //we need to get just the email from the userid key
- keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();
- if (keyEmail == email) {
- return true;
- }
+/**
+ * Checks a key to see if it matches the specified email address
+ * @param {String} email email address to search for
+ * @param {module:key~Key} key The key to be checked.
+ * @return {Boolean} True if the email address is defined in the specified key
+ */
+function emailCheck(email, key) {
+ email = email.toLowerCase();
+ var keyEmails = key.getUserIds();
+ for (var i; i < keyEmails.length; i++) {
+ //we need to get just the email from the userid key
+ keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();
+ if (keyEmail == email) {
+ return true;
}
- return false;
}
+ return false;
+}
- /**
- * Checks a key to see if it matches the specified keyid
- * @param {String} id hex string keyid to search for
- * @param {module:key~Key} key the key to be checked.
- * @return {Boolean} true if the email address is defined in the specified key
- * @inner
- */
- function idCheck(id, key) {
- var keyids = key.getKeyIds();
- for (var i = 0; i < keyids.length; i++) {
- if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
- return true;
- }
+/**
+ * Checks a key to see if it matches the specified keyid
+ * @param {String} id hex string keyid to search for
+ * @param {module:key~Key} key the key to be checked.
+ * @return {Boolean} true if the email address is defined in the specified key
+ * @inner
+ */
+function idCheck(id, key) {
+ var keyids = key.getKeyIds();
+ for (var i = 0; i < keyids.length; i++) {
+ if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
+ return true;
}
- return false;
}
+ return false;
+}
- /**
- * searches all public keys in the keyring matching the address or address part of the user ids
- * @param {Array<module:key~Key>} keys array of keys to search
- * @param {module:keyring/keyring.checkCallback} identityFunction callback function which checks for a match
- * @param {String} identityInput input to check against
- * @param {module:enums.packet} keyType packet types of keys to check
- * @return {Array<module:key~Key>} array of keys which match
- */
- function checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) {
- var results = [];
- for (var p = 0; p < keys.length; p++) {
- var key = keys[p];
- switch (keyType) {
- case openpgp.enums.packet.public_key:
- if (key.isPublic() && identityFunction(identityInput, key)) {
- results.push(key);
- }
- break;
- case openpgp.enums.packet.private_key:
- if (key.isPrivate() && identityFunction(identityInput, key)) {
- results.push(key);
- }
- break;
- }
+/**
+ * searches all public keys in the keyring matching the address or address part of the user ids
+ * @param {Array<module:key~Key>} keys array of keys to search
+ * @param {module:keyring/keyring.checkCallback} identityFunction callback function which checks for a match
+ * @param {String} identityInput input to check against
+ * @param {module:enums.packet} keyType packet types of keys to check
+ * @return {Array<module:key~Key>} array of keys which match
+ */
+function checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) {
+ var results = [];
+ for (var p = 0; p < keys.length; p++) {
+ var key = keys[p];
+ switch (keyType) {
+ case openpgp.enums.packet.publicKey:
+ if (key.isPublic() && identityFunction(identityInput, key)) {
+ results.push(key);
+ }
+ break;
+ case openpgp.enums.packet.private_key:
+ if (key.isPrivate() && identityFunction(identityInput, key)) {
+ results.push(key);
+ }
+ break;
}
- return results;
}
+ return results;
+}
- /**
- * searches all public keys in the keyring matching the address or address part of the user ids
- * @param {String} email email address to search for
- * @return {Array<module:key~Key>} The public keys associated with provided email address.
- */
- this.getPublicKeyForAddress = function (email) {
- return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.public_key);
- };
+/**
+ * searches all public keys in the keyring matching the address or address part of the user ids
+ * @param {String} email email address to search for
+ * @return {Array<module:key~Key>} The public keys associated with provided email address.
+ */
+Keyring.prototype.getPublicKeyForAddress = function (email) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.publicKey);
+};
- /**
- * Searches the keyring for a private key containing the specified email address
- * @param {String} email email address to search for
- * @return {Array<module:key~Key>} private keys found
- */
- this.getPrivateKeyForAddress = function (email) {
- return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secret_key);
- };
+/**
+ * Searches the keyring for a private key containing the specified email address
+ * @param {String} email email address to search for
+ * @return {Array<module:key~Key>} private keys found
+ */
+Keyring.prototype.getPrivateKeyForAddress = function (email) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secretKey);
+};
- /**
- * Searches the keyring for public keys having the specified key id
- * @param {String} keyId provided as string of hex number (lowercase)
- * @return {Array<module:key~Key>} public keys found
- */
- this.getKeysForKeyId = function (keyId) {
- return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.public_key);
- };
+/**
+ * Searches the keyring for public keys having the specified key id
+ * @param {String} keyId provided as string of hex number (lowercase)
+ * @return {Array<module:key~Key>} public keys found
+ */
+Keyring.prototype.getKeysForKeyId = function (keyId) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.publicKey);
+};
- /**
- * Imports a key from an ascii armored message
- * @param {String} armored message to read the keys/key from
- */
- this.importKey = function (armored) {
- this.keys = this.keys.concat(openpgp.key.readArmored(armored).keys);
+/**
+ * Imports a key from an ascii armored message
+ * @param {String} armored message to read the keys/key from
+ */
+Keyring.prototype.importKey = function (armored) {
+ this.keys = this.keys.concat(openpgp.key.readArmored(armored).keys);
- return true;
- };
+ return true;
+};
- /**
- * returns the armored message representation of the key at key ring index
- * @param {Integer} index the index of the key within the array
- * @return {String} armored message representing the key object
- */
- this.exportKey = function (index) {
- return this.keys[index].armor();
- };
+/**
+ * returns the armored message representation of the key at key ring index
+ * @param {Integer} index the index of the key within the array
+ * @return {String} armored message representing the key object
+ */
+Keyring.prototype.exportKey = function (index) {
+ return this.keys[index].armor();
+};
- /**
- * Removes a public key from the public key keyring at the specified index
- * @param {Integer} index the index of the public key within the publicKeys array
- * @return {module:key~Key} The public key object which has been removed
- */
- this.removeKey = function (index) {
- var removed = this.keys.splice(index, 1);
+/**
+ * Removes a public key from the public key keyring at the specified index
+ * @param {Integer} index the index of the public key within the publicKeys array
+ * @return {module:key~Key} The public key object which has been removed
+ */
+Keyring.prototype.removeKey = function (index) {
+ var removed = this.keys.splice(index, 1);
- return removed;
- };
+ return removed;
+};
- /**
- * returns the armored message representation of the public key portion of the key at key ring index
- * @param {Integer} index the index of the key within the array
- * @return {String} armored message representing the public key object
- */
- this.exportPublicKey = function (index) {
- return this.keys[index].toPublic().armor();
- };
+/**
+ * returns the armored message representation of the public key portion of the key at key ring index
+ * @param {Integer} index the index of the key within the array
+ * @return {String} armored message representing the public key object
+ */
+Keyring.prototype.exportPublicKey = function (index) {
+ return this.keys[index].toPublic().armor();
};
@@ -225,13 +224,13 @@ module.exports = function(storeHandler) {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/literal-Literal.html b/doc/literal-Literal.html
new file mode 100644
index 00000000..30cf3f09
--- /dev/null
+++ b/doc/literal-Literal.html
@@ -0,0 +1,924 @@
+
+
+
+
+ JSDoc: Class: Literal
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Literal
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Literal()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ getBytes() → {String}
+
+
+
+
+
+
+
+ Get the byte sequence representing the literal packet data
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ A sequence of bytes
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getText() → {String}
+
+
+
+
+
+
+
+ Returns literal data packets as native JavaScript string
+with normalized end of line to \n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ literal data as text
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parsing function for a literal data packet (tag 11).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of a tag 11 packet
+
+
+
+
+
+
+ position
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Position to start reading from the input string
+
+
+
+
+
+
+ len
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Length of the packet or the remaining length of
+ input at position
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/literal
+
+
+
+
+
+
+
+
+
+
+
+
+
+ setBytes(bytes, format)
+
+
+
+
+
+
+
+ Set the packet data to value represented by the provided string of bytes.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ bytes
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ The string of bytes
+
+
+
+
+
+
+ format
+
+
+
+
+
+utf8
+|
+
+binary
+|
+
+text
+
+
+
+
+
+
+
+
+
+ The format of the string of bytes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ setText(text)
+
+
+
+
+
+
+
+ Set the packet data to a javascript native string, end of line
+will be normalized to \r\n and by default text is converted to UTF8
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ text
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Any native javascript string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write(data) → {String}
+
+
+
+
+
+
+
+ Creates a string representation of the packet
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ data
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ The data to be inserted as body
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ string-representation of the packet
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/literal.html b/doc/literal.html
index d125a445..27f43d0a 100644
--- a/doc/literal.html
+++ b/doc/literal.html
@@ -35,81 +35,15 @@
+
+
Implementation of the Literal Data Packet (Tag 11)
-RFC4880 5.9: A Literal Data packet contains the body of a message; data that
+
RFC4880 5.9 : A Literal Data packet contains the body of a message; data that
is not to be further interpreted.
-
- new (require("packet/literal"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -164,792 +98,23 @@ is not to be further interpreted.
-
-
-
-
-
-
- Methods
+ Classes
-
-
- getBytes() → {String}
-
-
-
-
-
-
-
- Get the byte sequence representing the literal packet data
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A sequence of bytes
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getText() → {String}
-
-
-
-
-
-
-
- Returns literal data packets as native JavaScript string
-with normalized end of line to \n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- literal data as text
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Parsing function for a literal data packet (tag 11).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of a tag 11 packet
-
-
-
-
-
-
- position
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Position to start reading from the input string
-
-
-
-
-
-
- len
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Length of the packet or the remaining length of
- input at position
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/literal
-
-
-
-
-
-
-
-
-
-
-
-
-
- setBytes(bytes, format)
-
-
-
-
-
-
-
- Set the packet data to value represented by the provided string of bytes.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The string of bytes
-
-
-
-
-
-
- format
-
-
-
-
-
-utf8
-|
-
-binary
-|
-
-text
-
-
-
-
-
-
-
-
-
- The format of the string of bytes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- setText(text)
-
-
-
-
-
-
-
- Set the packet data to a javascript native string, end of line
-will be normalized to \r\n and by default text is converted to UTF8
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- text
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Any native javascript string
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write(data) → {String}
-
-
-
-
-
-
-
- Creates a string representation of the packet
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- data
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The data to be inserted as body
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- string-representation of the packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
+ Literal
+
+
+
+
+
+
+
@@ -960,13 +125,13 @@ will be normalized to \r\n and by default text is converted to UTF8
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/literal.js.html b/doc/literal.js.html
index a3cc5e9f..9e1e230e 100644
--- a/doc/literal.js.html
+++ b/doc/literal.js.html
@@ -45,114 +45,115 @@
/**
* Implementation of the Literal Data Packet (Tag 11)<br/>
* <br/>
- * RFC4880 5.9: A Literal Data packet contains the body of a message; data that
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.9|RFC4880 5.9}: A Literal Data packet contains the body of a message; data that
* is not to be further interpreted.
* @requires enums
* @requires util
* @module packet/literal
*/
+module.exports = Literal;
+
var util = require('../util'),
enums = require('../enums.js');
/**
* @constructor
*/
-module.exports = function literal() {
+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();
+}
+
+/**
+ * Set the packet data to a javascript native string, end of line
+ * will be normalized to \r\n and by default text is converted to UTF8
+ * @param {String} text Any native javascript string
+ */
+Literal.prototype.setText = function (text) {
+ // normalize EOL to \r\n
+ text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
+ // encode UTF8
+ this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
+};
+
+/**
+ * Returns literal data packets as native JavaScript string
+ * with normalized end of line to \n
+ * @return {String} literal data as text
+ */
+Literal.prototype.getText = function () {
+ // decode UTF8
+ var text = util.decode_utf8(this.data);
+ // normalize EOL to \n
+ return text.replace(/\r\n/g, '\n');
+};
+
+/**
+ * Set the packet data to value represented by the provided string of bytes.
+ * @param {String} bytes The string of bytes
+ * @param {utf8|binary|text} format The format of the string of bytes
+ */
+Literal.prototype.setBytes = function (bytes, format) {
+ this.format = format;
+ this.data = bytes;
+};
- /**
- * Set the packet data to a javascript native string, end of line
- * 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) {
- // normalize EOL to \r\n
- text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
- // encode UTF8
- this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
- };
-
- /**
- * Returns literal data packets as native JavaScript string
- * with normalized end of line to \n
- * @return {String} literal data as text
- */
- this.getText = function () {
- // decode UTF8
- var text = util.decode_utf8(this.data);
- // normalize EOL to \n
- return text.replace(/\r\n/g, '\n');
- };
-
- /**
- * Set the packet data to value represented by the provided string of bytes.
- * @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.format = format;
- this.data = bytes;
- };
+/**
+ * Get the byte sequence representing the literal packet data
+ * @returns {String} A sequence of bytes
+ */
+Literal.prototype.getBytes = function () {
+ return this.data;
+};
- /**
- * Get the byte sequence representing the literal packet data
- * @returns {String} A sequence of bytes
- */
- this.getBytes = function () {
- return this.data;
- };
+/**
+ * Parsing function for a literal data packet (tag 11).
+ *
+ * @param {String} input Payload of a tag 11 packet
+ * @param {Integer} position
+ * Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/literal} object representation
+ */
+Literal.prototype.read = function (bytes) {
+ // - A one-octet field that describes how the data is formatted.
+ var format = enums.read(enums.literal, bytes.charCodeAt(0));
- /**
- * Parsing function for a literal data packet (tag 11).
- *
- * @param {String} input Payload of a tag 11 packet
- * @param {Integer} position
- * Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/literal} object representation
- */
- this.read = function (bytes) {
- // - A one-octet field that describes how the data is formatted.
+ var filename_len = bytes.charCodeAt(1);
+ this.filename = util.decode_utf8(bytes.substr(2, filename_len));
- var format = enums.read(enums.literal, bytes.charCodeAt(0));
+ this.date = util.readDate(bytes.substr(2 + filename_len, 4));
- var filename_len = bytes.charCodeAt(1);
- this.filename = util.decode_utf8(bytes.substr(2, filename_len));
+ var data = bytes.substring(6 + filename_len);
- this.date = util.readDate(bytes.substr(2 + filename_len, 4));
+ this.setBytes(data, format);
+};
- var data = bytes.substring(6 + filename_len);
+/**
+ * Creates a string representation of the packet
+ *
+ * @param {String} data The data to be inserted as body
+ * @return {String} string-representation of the packet
+ */
+Literal.prototype.write = function () {
+ var filename = util.encode_utf8("msg.txt");
- this.setBytes(data, format);
- };
+ var data = this.getBytes();
- /**
- * Creates a string representation of the packet
- *
- * @param {String} data The data to be inserted as body
- * @return {String} string-representation of the packet
- */
- this.write = function () {
- var filename = util.encode_utf8("msg.txt");
-
- var data = this.getBytes();
-
- var result = '';
- result += String.fromCharCode(enums.write(enums.literal, this.format));
- result += String.fromCharCode(filename.length);
- result += filename;
- result += util.writeDate(this.date);
- result += data;
- return result;
- };
+ var result = '';
+ result += String.fromCharCode(enums.write(enums.literal, this.format));
+ result += String.fromCharCode(filename.length);
+ result += filename;
+ result += util.writeDate(this.date);
+ result += data;
+ return result;
};
@@ -164,13 +165,13 @@ module.exports = function literal() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/localStorage-LocalStorage.html b/doc/localStorage-LocalStorage.html
new file mode 100644
index 00000000..c39e4599
--- /dev/null
+++ b/doc/localStorage-LocalStorage.html
@@ -0,0 +1,292 @@
+
+
+
+
+ JSDoc: Class: LocalStorage
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: LocalStorage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new LocalStorage()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ read()
+
+
+
+
+
+
+
+ Reads the config out of the HTML5 local storage
+and initializes the object config.
+if config is null the default config will be used
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write()
+
+
+
+
+
+
+
+ Writes the config to HTML5 local storage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/localStorage.html b/doc/localStorage.html
index a237dd9f..3c5e6cdb 100644
--- a/doc/localStorage.html
+++ b/doc/localStorage.html
@@ -35,78 +35,12 @@
+
+
This object storing and retrieving configuration from HTML5 local storage.
-
- new (require("config/localStorage"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -153,160 +87,23 @@
-
-
-
-
-
-
- Methods
+ Classes
-
-
- read()
-
-
-
-
-
-
-
- Reads the config out of the HTML5 local storage
-and initializes the object config.
-if config is null the default config will be used
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write()
-
-
-
-
-
-
-
- Writes the config to HTML5 local storage
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ LocalStorage
+
+
+
+
+
+
+
@@ -317,13 +114,13 @@ if config is null the default config will be used
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/localStorage.js.html b/doc/localStorage.js.html
index 77b14d78..fb90a4e3 100644
--- a/doc/localStorage.js.html
+++ b/doc/localStorage.js.html
@@ -30,31 +30,33 @@
* @module config/localStorage
*/
+module.exports = LocalStorage;
+
/**
* @constructor
*/
-module.exports = function localStorage() {
+function LocalStorage() {
+}
- /**
- * Reads the config out of the HTML5 local storage
- * and initializes the object config.
- * if config is null the default config will be used
- */
- this.read = function () {
- var cf = JSON.parse(window.localStorage.getItem("config"));
- if (cf === null) {
- this.config = this.default_config;
- this.write();
- } else
- this.config = cf;
- };
+/**
+ * Reads the config out of the HTML5 local storage
+ * and initializes the object config.
+ * if config is null the default config will be used
+ */
+LocalStorage.prototype.read = function () {
+ var cf = JSON.parse(window.localStorage.getItem("config"));
+ if (cf === null) {
+ this.config = this.default_config;
+ this.write();
+ } else
+ this.config = cf;
+};
- /**
- * Writes the config to HTML5 local storage
- */
- this.write = function () {
- window.localStorage.setItem("config", JSON.stringify(this.config));
- };
+/**
+ * Writes the config to HTML5 local storage
+ */
+LocalStorage.prototype.write = function () {
+ window.localStorage.setItem("config", JSON.stringify(this.config));
};
@@ -66,13 +68,13 @@ module.exports = function localStorage() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/localstore.html b/doc/localstore.html
index 4fde3bd2..be03bba0 100644
--- a/doc/localstore.html
+++ b/doc/localstore.html
@@ -99,219 +99,6 @@
- Methods
-
-
-
-
-
-
-
-
-
-
-
-
- Load the keyring from HTML5 local storage and initializes this instance.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- array of keys retrieved from localstore
-
-
-
-
-
-
- Type
-
-
-
-Array.<module:key~Key >
-
-
-
-
-
-
-
-
-
-
-
-
-
- <static> store(keys)
-
-
-
-
-
-
-
- Saves the current state of the keyring to HTML5 local storage.
-The privateKeys array and publicKeys array gets Stringified using JSON
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- keys
-
-
-
-
-
-Array.<module:key~Key >
-
-
-
-
-
-
-
-
-
- array of keys to save in localstore
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -326,13 +113,13 @@ The privateKeys array and publicKeys array gets Stringified using JSON
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/localstore.js.html b/doc/localstore.js.html
index 644c9b38..c3739060 100644
--- a/doc/localstore.js.html
+++ b/doc/localstore.js.html
@@ -47,39 +47,41 @@
* @requires openpgp
* @module keyring/localstore
*/
+module.exports = LocalStore;
var openpgp = require('openpgp');
-module.exports = function () {
- /**
- * Load the keyring from HTML5 local storage and initializes this instance.
- * @return {Array<module:key~Key>} array of keys retrieved from localstore
- */
- this.load = function () {
- var armoredKeys = JSON.parse(window.localStorage.getItem("armoredKeys"));
- var keys = [];
- if (armoredKeys !== null && armoredKeys.length !== 0) {
- var key;
- for (var i = 0; i < armoredKeys.length; i++) {
- key = openpgp.key.readArmored(armoredKeys[i]);
- keys.push(key);
- }
- }
- return keys;
- };
+function LocalStore() {
+}
- /**
- * Saves the current state of the keyring to HTML5 local storage.
- * The privateKeys array and publicKeys array gets Stringified using JSON
- * @param {Array<module:key~Key>} keys array of keys to save in localstore
- */
- this.store = function (keys) {
- var armoredKeys = [];
- for (var i = 0; i < keys.length; i++) {
- armoredKeys.push(keys[i].armor());
+/**
+ * Load the keyring from HTML5 local storage and initializes this instance.
+ * @return {Array<module:key~Key>} array of keys retrieved from localstore
+ */
+LocalStore.prototype.load = function () {
+ var armoredKeys = JSON.parse(window.localStorage.getItem("armoredKeys"));
+ var keys = [];
+ if (armoredKeys !== null && armoredKeys.length !== 0) {
+ var key;
+ for (var i = 0; i < armoredKeys.length; i++) {
+ key = openpgp.key.readArmored(armoredKeys[i]);
+ keys.push(key);
}
- window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
- };
+ }
+ return keys;
+};
+
+/**
+ * Saves the current state of the keyring to HTML5 local storage.
+ * The privateKeys array and publicKeys array gets Stringified using JSON
+ * @param {Array<module:key~Key>} keys array of keys to save in localstore
+ */
+LocalStore.prototype.store = function (keys) {
+ var armoredKeys = [];
+ for (var i = 0; i < keys.length; i++) {
+ armoredKeys.push(keys[i].armor());
+ }
+ window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
};
@@ -91,13 +93,13 @@ module.exports = function () {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/marker-Marker.html b/doc/marker-Marker.html
new file mode 100644
index 00000000..dc1fa708
--- /dev/null
+++ b/doc/marker-Marker.html
@@ -0,0 +1,338 @@
+
+
+
+
+ JSDoc: Class: Marker
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Marker
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Marker()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+
+
+
+
+
+
+
+
+ Parsing function for a literal data packet (tag 10).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of a tag 10 packet
+
+
+
+
+
+
+ position
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Position to start reading from the input string
+
+
+
+
+
+
+ len
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Length of the packet or the remaining length of
+ input at position
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/marker
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/marker.html b/doc/marker.html
index 6056eec5..120127b7 100644
--- a/doc/marker.html
+++ b/doc/marker.html
@@ -35,10 +35,12 @@
+
+
Implementation of the strange "Marker packet" (Tag 10)
-RFC4880 5.8: An experimental version of PGP used this packet as the Literal
+
RFC4880 5.8 : An experimental version of PGP used this packet as the Literal
packet, but no released version of PGP generated Literal packets with this
tag. With PGP 5.x, this packet has been reassigned and is reserved for use as
the Marker packet.
@@ -46,74 +48,6 @@ the Marker packet.
Such a packet MUST be ignored when received.
-
- new (require("packet/marker"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -160,206 +94,23 @@ Such a packet MUST be ignored when received.
-
-
-
-
-
-
- Methods
+ Classes
-
-
-
-
-
-
-
-
-
-
- Parsing function for a literal data packet (tag 10).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of a tag 10 packet
-
-
-
-
-
-
- position
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Position to start reading from the input string
-
-
-
-
-
-
- len
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Length of the packet or the remaining length of
- input at position
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/marker
-
-
-
-
-
-
-
-
-
-
+ Marker
+
+
+
+
+
+
+
@@ -370,13 +121,13 @@ Such a packet MUST be ignored when received.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/marker.js.html b/doc/marker.js.html
index 49938be3..08c432f9 100644
--- a/doc/marker.js.html
+++ b/doc/marker.js.html
@@ -46,7 +46,7 @@
/**
* Implementation of the strange "Marker packet" (Tag 10)<br/>
* <br/>
- * RFC4880 5.8: An experimental version of PGP used this packet as the Literal
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.8|RFC4880 5.8}: An experimental version of PGP used this packet as the Literal
* packet, but no released version of PGP generated Literal packets with this
* tag. With PGP 5.x, this packet has been reassigned and is reserved for use as
* the Marker packet.<br/>
@@ -55,29 +55,32 @@
* @module packet/marker
*/
+module.exports = Marker;
+
/**
* @constructor
*/
-module.exports = function marker() {
- /**
- * Parsing function for a literal data packet (tag 10).
- *
- * @param {String} input Payload of a tag 10 packet
- * @param {Integer} position
- * Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/marker} Object representation
- */
- this.read = function (bytes) {
- if (bytes.charCodeAt(0) == 0x50 && // P
- bytes.charCodeAt(1) == 0x47 && // G
- bytes.charCodeAt(2) == 0x50) // P
- return true;
- // marker packet does not contain "PGP"
- return false;
- };
+function Marker() {
+}
+
+/**
+ * Parsing function for a literal data packet (tag 10).
+ *
+ * @param {String} input Payload of a tag 10 packet
+ * @param {Integer} position
+ * Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/marker} Object representation
+ */
+Marker.prototype.read = function (bytes) {
+ if (bytes.charCodeAt(0) == 0x50 && // P
+ bytes.charCodeAt(1) == 0x47 && // G
+ bytes.charCodeAt(2) == 0x50) // P
+ return true;
+ // marker packet does not contain "PGP"
+ return false;
};
@@ -89,13 +92,13 @@ module.exports = function marker() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/md5.html b/doc/md5.html
index 4c0ac4d6..3eb168bf 100644
--- a/doc/md5.html
+++ b/doc/md5.html
@@ -229,13 +229,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/md5.js.html b/doc/md5.js.html
index 18e89261..d2f9915b 100644
--- a/doc/md5.js.html
+++ b/doc/md5.js.html
@@ -252,13 +252,13 @@ if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/message.js.html b/doc/message.js.html
index 968ce459..e9c45cc3 100644
--- a/doc/message.js.html
+++ b/doc/message.js.html
@@ -62,14 +62,14 @@ var packet = require('./packet'),
* @classdesc Class that represents an OpenPGP message.
* Can be an encrypted message, signed message, compressed message or literal message
* @param {module:packet/packetlist} packetlist The packets that form this message
- * See http://tools.ietf.org/html/rfc4880#section-11.3
+ * See {@link http://tools.ietf.org/html/rfc4880#section-11.3}
*/
function Message(packetlist) {
if (!(this instanceof Message)) {
return new Message(packetlist);
}
- this.packets = packetlist || new packet.list();
+ this.packets = packetlist || new packet.List();
}
/**
@@ -78,7 +78,7 @@ function Message(packetlist) {
*/
Message.prototype.getEncryptionKeyIds = function() {
var keyIds = [];
- var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
+ var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
pkESKeyPacketlist.forEach(function(packet) {
keyIds.push(packet.publicKeyId);
});
@@ -93,7 +93,7 @@ Message.prototype.getSigningKeyIds = function() {
var keyIds = [];
var msg = this.unwrapCompressed();
// search for one pass signatures
- var onePassSigList = msg.packets.filterByTag(enums.packet.one_pass_signature);
+ var onePassSigList = msg.packets.filterByTag(enums.packet.onePassSignature);
onePassSigList.forEach(function(packet) {
keyIds.push(packet.signingKeyId);
});
@@ -120,7 +120,7 @@ Message.prototype.decrypt = function(privateKey) {
}
var privateKeyPacket = privateKey.getPrivateKeyPacket(encryptionKeyIds);
if (!privateKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.');
- var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
+ var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
var pkESKeyPacket;
for (var i = 0; i < pkESKeyPacketlist.length; i++) {
if (pkESKeyPacketlist[i].publicKeyId.equals(privateKeyPacket.getKeyId())) {
@@ -130,7 +130,7 @@ Message.prototype.decrypt = function(privateKey) {
}
}
if (pkESKeyPacket) {
- var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetrically_encrypted, enums.packet.sym_encrypted_integrity_protected);
+ var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected);
if (symEncryptedPacketlist.length !== 0) {
var symEncryptedPacket = symEncryptedPacketlist[0];
symEncryptedPacket.decrypt(pkESKeyPacket.sessionKeyAlgorithm, pkESKeyPacket.sessionKey);
@@ -167,13 +167,13 @@ Message.prototype.getText = function() {
* @return {Array<module:message~Message>} new message with encrypted content
*/
Message.prototype.encrypt = function(keys) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
//TODO get preferred algo from signature
var sessionKey = crypto.generateSessionKey(enums.read(enums.symmetric, config.encryption_cipher));
keys.forEach(function(key) {
var encryptionKeyPacket = key.getEncryptionKeyPacket();
if (encryptionKeyPacket) {
- var pkESKeyPacket = new packet.public_key_encrypted_session_key();
+ var pkESKeyPacket = new packet.PublicKeyEncryptedSessionKey();
pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId();
pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm;
pkESKeyPacket.sessionKey = sessionKey;
@@ -187,9 +187,9 @@ Message.prototype.encrypt = function(keys) {
});
var symEncryptedPacket;
if (config.integrity_protect) {
- symEncryptedPacket = new packet.sym_encrypted_integrity_protected();
+ symEncryptedPacket = new packet.SymEncryptedIntegrityProtected();
} else {
- symEncryptedPacket = new packet.symmetrically_encrypted();
+ symEncryptedPacket = new packet.SymmetricallyEncrypted();
}
symEncryptedPacket.packets = this.packets;
//TODO get preferred algo from signature
@@ -205,7 +205,7 @@ Message.prototype.encrypt = function(keys) {
*/
Message.prototype.sign = function(privateKeys) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
var literalDataPacket = this.packets.findPacket(enums.packet.literal);
if (!literalDataPacket) throw new Error('No literal data packet to sign.');
@@ -215,7 +215,7 @@ Message.prototype.sign = function(privateKeys) {
enums.signature.binary : enums.signature.text;
var i;
for (i = 0; i < privateKeys.length; i++) {
- var onePassSig = new packet.one_pass_signature();
+ var onePassSig = new packet.OnePassSignature();
onePassSig.type = signatureType;
//TODO get preferred hashg algo from key signature
onePassSig.hashAlgorithm = config.prefer_hash_algorithm;
@@ -231,7 +231,7 @@ Message.prototype.sign = function(privateKeys) {
packetlist.push(literalDataPacket);
for (i = privateKeys.length - 1; i >= 0; i--) {
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = signatureType;
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
@@ -300,7 +300,7 @@ function readArmored(armoredText) {
//TODO how do we want to handle bad text? Exception throwing
//TODO don't accept non-message armored texts
var input = armor.decode(armoredText).data;
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input);
var newMessage = new Message(packetlist);
return newMessage;
@@ -313,10 +313,10 @@ function readArmored(armoredText) {
* @static
*/
function fromText(text) {
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
// text will be converted to UTF8
literalDataPacket.setText(text);
- var literalDataPacketlist = new packet.list();
+ var literalDataPacketlist = new packet.List();
literalDataPacketlist.push(literalDataPacket);
var newMessage = new Message(literalDataPacketlist);
return newMessage;
@@ -329,9 +329,9 @@ function fromText(text) {
* @static
*/
function fromBinary(bytes) {
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
literalDataPacket.setBytes(bytes, enums.read(enums.literal, enums.literal.binary));
- var literalDataPacketlist = new packet.list();
+ var literalDataPacketlist = new packet.List();
literalDataPacketlist.push(literalDataPacket);
var newMessage = new Message(literalDataPacketlist);
return newMessage;
@@ -351,13 +351,13 @@ exports.fromBinary = fromBinary;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/module-armor.html b/doc/module-armor.html
index 234081be..da40dc27 100644
--- a/doc/module-armor.html
+++ b/doc/module-armor.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/module-cleartext-CleartextMessage.html b/doc/module-cleartext-CleartextMessage.html
index 922f470c..2cc25e23 100644
--- a/doc/module-cleartext-CleartextMessage.html
+++ b/doc/module-cleartext-CleartextMessage.html
@@ -33,7 +33,7 @@
Class that represents an OpenPGP cleartext signed message.
-See http://tools.ietf.org/html/rfc4880#section-7
+See http://tools.ietf.org/html/rfc4880#section-7
@@ -741,13 +741,13 @@ See http://tools.ietf.org/html/rfc4880#section-7
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/module-cleartext.html b/doc/module-cleartext.html
index 766d2bcc..05107213 100644
--- a/doc/module-cleartext.html
+++ b/doc/module-cleartext.html
@@ -267,13 +267,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/module-config.html b/doc/module-config.html
index f2230251..bc4b04dd 100644
--- a/doc/module-config.html
+++ b/doc/module-config.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/module-crypto.html b/doc/module-crypto.html
index 9821b8c1..0970136f 100644
--- a/doc/module-crypto.html
+++ b/doc/module-crypto.html
@@ -515,13 +515,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:28 GMT+0100 (MEZ)
diff --git a/doc/module-enums.html b/doc/module-enums.html
index e91c229c..6575fd6f 100644
--- a/doc/module-enums.html
+++ b/doc/module-enums.html
@@ -369,7 +369,7 @@
@@ -579,7 +579,7 @@
@@ -1643,7 +1643,7 @@
- public_key_encrypted_session_key
+ publicKeyEncryptedSessionKey
@@ -1701,7 +1701,7 @@
- sym_encrypted_session_key
+ symEncryptedSessionKey
@@ -1730,7 +1730,7 @@
- one_pass_signature
+ onePassSignature
@@ -1759,7 +1759,7 @@
- secret_key
+ secretKey
@@ -1788,7 +1788,7 @@
- public_key
+ publicKey
@@ -1817,7 +1817,7 @@
- secret_subkey
+ secretSubkey
@@ -1875,7 +1875,7 @@
- symmetrically_encrypted
+ symmetricallyEncrypted
@@ -2020,7 +2020,7 @@
- public_subkey
+ publicSubkey
@@ -2049,7 +2049,7 @@
- user_attribute
+ userAttribute
@@ -2078,7 +2078,7 @@
- sym_encrypted_integrity_protected
+ symEncryptedIntegrityProtected
@@ -2107,7 +2107,7 @@
- modification_detection_code
+ modificationDetectionCode
@@ -2182,7 +2182,7 @@
@@ -4022,7 +4022,7 @@ document) that cannot include a target subpacket.
@@ -4527,13 +4527,13 @@ document) that cannot include a target subpacket.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/module-key-Key.html b/doc/module-key-Key.html
index c605bdfd..89a37215 100644
--- a/doc/module-key-Key.html
+++ b/doc/module-key-Key.html
@@ -2252,13 +2252,13 @@ and valid self signature
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-key-SubKey.html b/doc/module-key-SubKey.html
index a8a9137b..9df768f6 100644
--- a/doc/module-key-SubKey.html
+++ b/doc/module-key-SubKey.html
@@ -594,13 +594,13 @@ and valid binding signature
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-key-User.html b/doc/module-key-User.html
index 414fded8..a27127c4 100644
--- a/doc/module-key-User.html
+++ b/doc/module-key-User.html
@@ -676,13 +676,13 @@ and validity of self signature
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-key.html b/doc/module-key.html
index 76e4e19f..777450f8 100644
--- a/doc/module-key.html
+++ b/doc/module-key.html
@@ -170,7 +170,7 @@ Primary and subkey will be of same type.
-Integer
+module:enums.publicKey
@@ -180,8 +180,8 @@ Primary and subkey will be of same type.
- to indicate what type of key to make.
- RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ to indicate what type of key to make.
+ RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
@@ -479,13 +479,13 @@ Primary and subkey will be of same type.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/module-keyid.html b/doc/module-keyid.html
index 4487745e..1572fbcb 100644
--- a/doc/module-keyid.html
+++ b/doc/module-keyid.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:52 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-message-Message.html b/doc/module-message-Message.html
index b81645dd..ed41af96 100644
--- a/doc/module-message-Message.html
+++ b/doc/module-message-Message.html
@@ -99,7 +99,7 @@ Can be an encrypted message, signed message, compressed message or literal messa
The packets that form this message
-See http://tools.ietf.org/html/rfc4880#section-11.3
+See http://tools.ietf.org/html/rfc4880#section-11.3
@@ -1297,13 +1297,13 @@ See http://tools.ietf.org/html/rfc4880#section-11.3
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-message.html b/doc/module-message.html
index 24ee518e..545750fb 100644
--- a/doc/module-message.html
+++ b/doc/module-message.html
@@ -547,13 +547,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-mpi.html b/doc/module-mpi.html
index 9ee11d03..3db3c76b 100644
--- a/doc/module-mpi.html
+++ b/doc/module-mpi.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-openpgp.html b/doc/module-openpgp.html
index 805c6df5..f2bf64b2 100644
--- a/doc/module-openpgp.html
+++ b/doc/module-openpgp.html
@@ -675,7 +675,7 @@ Primary and subkey will be of same type.
-Integer
+module:enums.publicKey
@@ -685,8 +685,8 @@ Primary and subkey will be of same type.
- to indicate what type of key to make.
- RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ to indicate what type of key to make.
+ RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
@@ -1358,13 +1358,13 @@ Primary and subkey will be of same type.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-packet.html b/doc/module-packet.html
index 6a6c7a8e..3214aa64 100644
--- a/doc/module-packet.html
+++ b/doc/module-packet.html
@@ -100,7 +100,7 @@
- <static> compressed
+ <static> Compressed
@@ -157,7 +157,64 @@
- <static> literal
+ <static> List
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <static> Literal
@@ -214,7 +271,7 @@
- <static> marker
+ <static> Marker
@@ -271,7 +328,7 @@
- <static> one_pass_signature
+ <static> OnePassSignature
@@ -328,7 +385,7 @@
- <static> public_key
+ <static> PublicKey
@@ -385,7 +442,7 @@
- <static> public_key_encrypted_session_key
+ <static> PublicKeyEncryptedSessionKey
@@ -442,7 +499,7 @@
- <static> public_subkey
+ <static> PublicSubkey
@@ -499,7 +556,7 @@
- <static> secret_key
+ <static> SecretKey
@@ -556,7 +613,7 @@
- <static> secret_subkey
+ <static> SecretSubkey
@@ -613,7 +670,7 @@
- <static> signature
+ <static> Signature
@@ -670,7 +727,7 @@
- <static> sym_encrypted_integrity_protected
+ <static> SymEncryptedIntegrityProtected
@@ -727,7 +784,7 @@
- <static> sym_encrypted_session_key
+ <static> SymEncryptedSessionKey
@@ -784,7 +841,7 @@
- <static> symmetrically_encrypted
+ <static> SymmetricallyEncrypted
@@ -841,7 +898,7 @@
- <static> trust
+ <static> Trust
@@ -898,7 +955,7 @@
- <static> user_attribute
+ <static> UserAttribute
@@ -955,7 +1012,7 @@
- <static> userid
+ <static> Userid
@@ -1013,6 +1070,284 @@
+ Methods
+
+
+
+
+ <static> newPacketFromTag(tag) → {Object}
+
+
+
+
+
+
+
+ Allocate a new packet
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ tag
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ property name from module:enums.packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ new packet object with type based on tag
+
+
+
+
+
+
+ Type
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <inner> packetClassFromTagName(tag) → {String}
+
+
+
+
+
+
+
+ Convert tag name to class name
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ tag
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ property name from module:enums.packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1027,13 +1362,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:31 GMT+0100 (MEZ)
diff --git a/doc/module-s2k.html b/doc/module-s2k.html
index ef97b27e..7e0fcbf3 100644
--- a/doc/module-s2k.html
+++ b/doc/module-s2k.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/module-util.html b/doc/module-util.html
index 14c67107..eb6b2c31 100644
--- a/doc/module-util.html
+++ b/doc/module-util.html
@@ -112,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
diff --git a/doc/mpi-MPI.html b/doc/mpi-MPI.html
new file mode 100644
index 00000000..86e62e1a
--- /dev/null
+++ b/doc/mpi-MPI.html
@@ -0,0 +1,440 @@
+
+
+
+
+ JSDoc: Class: MPI
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: MPI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new MPI()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+ data
+
+
+
+
+
+
+ An implementation dependent integer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ read(input) → {Integer}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of mpi data
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Length of data read
+
+
+
+
+
+
+ Type
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ Converts the mpi object to a string as specified in
RFC4880 3.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ mpi Byte representation
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/mpi.html b/doc/mpi.html
index d80d367b..1926ccff 100644
--- a/doc/mpi.html
+++ b/doc/mpi.html
@@ -35,8 +35,10 @@
+
+
-
Implementation of type MPI (RFC4880 3.2)
+
Implementation of type MPI (
RFC4880 3.2 )
Multiprecision integers (also called MPIs) are unsigned integers used
to hold large integers such as the ones used in cryptographic
@@ -46,74 +48,6 @@ of the MPI in bits followed by a string of octets that contain the
actual integer.
-
- new (require("type/mpi"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -168,304 +102,19 @@ actual integer.
-
-
-
-
-
Members
+
Classes
-
-
- data
-
-
-
-
-
-
- An implementation dependent integer
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ MPI
+
-
Methods
-
-
-
-
- read(input) → {Integer}
-
-
-
- Parsing function for a mpi (RFC 4880 3.2).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of mpi data
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Length of data read
-
-
-
-
-
-
- Type
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Converts the mpi object to a string as specified in RFC4880 3.2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- mpi Byte representation
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -480,13 +129,13 @@ actual integer.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
diff --git a/doc/mpi.js.html b/doc/mpi.js.html
index dd549b1d..d381d926 100644
--- a/doc/mpi.js.html
+++ b/doc/mpi.js.html
@@ -48,7 +48,7 @@
// - MPI = c | d << 8 | e << ((MPI.length -2)*8) | f ((MPI.length -2)*8)
/**
- * Implementation of type MPI (RFC4880 3.2)<br/>
+ * Implementation of type MPI ({@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2})<br/>
* <br/>
* Multiprecision integers (also called MPIs) are unsigned integers used
* to hold large integers such as the ones used in cryptographic
@@ -61,69 +61,71 @@
* @module type/mpi
*/
+module.exports = MPI;
+
var BigInteger = require('../crypto/public_key/jsbn.js'),
util = require('../util');
/**
* @constructor
*/
-module.exports = function mpi() {
+function MPI() {
/** An implementation dependent integer */
this.data = null;
+}
- /**
- * Parsing function for a mpi (RFC 4880 3.2).
- * @param {String} input Payload of mpi data
- * @return {Integer} Length of data read
- */
- this.read = function (bytes) {
- var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
+/**
+ * Parsing function for a mpi ({@link http://tools.ietf.org/html/rfc4880#section3.2|RFC 4880 3.2}).
+ * @param {String} input Payload of mpi data
+ * @return {Integer} Length of data read
+ */
+MPI.prototype.read = function (bytes) {
+ var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
- // Additional rules:
- //
- // The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
- //
- // The length field of an MPI describes the length starting from its
- // most significant non-zero bit. Thus, the MPI [00 02 01] is not
- // formed correctly. It should be [00 01 01].
+ // Additional rules:
+ //
+ // The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
+ //
+ // The length field of an MPI describes the length starting from its
+ // most significant non-zero bit. Thus, the MPI [00 02 01] is not
+ // formed correctly. It should be [00 01 01].
- // TODO: Verification of this size method! This size calculation as
- // specified above is not applicable in JavaScript
- var bytelen = Math.ceil(bits / 8);
+ // TODO: Verification of this size method! This size calculation as
+ // specified above is not applicable in JavaScript
+ var bytelen = Math.ceil(bits / 8);
- var raw = bytes.substr(2, bytelen);
- this.fromBytes(raw);
+ var raw = bytes.substr(2, bytelen);
+ this.fromBytes(raw);
- return 2 + bytelen;
- };
+ return 2 + bytelen;
+};
- this.fromBytes = function (bytes) {
- this.data = new BigInteger(util.hexstrdump(bytes), 16);
- };
+MPI.prototype.fromBytes = function (bytes) {
+ this.data = new BigInteger(util.hexstrdump(bytes), 16);
+};
- this.toBytes = function () {
- return this.write().substr(2);
- };
+MPI.prototype.toBytes = function () {
+ return this.write().substr(2);
+};
- this.byteLength = function () {
- return this.toBytes().length;
- };
+MPI.prototype.byteLength = function () {
+ return this.toBytes().length;
+};
- /**
- * Converts the mpi object to a string as specified in RFC4880 3.2
- * @return {String} mpi Byte representation
- */
- this.write = function () {
- return this.data.toMPI();
- };
+/**
+ * Converts the mpi object to a string as specified in {@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2}
+ * @return {String} mpi Byte representation
+ */
+MPI.prototype.write = function () {
+ return this.data.toMPI();
+};
- this.toBigInteger = function () {
- return this.data.clone();
- };
+MPI.prototype.toBigInteger = function () {
+ return this.data.clone();
+};
- this.fromBigInteger = function (bn) {
- this.data = bn.clone();
- };
+MPI.prototype.fromBigInteger = function (bn) {
+ this.data = bn.clone();
};
@@ -135,13 +137,13 @@ module.exports = function mpi() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/one_pass_signature-OnePassSignature.html b/doc/one_pass_signature-OnePassSignature.html
new file mode 100644
index 00000000..03a08719
--- /dev/null
+++ b/doc/one_pass_signature-OnePassSignature.html
@@ -0,0 +1,382 @@
+
+
+
+
+ JSDoc: Class: OnePassSignature
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: OnePassSignature
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new OnePassSignature()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+
+
+
+
+
+
+
+
+ parsing function for a one-pass signature packet (tag 4).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ bytes
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ payload of a tag 4 packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/one_pass_signature
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ creates a string representation of a one-pass signature packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ a string representation of a one-pass signature packet
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/one_pass_signature.html b/doc/one_pass_signature.html
index 8720ecd8..fca33f48 100644
--- a/doc/one_pass_signature.html
+++ b/doc/one_pass_signature.html
@@ -35,85 +35,18 @@
+
+
Implementation of the One-Pass Signature Packets (Tag 4)
-RFC4880 5.4:
-The One-Pass Signature packet precedes the signed data and contains
+
RFC4880 5.4 : The One-Pass Signature packet precedes the signed data and contains
enough information to allow the receiver to begin calculating any
hashes needed to verify the signature. It allows the Signature
packet to be placed at the end of the message, so that the signer
can compute the entire signed message in one pass.
-
- new (require("packet/one_pass_signature"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -168,250 +101,23 @@ can compute the entire signed message in one pass.
-
-
-
-
-
-
- Methods
+ Classes
-
-
-
-
-
-
-
-
-
-
- parsing function for a one-pass signature packet (tag 4).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- payload of a tag 4 packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/one_pass_signature
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- creates a string representation of a one-pass signature packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- a string representation of a one-pass signature packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
+ OnePassSignature
+
+
+
+
+
+
+
@@ -422,13 +128,13 @@ can compute the entire signed message in one pass.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/one_pass_signature.js.html b/doc/one_pass_signature.js.html
index abb09a50..4a744040 100644
--- a/doc/one_pass_signature.js.html
+++ b/doc/one_pass_signature.js.html
@@ -45,8 +45,7 @@
/**
* Implementation of the One-Pass Signature Packets (Tag 4)<br/>
* <br/>
- * RFC4880 5.4:
- * The One-Pass Signature packet precedes the signed data and contains
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.4|RFC4880 5.4}: The One-Pass Signature packet precedes the signed data and contains
* enough information to allow the receiver to begin calculating any
* hashes needed to verify the signature. It allows the Signature
* packet to be placed at the end of the message, so that the signer
@@ -56,69 +55,71 @@
* @module packet/one_pass_signature
*/
+module.exports = OnePassSignature;
+
var enums = require('../enums.js'),
type_keyid = require('../type/keyid.js');
/**
* @constructor
*/
-module.exports = function one_pass_signature() {
+function OnePassSignature() {
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)
- this.publicKeyAlgorithm = null; // A one-octet number describing the public-key algorithm used. (See RFC4880 9.1)
+ this.type = null; // A one-octet signature type. Signature types are described in {@link http://tools.ietf.org/html/rfc4880#section-5.2.1|RFC4880 Section 5.2.1}.
+ this.hashAlgorithm = null; // A one-octet number describing the hash algorithm used. (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC4880 9.4})
+ this.publicKeyAlgorithm = null; // A one-octet number describing the public-key algorithm used. (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880 9.1})
this.signingKeyId = null; // An eight-octet number holding the Key ID of the signing key.
this.flags = null; // A one-octet number holding a flag showing whether the signature is nested. A zero value indicates that the next packet is another One-Pass Signature packet that describes another signature to be applied to the same message data.
+}
- /**
- * parsing function for a one-pass signature packet (tag 4).
- * @param {String} bytes payload of a tag 4 packet
- * @return {module:packet/one_pass_signature} object representation
- */
- this.read = function (bytes) {
- var mypos = 0;
- // A one-octet version number. The current version is 3.
- this.version = bytes.charCodeAt(mypos++);
+/**
+ * parsing function for a one-pass signature packet (tag 4).
+ * @param {String} bytes payload of a tag 4 packet
+ * @return {module:packet/one_pass_signature} object representation
+ */
+OnePassSignature.prototype.read = function (bytes) {
+ var mypos = 0;
+ // A one-octet version number. The current version is 3.
+ this.version = bytes.charCodeAt(mypos++);
- // A one-octet signature type. Signature types are described in
- // Section 5.2.1.
- this.type = enums.read(enums.signature, bytes.charCodeAt(mypos++));
+ // A one-octet signature type. Signature types are described in
+ // Section 5.2.1.
+ this.type = enums.read(enums.signature, bytes.charCodeAt(mypos++));
- // A one-octet number describing the hash algorithm used.
- this.hashAlgorithm = enums.read(enums.hash, bytes.charCodeAt(mypos++));
+ // A one-octet number describing the hash algorithm used.
+ this.hashAlgorithm = enums.read(enums.hash, bytes.charCodeAt(mypos++));
- // A one-octet number describing the public-key algorithm used.
- this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(mypos++));
+ // A one-octet number describing the public-key algorithm used.
+ this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(mypos++));
- // An eight-octet number holding the Key ID of the signing key.
- this.signingKeyId = new type_keyid();
- this.signingKeyId.read(bytes.substr(mypos));
- mypos += 8;
+ // An eight-octet number holding the Key ID of the signing key.
+ this.signingKeyId = new type_keyid();
+ this.signingKeyId.read(bytes.substr(mypos));
+ mypos += 8;
- // A one-octet number holding a flag showing whether the signature
- // is nested. A zero value indicates that the next packet is
- // another One-Pass Signature packet that describes another
- // signature to be applied to the same message data.
- this.flags = bytes.charCodeAt(mypos++);
- return this;
- };
+ // A one-octet number holding a flag showing whether the signature
+ // is nested. A zero value indicates that the next packet is
+ // another One-Pass Signature packet that describes another
+ // signature to be applied to the same message data.
+ this.flags = bytes.charCodeAt(mypos++);
+ return this;
+};
- /**
- * creates a string representation of a one-pass signature packet
- * @return {String} a string representation of a one-pass signature packet
- */
- this.write = function () {
- var result = "";
+/**
+ * creates a string representation of a one-pass signature packet
+ * @return {String} a string representation of a one-pass signature packet
+ */
+OnePassSignature.prototype.write = function () {
+ var result = "";
- result += String.fromCharCode(3);
- result += String.fromCharCode(enums.write(enums.signature, this.type));
- result += String.fromCharCode(enums.write(enums.hash, this.hashAlgorithm));
- result += String.fromCharCode(enums.write(enums.publicKey, this.publicKeyAlgorithm));
- result += this.signingKeyId.write();
- result += String.fromCharCode(this.flags);
+ result += String.fromCharCode(3);
+ result += String.fromCharCode(enums.write(enums.signature, this.type));
+ result += String.fromCharCode(enums.write(enums.hash, this.hashAlgorithm));
+ result += String.fromCharCode(enums.write(enums.publicKey, this.publicKeyAlgorithm));
+ result += this.signingKeyId.write();
+ result += String.fromCharCode(this.flags);
- return result;
- };
+ return result;
};
@@ -130,13 +131,13 @@ module.exports = function one_pass_signature() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/openpgp.js.html b/doc/openpgp.js.html
index b81879d0..236cfa3c 100644
--- a/doc/openpgp.js.html
+++ b/doc/openpgp.js.html
@@ -165,8 +165,8 @@ function verifyClearSignedMessage(publicKeys, message) {
/**
* Generates a new OpenPGP key pair. Currently only supports RSA keys.
* Primary and subkey will be of same type.
- * @param {Integer} keyType to indicate what type of key to make.
- * RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ * @param {module:enums.publicKey} keyType to indicate what type of key to make.
+ * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1}
* @param {Integer} numBits number of bits for the key creation. (should be 1024+, generally)
* @param {String} userId assumes already in form of "User Name <username@email.com>"
* @param {String} passphrase The passphrase used to encrypt the resulting private key
@@ -199,13 +199,13 @@ exports.generateKeyPair = generateKeyPair;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/packet.html b/doc/packet.html
index 60205715..9fe3d385 100644
--- a/doc/packet.html
+++ b/doc/packet.html
@@ -239,7 +239,7 @@
Source:
@@ -402,7 +402,7 @@ string
Source:
@@ -565,7 +565,7 @@ string
Source:
@@ -705,7 +705,7 @@ string
Source:
@@ -768,13 +768,13 @@ string
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/packet.js.html b/doc/packet.js.html
index 4f04546d..bb6b2b35 100644
--- a/doc/packet.js.html
+++ b/doc/packet.js.html
@@ -51,7 +51,6 @@
var enums = require('../enums.js'),
util = require('../util');
-
module.exports = {
readSimpleLength: function(bytes) {
var len = 0,
@@ -299,13 +298,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/packetlist-Packetlist.html b/doc/packetlist-Packetlist.html
new file mode 100644
index 00000000..eade1d96
--- /dev/null
+++ b/doc/packetlist-Packetlist.html
@@ -0,0 +1,1051 @@
+
+
+
+
+ JSDoc: Class: Packetlist
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Packetlist
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Packetlist()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+ <readonly> length :Integer
+
+
+
+
+
+
+ The number of packets contained within the list.
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ concat()
+
+
+
+
+
+
+
+ Concatenates packetlist or array of packets
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ filter()
+
+
+
+
+
+
+
+ Creates a new PacketList with all packets that pass the test implemented by the provided function.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ filterByTag()
+
+
+
+
+
+
+
+ Creates a new PacketList with all packets from the given types
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Traverses packet tree and returns first matching packet
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ type
+
+
+
+
+
+module:enums.packet
+
+
+
+
+
+
+
+
+
+ The packet type
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/packet
+|
+
+null
+
+
+
+
+
+
+
+
+
+
+
+
+
+ forEach()
+
+
+
+
+
+
+
+ Executes the provided callback once for each element
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ indexOfTag()
+
+
+
+
+
+
+
+ Returns array of found indices by tag
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ push()
+
+
+
+
+
+
+
+ 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.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ read(A)
+
+
+
+
+
+
+
+ Reads a stream of binary data and interprents it as a list of packets.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ binary string of bytes.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ slice()
+
+
+
+
+
+
+
+ Returns slice of packetlist
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ Creates a binary representation of openpgp objects contained within the
+class instance.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ A binary string of bytes containing valid openpgp packets.
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/packetlist.html b/doc/packetlist.html
index e905bb88..078a1ab4 100644
--- a/doc/packetlist.html
+++ b/doc/packetlist.html
@@ -35,80 +35,14 @@
+
+
This class represents a list of openpgp packets.
Take care when iterating over it - the packets themselves
are stored as numerical indices.
-
- new (require("packet/packetlist"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -165,915 +99,19 @@ are stored as numerical indices.
-
-
-
-
- Members
+ Classes
-
-
- <readonly> length :Integer
-
-
-
-
-
-
- The number of packets contained within the list.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Packetlist
+
- Methods
-
-
-
-
- concat()
-
-
-
- Concatenates packetlist or array of packets
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- filter()
-
-
-
-
-
-
-
- Creates a new packetList with all packets that pass the test implemented by the provided function.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- filterByTag()
-
-
-
-
-
-
-
- Creates a new packetList with all packets from the given types
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Traverses packet tree and returns first matching packet
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- type
-
-
-
-
-
-module:enums.packet
-
-
-
-
-
-
-
-
-
- The packet type
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
-
-
-
- Type
-
-
-
-module:packet/packet
-|
-
-null
-
-
-
-
-
-
-
-
-
-
-
-
-
- forEach()
-
-
-
-
-
-
-
- Executes the provided callback once for each element
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- indexOfTag()
-
-
-
-
-
-
-
- Returns array of found indices by tag
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- push()
-
-
-
-
-
-
-
- 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.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(A)
-
-
-
-
-
-
-
- Reads a stream of binary data and interprents it as a list of packets.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- A
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- binary string of bytes.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- slice()
-
-
-
-
-
-
-
- Returns slice of packetlist
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Creates a binary representation of openpgp objects contained within the
-class instance.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A binary string of bytes containing valid openpgp packets.
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1088,13 +126,13 @@ class instance.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:53 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/packetlist.js.html b/doc/packetlist.js.html
index b325fd93..7470d021 100644
--- a/doc/packetlist.js.html
+++ b/doc/packetlist.js.html
@@ -35,6 +35,8 @@
* @module packet/packetlist
*/
+module.exports = Packetlist;
+
var packetParser = require('./packet.js'),
packets = require('./all_packets.js'),
enums = require('../enums.js');
@@ -42,164 +44,163 @@ var packetParser = require('./packet.js'),
/**
* @constructor
*/
-module.exports = function packetlist() {
+function Packetlist() {
/** The number of packets contained within the list.
* @readonly
* @type {Integer} */
this.length = 0;
+}
+/**
+ * Reads a stream of binary data and interprents it as a list of packets.
+ * @param {String} A binary string of bytes.
+ */
+Packetlist.prototype.read = function (bytes) {
+ var i = 0;
- /**
- * 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) {
- var i = 0;
+ while (i < bytes.length) {
+ var parsed = packetParser.read(bytes, i, bytes.length - i);
+ i = parsed.offset;
- while (i < bytes.length) {
- var parsed = packetParser.read(bytes, i, bytes.length - i);
- i = parsed.offset;
+ var tag = enums.read(enums.packet, parsed.tag);
+ var packet = packets.newPacketFromTag(tag);
- var tag = enums.read(enums.packet, parsed.tag);
- var packet = new packets[tag]();
+ this.push(packet);
- this.push(packet);
+ packet.read(parsed.packet);
+ }
+};
- packet.read(parsed.packet);
+/**
+ * Creates a binary representation of openpgp objects contained within the
+ * class instance.
+ * @returns {String} A binary string of bytes containing valid openpgp packets.
+ */
+Packetlist.prototype.write = function () {
+ var bytes = '';
+
+ for (var i = 0; i < this.length; i++) {
+ var packetbytes = this[i].write();
+ bytes += packetParser.writeHeader(this[i].tag, packetbytes.length);
+ bytes += packetbytes;
+ }
+
+ return bytes;
+};
+
+/**
+ * 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.
+ */
+Packetlist.prototype.push = function (packet) {
+ if (!packet) return;
+
+ packet.packets = packet.packets || new Packetlist();
+
+ this[this.length] = packet;
+ this.length++;
+};
+
+/**
+* Creates a new PacketList with all packets that pass the test implemented by the provided function.
+*/
+Packetlist.prototype.filter = function (callback) {
+
+ var filtered = new Packetlist();
+
+ for (var i = 0; i < this.length; i++) {
+ if (callback(this[i], i, this)) {
+ filtered.push(this[i]);
}
- };
+ }
- /**
- * Creates a binary representation of openpgp objects contained within the
- * class instance.
- * @returns {String} A binary string of bytes containing valid openpgp packets.
- */
- this.write = function () {
- var bytes = '';
+ return filtered;
+};
- for (var i = 0; i < this.length; i++) {
- var packetbytes = this[i].write();
- bytes += packetParser.writeHeader(this[i].tag, packetbytes.length);
- bytes += packetbytes;
+/**
+* Creates a new PacketList with all packets from the given types
+*/
+Packetlist.prototype.filterByTag = function () {
+ var args = Array.prototype.slice.call(arguments);
+ var filtered = new Packetlist();
+ var that = this;
+
+ for (var i = 0; i < this.length; i++) {
+ if (args.some(function(packetType) {return that[i].tag == packetType;})) {
+ filtered.push(this[i]);
}
+ }
- return bytes;
- };
+ return filtered;
+};
- /**
- * 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) {
- if (!packet) return;
-
- packet.packets = packet.packets || new packetlist();
-
- this[this.length] = packet;
- this.length++;
- };
-
- /**
- * Creates a new packetList with all packets that pass the test implemented by the provided function.
- */
- this.filter = function (callback) {
-
- var filtered = new packetlist();
+/**
+* Executes the provided callback once for each element
+*/
+Packetlist.prototype.forEach = function (callback) {
+ for (var i = 0; i < this.length; i++) {
+ callback(this[i]);
+ }
+};
+/**
+ * Traverses packet tree and returns first matching packet
+ * @param {module:enums.packet} type The packet type
+ * @return {module:packet/packet|null}
+ */
+Packetlist.prototype.findPacket = function (type) {
+ var packetlist = this.filterByTag(type);
+ if (packetlist.length) {
+ return packetlist[0];
+ } else {
+ var found = null;
for (var i = 0; i < this.length; i++) {
- if (callback(this[i], i, this)) {
- filtered.push(this[i]);
+ if (this[i].packets.length) {
+ found = this[i].packets.findPacket(type);
+ if (found) return found;
}
}
+ }
+ return null;
+};
- return filtered;
- };
-
- /**
- * Creates a new packetList with all packets from the given types
- */
- this.filterByTag = function () {
- var args = Array.prototype.slice.call(arguments);
- var filtered = new packetlist();
- var that = this;
-
- for (var i = 0; i < this.length; i++) {
- if (args.some(function(packetType) {return that[i].tag == packetType;})) {
- filtered.push(this[i]);
- }
+/**
+ * Returns array of found indices by tag
+ */
+Packetlist.prototype.indexOfTag = function () {
+ var args = Array.prototype.slice.call(arguments);
+ var tagIndex = [];
+ var that = this;
+ for (var i = 0; i < this.length; i++) {
+ if (args.some(function(packetType) {return that[i].tag == packetType;})) {
+ tagIndex.push(i);
}
+ }
+ return tagIndex;
+};
- return filtered;
- };
+/**
+ * Returns slice of packetlist
+ */
+Packetlist.prototype.slice = function (begin, end) {
+ if (!end) {
+ end = this.length;
+ }
+ var part = new Packetlist();
+ for (var i = begin; i < end; i++) {
+ part.push(this[i]);
+ }
+ return part;
+};
- /**
- * Executes the provided callback once for each element
- */
- this.forEach = function (callback) {
- for (var i = 0; i < this.length; i++) {
- callback(this[i]);
+/**
+ * Concatenates packetlist or array of packets
+ */
+Packetlist.prototype.concat = function (packetlist) {
+ if (packetlist) {
+ for (var i = 0; i < packetlist.length; i++) {
+ this.push(packetlist[i]);
}
- };
-
- /**
- * Traverses packet tree and returns first matching packet
- * @param {module:enums.packet} type The packet type
- * @return {module:packet/packet|null}
- */
- this.findPacket = function (type) {
- var packetlist = this.filterByTag(type);
- if (packetlist.length) {
- return packetlist[0];
- } else {
- var found = null;
- for (var i = 0; i < this.length; i++) {
- if (this[i].packets.length) {
- found = this[i].packets.findPacket(type);
- if (found) return found;
- }
- }
- }
- return null;
- };
-
- /**
- * Returns array of found indices by tag
- */
- this.indexOfTag = function () {
- var args = Array.prototype.slice.call(arguments);
- var tagIndex = [];
- var that = this;
- for (var i = 0; i < this.length; i++) {
- if (args.some(function(packetType) {return that[i].tag == packetType;})) {
- tagIndex.push(i);
- }
- }
- return tagIndex;
- };
-
- /**
- * Returns slice of packetlist
- */
- this.slice = function (begin, end) {
- if (!end) {
- end = this.length;
- }
- var part = new packetlist();
- for (var i = begin; i < end; i++) {
- part.push(this[i]);
- }
- return part;
- };
-
- /**
- * Concatenates packetlist or array of packets
- */
- this.concat = function (packetlist) {
- if (packetlist) {
- for (var i = 0; i < packetlist.length; i++) {
- this.push(packetlist[i]);
- }
- }
- };
+ }
};
@@ -211,13 +212,13 @@ module.exports = function packetlist() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/pkcs1.html b/doc/pkcs1.html
index 43d8efbc..855046cf 100644
--- a/doc/pkcs1.html
+++ b/doc/pkcs1.html
@@ -117,7 +117,7 @@
@@ -179,13 +179,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/pkcs1.js.html b/doc/pkcs1.js.html
index 79fd6f9d..a90b51e2 100644
--- a/doc/pkcs1.js.html
+++ b/doc/pkcs1.js.html
@@ -53,7 +53,7 @@
*/
/**
- * ASN1 object identifiers for hashes (See RFC4880 5.2.2)
+ * ASN1 object identifiers for hashes (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.2})
*/
hash_headers = [];
hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04,
@@ -83,7 +83,7 @@ var crypto = require('./crypto.js'),
module.exports = {
eme: {
/**
- * create a EME-PKCS1-v1_5 padding (See RFC4880 13.1.1)
+ * create a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1})
* @param {String} message message to be padded
* @param {Integer} length Length to the resulting message
* @return {String} EME-PKCS1 padded message
@@ -103,9 +103,9 @@ module.exports = {
},
/**
- * decodes a EME-PKCS1-v1_5 padding (See RFC4880 13.1.2)
+ * decodes a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.2|RFC 4880 13.1.2})
* @param {String} message EME-PKCS1 padded message
- * @return {String} decoded message
+ * @return {String} decoded message
*/
decode: function(message, len) {
if (message.length < len)
@@ -122,7 +122,7 @@ module.exports = {
emsa: {
/**
- * create a EMSA-PKCS1-v1_5 padding (See RFC4880 13.1.3)
+ * create a EMSA-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})
* @param {Integer} algo Hash algorithm type used
* @param {String} data Data to be hashed
* @param {Integer} keylength Key size of the public mpi in bytes
@@ -148,7 +148,7 @@ module.exports = {
},
/**
- * extract the hash out of an EMSA-PKCS1-v1.5 padding (See RFC4880 13.1.3)
+ * extract the hash out of an EMSA-PKCS1-v1.5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})
* @param {String} data Hash in pkcs1 encoding
* @returns {String} The hash as string
*/
@@ -180,13 +180,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/public_key-PublicKey.html b/doc/public_key-PublicKey.html
new file mode 100644
index 00000000..e71045a4
--- /dev/null
+++ b/doc/public_key-PublicKey.html
@@ -0,0 +1,954 @@
+
+
+
+
+ JSDoc: Class: PublicKey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: PublicKey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new PublicKey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+
+
+
+
+
+
+
+ Public key algorithm
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ created :Date
+
+
+
+
+
+
+ Key creation date.
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A list of multiprecision integers
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ readPublicKey
+
+
+
+
+
+
+ Alias of read()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ writePublicKey
+
+
+
+
+
+
+ Alias of write()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ getFingerprint() → {String}
+
+
+
+
+
+
+
+ Calculates the fingerprint of the key
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ A string containing the fingerprint
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getKeyId() → {String}
+
+
+
+
+
+
+
+ Calculates the key id of the key
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ A 8 byte key id
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ read(input) → {Object}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Input string to read the packet from
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ This object with attributes set by the parser
+
+
+
+
+
+
+ Type
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {Object}
+
+
+
+
+
+
+
+ Same as write_private_key, but has less information because of
+public key.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ {body: [string]OpenPGP packet body contents,
+header: [string] OpenPGP packet header, string: [string] header+body}
+
+
+
+
+
+
+ Type
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+ writeOld()
+
+
+
+
+
+
+
+ Write an old version packet - it's used by some of the internal routines.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/public_key.html b/doc/public_key.html
index d4630cea..5ea0e983 100644
--- a/doc/public_key.html
+++ b/doc/public_key.html
@@ -290,13 +290,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/public_key.js.html b/doc/public_key.js.html
index b6d182be..a96cce2c 100644
--- a/doc/public_key.js.html
+++ b/doc/public_key.js.html
@@ -45,7 +45,7 @@
/**
* Implementation of the Key Material Packet (Tag 5,6,7,14)<br/>
* <br/>
- * RFC4480 5.5:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.5|RFC4480 5.5}:
* A key material packet contains all the information about a public or
* private key. There are four variants of this packet type, and two
* major versions. Consequently, this section is complex.
@@ -57,6 +57,8 @@
* @module packet/public_key
*/
+module.exports = PublicKey;
+
var util = require('../util'),
type_mpi = require('../type/mpi.js'),
type_keyid = require('../type/keyid.js'),
@@ -66,7 +68,7 @@ var util = require('../util'),
/**
* @constructor
*/
-module.exports = function public_key() {
+function PublicKey() {
this.version = 4;
/** Key creation date.
* @type {Date} */
@@ -79,138 +81,134 @@ module.exports = function public_key() {
this.algorithm = 'rsa_sign';
// time in days (V3 only)
this.expirationTimeV3 = 0;
+}
+/**
+ * Internal Parser for public keys as specified in {@link http://tools.ietf.org/html/rfc4880#section-5.5.2|RFC 4880 section 5.5.2 Public-Key Packet Formats}
+ * called by read_tag<num>
+ * @param {String} input Input string to read the packet from
+ * @return {Object} This object with attributes set by the parser
+ */
+PublicKey.prototype.read = function (bytes) {
+ var pos = 0;
+ // A one-octet version number (3 or 4).
+ this.version = bytes.charCodeAt(pos++);
- /**
- * Internal Parser for public keys as specified in RFC 4880 section
- * 5.5.2 Public-Key Packet Formats
- * called by read_tag<num>
- * @param {String} input Input string to read the packet from
- * @return {Object} This object with attributes set by the parser
- */
- this.read = function (bytes) {
- var pos = 0;
- // A one-octet version number (3 or 4).
- this.version = bytes.charCodeAt(pos++);
+ if (this.version == 3 || this.version == 4) {
+ // - A four-octet number denoting the time that the key was created.
+ this.created = util.readDate(bytes.substr(pos, 4));
+ pos += 4;
- if (this.version == 3 || this.version == 4) {
- // - A four-octet number denoting the time that the key was created.
- this.created = util.readDate(bytes.substr(pos, 4));
- pos += 4;
-
- if (this.version == 3) {
- // - A two-octet number denoting the time in days that this key is
- // valid. If this number is zero, then it does not expire.
- this.expirationTimeV3 = util.readNumber(bytes.substr(pos, 2));
- pos += 2;
- }
-
- // - A one-octet number denoting the public-key algorithm of this key.
- this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(pos++));
-
- var mpicount = crypto.getPublicMpiCount(this.algorithm);
- this.mpi = [];
-
- var bmpi = bytes.substr(pos);
- var p = 0;
-
- for (var i = 0; i < mpicount && p < bmpi.length; i++) {
-
- this.mpi[i] = new type_mpi();
-
- p += this.mpi[i].read(bmpi.substr(p));
-
- if (p > bmpi.length) {
- throw new Error('Error reading MPI @:' + p);
- }
- }
-
- return p + 6;
- } else {
- throw new Error('Version ' + version + ' of the key packet is unsupported.');
- }
- };
-
- /**
- * Alias of read()
- * @function module:packet/public_key#readPublicKey
- * @see module:packet/public_key#read
- */
- this.readPublicKey = this.read;
-
- /**
- * Same as write_private_key, but has less information because of
- * public key.
- * @return {Object} {body: [string]OpenPGP packet body contents,
- * header: [string] OpenPGP packet header, string: [string] header+body}
- */
- this.write = function () {
- // Version
- var result = String.fromCharCode(this.version);
- result += util.writeDate(this.created);
if (this.version == 3) {
- result += util.writeNumber(this.expirationTimeV3, 2);
+ // - A two-octet number denoting the time in days that this key is
+ // valid. If this number is zero, then it does not expire.
+ this.expirationTimeV3 = util.readNumber(bytes.substr(pos, 2));
+ pos += 2;
}
- result += String.fromCharCode(enums.write(enums.publicKey, this.algorithm));
+
+ // - A one-octet number denoting the public-key algorithm of this key.
+ this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(pos++));
var mpicount = crypto.getPublicMpiCount(this.algorithm);
+ this.mpi = [];
- for (var i = 0; i < mpicount; i++) {
- result += this.mpi[i].write();
- }
+ var bmpi = bytes.substr(pos);
+ var p = 0;
- return result;
- };
+ for (var i = 0; i < mpicount && p < bmpi.length; i++) {
- /**
- * Alias of write()
- * @function module:packet/public_key#writePublicKey
- * @see module:packet/public_key#write
- */
- this.writePublicKey = this.write;
+ this.mpi[i] = new type_mpi();
- /**
- * Write an old version packet - it's used by some of the internal routines.
- */
- this.writeOld = function () {
- var bytes = this.writePublicKey();
+ p += this.mpi[i].read(bmpi.substr(p));
- return String.fromCharCode(0x99) +
- util.writeNumber(bytes.length, 2) +
- bytes;
- };
-
- /**
- * Calculates the key id of the key
- * @return {String} A 8 byte key id
- */
- this.getKeyId = function () {
- var keyid = new type_keyid();
- if (this.version == 4) {
- keyid.read(this.getFingerprint().substr(12, 8));
- } else if (this.version == 3) {
- keyid.read(this.mpi[0].write().substr(-8));
- }
- return keyid;
- };
-
- /**
- * Calculates the fingerprint of the key
- * @return {String} A string containing the fingerprint
- */
- this.getFingerprint = function () {
- var toHash = '';
- if (this.version == 4) {
- toHash = this.writeOld();
- return crypto.hash.sha1(toHash);
- } else if (this.version == 3) {
- var mpicount = crypto.getPublicMpiCount(this.algorithm);
- for (var i = 0; i < mpicount; i++) {
- toHash += this.mpi[i].toBytes();
+ if (p > bmpi.length) {
+ throw new Error('Error reading MPI @:' + p);
}
- return crypto.hash.md5(toHash);
}
- };
+
+ return p + 6;
+ } else {
+ throw new Error('Version ' + version + ' of the key packet is unsupported.');
+ }
+};
+
+/**
+ * Alias of read()
+ * @see module:packet/public_key~PublicKey#read
+ */
+PublicKey.prototype.readPublicKey = PublicKey.prototype.read;
+
+/**
+ * Same as write_private_key, but has less information because of
+ * public key.
+ * @return {Object} {body: [string]OpenPGP packet body contents,
+ * header: [string] OpenPGP packet header, string: [string] header+body}
+ */
+PublicKey.prototype.write = function () {
+ // Version
+ var result = String.fromCharCode(this.version);
+ result += util.writeDate(this.created);
+ if (this.version == 3) {
+ result += util.writeNumber(this.expirationTimeV3, 2);
+ }
+ result += String.fromCharCode(enums.write(enums.publicKey, this.algorithm));
+
+ var mpicount = crypto.getPublicMpiCount(this.algorithm);
+
+ for (var i = 0; i < mpicount; i++) {
+ result += this.mpi[i].write();
+ }
+
+ return result;
+};
+
+/**
+ * Alias of write()
+ * @see module:packet/public_key~PublicKey#write
+ */
+PublicKey.prototype.writePublicKey = PublicKey.prototype.write;
+
+/**
+ * Write an old version packet - it's used by some of the internal routines.
+ */
+PublicKey.prototype.writeOld = function () {
+ var bytes = this.writePublicKey();
+
+ return String.fromCharCode(0x99) +
+ util.writeNumber(bytes.length, 2) +
+ bytes;
+};
+
+/**
+ * Calculates the key id of the key
+ * @return {String} A 8 byte key id
+ */
+PublicKey.prototype.getKeyId = function () {
+ var keyid = new type_keyid();
+ if (this.version == 4) {
+ keyid.read(this.getFingerprint().substr(12, 8));
+ } else if (this.version == 3) {
+ keyid.read(this.mpi[0].write().substr(-8));
+ }
+ return keyid;
+};
+
+/**
+ * Calculates the fingerprint of the key
+ * @return {String} A string containing the fingerprint
+ */
+PublicKey.prototype.getFingerprint = function () {
+ var toHash = '';
+ if (this.version == 4) {
+ toHash = this.writeOld();
+ return crypto.hash.sha1(toHash);
+ } else if (this.version == 3) {
+ var mpicount = crypto.getPublicMpiCount(this.algorithm);
+ for (var i = 0; i < mpicount; i++) {
+ toHash += this.mpi[i].toBytes();
+ }
+ return crypto.hash.md5(toHash);
+ }
};
@@ -222,13 +220,13 @@ module.exports = function public_key() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/public_key_.html b/doc/public_key_.html
index 32746eb9..b4ff124b 100644
--- a/doc/public_key_.html
+++ b/doc/public_key_.html
@@ -35,83 +35,17 @@
+
+
Implementation of the Key Material Packet (Tag 5,6,7,14)
-RFC4480 5.5:
+
RFC4480 5.5 :
A key material packet contains all the information about a public or
private key. There are four variants of this packet type, and two
major versions. Consequently, this section is complex.
-
- new (require("packet/public_key"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -172,849 +106,19 @@ major versions. Consequently, this section is complex.
-
-
-
-
- Members
+ Classes
-
-
-
-
-
-
-
-
-
- Public key algorithm
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- created :Date
-
-
-
-
-
-
- Key creation date.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A list of multiprecision integers
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ PublicKey
+
- Methods
-
-
-
-
- getFingerprint() → {String}
-
-
-
- Calculates the fingerprint of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string containing the fingerprint
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getKeyId() → {String}
-
-
-
-
-
-
-
- Calculates the key id of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A 8 byte key id
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(input) → {Object}
-
-
-
-
-
-
-
- Internal Parser for public keys as specified in RFC 4880 section
-5.5.2 Public-Key Packet Formats
-called by read_tag<num>
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Input string to read the packet from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- This object with attributes set by the parser
-
-
-
-
-
-
- Type
-
-
-
-Object
-
-
-
-
-
-
-
-
-
-
-
-
-
- readPublicKey()
-
-
-
-
-
-
-
- Alias of read()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {Object}
-
-
-
-
-
-
-
- Same as write_private_key, but has less information because of
-public key.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- {body: [string]OpenPGP packet body contents,
-header: [string] OpenPGP packet header, string: [string] header+body}
-
-
-
-
-
-
- Type
-
-
-
-Object
-
-
-
-
-
-
-
-
-
-
-
-
-
- writeOld()
-
-
-
-
-
-
-
- Write an old version packet - it's used by some of the internal routines.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- writePublicKey()
-
-
-
-
-
-
-
- Alias of write()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1029,13 +133,13 @@ header: [string] OpenPGP packet header, string: [string] header+body}
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/public_key_encrypted_session_key-PublicKeyEncryptedSessionKey.html b/doc/public_key_encrypted_session_key-PublicKeyEncryptedSessionKey.html
new file mode 100644
index 00000000..cc611472
--- /dev/null
+++ b/doc/public_key_encrypted_session_key-PublicKeyEncryptedSessionKey.html
@@ -0,0 +1,776 @@
+
+
+
+
+ JSDoc: Class: PublicKeyEncryptedSessionKey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: PublicKeyEncryptedSessionKey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new PublicKeyEncryptedSessionKey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+
+
+
+
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ decrypt(key) → {String}
+
+
+
+
+
+
+
+ Decrypts the session key (only for public key encrypted session key
+packets (tag 1)
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+module:packet/secret_key
+
+
+
+
+
+
+
+
+
+ Private key with secMPIs unlocked
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The unencrypted session key
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parsing function for a publickey encrypted session key packet (tag 1).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of a tag 1 packet
+
+
+
+
+
+
+ position
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Position to start reading from the input string
+
+
+
+
+
+
+ len
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Length of the packet or the remaining length of
+ input at position
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/public_key_encrypted_session_key
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write(publicKeyId, publicMPIs, pubalgo, symmalgo, sessionkey) → {String}
+
+
+
+
+
+
+
+ Create a string representation of a tag 1 packet
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ publicKeyId
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ The public key id corresponding to publicMPIs key as string
+
+
+
+
+
+
+ publicMPIs
+
+
+
+
+
+Array.<module:type/mpi >
+
+
+
+
+
+
+
+
+
+ Multiprecision integer objects describing the public key
+
+
+
+
+
+
+ pubalgo
+
+
+
+
+
+module:enums.publicKey
+
+
+
+
+
+
+
+
+
+ The corresponding public key algorithm // See RFC4880 9.1
+
+
+
+
+
+
+ symmalgo
+
+
+
+
+
+module:enums.symmetric
+
+
+
+
+
+
+
+
+
+ The symmetric cipher algorithm used to encrypt the data
+ within an encrypteddatapacket or encryptedintegrity-
+ protecteddatapacket
+ following this packet //See RFC4880 9.2
+
+
+
+
+
+
+ sessionkey
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ A string of randombytes representing the session key
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The string representation
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/public_key_encrypted_session_key.html b/doc/public_key_encrypted_session_key.html
index 104a7c0f..0265487d 100644
--- a/doc/public_key_encrypted_session_key.html
+++ b/doc/public_key_encrypted_session_key.html
@@ -35,10 +35,12 @@
+
+
Public-Key Encrypted Session Key Packets (Tag 1)
-RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+
RFC4880 5.1 : A Public-Key Encrypted Session Key packet holds the session key
used to encrypt a message. Zero or more Public-Key Encrypted Session Key
packets and/or Symmetric-Key Encrypted Session Key packets may precede a
Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -51,74 +53,6 @@ public key, decrypts the session key, and then uses the session key to
decrypt the message.
-
- new (require("packet/public_key_encrypted_session_key"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -179,640 +113,19 @@ decrypt the message.
-
-
-
-
- Members
+ Classes
-
-
-
-
-
-
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ PublicKeyEncryptedSessionKey
+
- Methods
-
-
-
-
- decrypt(key) → {String}
-
-
-
- Decrypts the session key (only for public key encrypted session key
-packets (tag 1)
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- key
-
-
-
-
-
-module:packet/secret_key
-
-
-
-
-
-
-
-
-
- Private key with secMPIs unlocked
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The unencrypted session key
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Parsing function for a publickey encrypted session key packet (tag 1).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of a tag 1 packet
-
-
-
-
-
-
- position
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Position to start reading from the input string
-
-
-
-
-
-
- len
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Length of the packet or the remaining length of
- input at position
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/public_key_encrypted_session_key
-
-
-
-
-
-
-
-
-
-
-
-
-
- write(publicKeyId, publicMPIs, pubalgo, symmalgo, sessionkey) → {String}
-
-
-
-
-
-
-
- Create a string representation of a tag 1 packet
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- publicKeyId
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The public key id corresponding to publicMPIs key as string
-
-
-
-
-
-
- publicMPIs
-
-
-
-
-
-Array.<module:type/mpi >
-
-
-
-
-
-
-
-
-
- Multiprecision integer objects describing the public key
-
-
-
-
-
-
- pubalgo
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- The corresponding public key algorithm // See RFC4880 9.1
-
-
-
-
-
-
- symmalgo
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- The symmetric cipher algorithm used to encrypt the data
- within an encrypteddatapacket or encryptedintegrity-
- protecteddatapacket
- following this packet //See RFC4880 9.2
-
-
-
-
-
-
- sessionkey
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- A string of randombytes representing the session key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The string representation
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -827,13 +140,13 @@ packets (tag 1)
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/public_key_encrypted_session_key.js.html b/doc/public_key_encrypted_session_key.js.html
index 91bfc855..1d6d2557 100644
--- a/doc/public_key_encrypted_session_key.js.html
+++ b/doc/public_key_encrypted_session_key.js.html
@@ -45,7 +45,7 @@
/**
* Public-Key Encrypted Session Key Packets (Tag 1)<br/>
* <br/>
- * RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}: A Public-Key Encrypted Session Key packet holds the session key
* used to encrypt a message. Zero or more Public-Key Encrypted Session Key
* packets and/or Symmetric-Key Encrypted Session Key packets may precede a
* Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -64,6 +64,8 @@
* @module packet/public_key_encrypted_session_key
*/
+module.exports = PublicKeyEncryptedSessionKey;
+
var type_keyid = require('../type/keyid.js'),
util = require('../util'),
type_mpi = require('../type/mpi.js'),
@@ -73,7 +75,7 @@ var type_keyid = require('../type/keyid.js'),
/**
* @constructor
*/
-module.exports = function public_key_encrypted_session_key() {
+function PublicKeyEncryptedSessionKey() {
this.version = 3;
this.publicKeyId = new type_keyid();
@@ -84,128 +86,128 @@ module.exports = function public_key_encrypted_session_key() {
/** @type {Array<module:type/mpi>} */
this.encrypted = [];
+}
- /**
- * Parsing function for a publickey encrypted session key packet (tag 1).
- *
- * @param {String} input Payload of a tag 1 packet
- * @param {Integer} position Position to start reading from the input string
- * @param {Integer} len Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/public_key_encrypted_session_key} Object representation
- */
- this.read = function (bytes) {
+/**
+ * Parsing function for a publickey encrypted session key packet (tag 1).
+ *
+ * @param {String} input Payload of a tag 1 packet
+ * @param {Integer} position Position to start reading from the input string
+ * @param {Integer} len Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/public_key_encrypted_session_key} Object representation
+ */
+PublicKeyEncryptedSessionKey.prototype.read = function (bytes) {
- this.version = bytes.charCodeAt(0);
- this.publicKeyId.read(bytes.substr(1));
- this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
+ this.version = bytes.charCodeAt(0);
+ this.publicKeyId.read(bytes.substr(1));
+ this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
- var i = 10;
+ var i = 10;
- var integerCount = (function(algo) {
- switch (algo) {
- case 'rsa_encrypt':
- case 'rsa_encrypt_sign':
- return 1;
+ var integerCount = (function(algo) {
+ switch (algo) {
+ case 'rsa_encrypt':
+ case 'rsa_encrypt_sign':
+ return 1;
- case 'elgamal':
- return 2;
+ case 'elgamal':
+ return 2;
- default:
- throw new Error("Invalid algorithm.");
- }
- })(this.publicKeyAlgorithm);
-
- this.encrypted = [];
-
- for (var j = 0; j < integerCount; j++) {
- var mpi = new type_mpi();
- i += mpi.read(bytes.substr(i));
- this.encrypted.push(mpi);
+ default:
+ throw new Error("Invalid algorithm.");
}
- };
+ })(this.publicKeyAlgorithm);
- /**
- * Create a string representation of a tag 1 packet
- *
- * @param {String} publicKeyId
- * The public key id corresponding to publicMPIs key as string
- * @param {Array<module:type/mpi>} publicMPIs
- * Multiprecision integer objects describing the public key
- * @param {Integer} pubalgo
- * The corresponding public key algorithm // See RFC4880 9.1
- * @param {Integer} symmalgo
- * The symmetric cipher algorithm used to encrypt the data
- * within an encrypteddatapacket or encryptedintegrity-
- * protecteddatapacket
- * following this packet //See RFC4880 9.2
- * @param {String} sessionkey
- * A string of randombytes representing the session key
- * @return {String} The string representation
- */
- this.write = function () {
-
- var result = String.fromCharCode(this.version);
- result += this.publicKeyId.write();
- result += String.fromCharCode(
- enums.write(enums.publicKey, this.publicKeyAlgorithm));
-
- for (var i = 0; i < this.encrypted.length; i++) {
- result += this.encrypted[i].write();
- }
-
- return result;
- };
-
- this.encrypt = function (key) {
- var data = String.fromCharCode(
- enums.write(enums.symmetric, this.sessionKeyAlgorithm));
-
- data += this.sessionKey;
- var checksum = util.calc_checksum(this.sessionKey);
- data += util.writeNumber(checksum, 2);
+ this.encrypted = [];
+ for (var j = 0; j < integerCount; j++) {
var mpi = new type_mpi();
- mpi.fromBytes(crypto.pkcs1.eme.encode(
- data,
- key.mpi[0].byteLength()));
+ i += mpi.read(bytes.substr(i));
+ this.encrypted.push(mpi);
+ }
+};
- this.encrypted = crypto.publicKeyEncrypt(
- this.publicKeyAlgorithm,
- key.mpi,
- mpi);
- };
+/**
+ * Create a string representation of a tag 1 packet
+ *
+ * @param {String} publicKeyId
+ * The public key id corresponding to publicMPIs key as string
+ * @param {Array<module:type/mpi>} publicMPIs
+ * Multiprecision integer objects describing the public key
+ * @param {module:enums.publicKey} pubalgo
+ * The corresponding public key algorithm // See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880 9.1}
+ * @param {module:enums.symmetric} symmalgo
+ * The symmetric cipher algorithm used to encrypt the data
+ * within an encrypteddatapacket or encryptedintegrity-
+ * protecteddatapacket
+ * following this packet //See {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880 9.2}
+ * @param {String} sessionkey
+ * A string of randombytes representing the session key
+ * @return {String} The string representation
+ */
+PublicKeyEncryptedSessionKey.prototype.write = function () {
- /**
- * Decrypts the session key (only for public key encrypted session key
- * packets (tag 1)
- *
- * @param {module:packet/secret_key} key
- * Private key with secMPIs unlocked
- * @return {String} The unencrypted session key
- */
- this.decrypt = function (key) {
- var result = crypto.publicKeyDecrypt(
- this.publicKeyAlgorithm,
- key.mpi,
- this.encrypted).toBytes();
+ var result = String.fromCharCode(this.version);
+ result += this.publicKeyId.write();
+ result += String.fromCharCode(
+ enums.write(enums.publicKey, this.publicKeyAlgorithm));
- var checksum = util.readNumber(result.substr(result.length - 2));
+ for (var i = 0; i < this.encrypted.length; i++) {
+ result += this.encrypted[i].write();
+ }
- var decoded = crypto.pkcs1.eme.decode(
- result,
- key.mpi[0].byteLength());
+ return result;
+};
- key = decoded.substring(1, decoded.length - 2);
+PublicKeyEncryptedSessionKey.prototype.encrypt = function (key) {
+ var data = String.fromCharCode(
+ enums.write(enums.symmetric, this.sessionKeyAlgorithm));
- if (checksum != util.calc_checksum(key)) {
- throw new Error('Checksum mismatch');
- } else {
- this.sessionKey = key;
- this.sessionKeyAlgorithm =
- enums.read(enums.symmetric, decoded.charCodeAt(0));
- }
- };
+ data += this.sessionKey;
+ var checksum = util.calc_checksum(this.sessionKey);
+ data += util.writeNumber(checksum, 2);
+
+ var mpi = new type_mpi();
+ mpi.fromBytes(crypto.pkcs1.eme.encode(
+ data,
+ key.mpi[0].byteLength()));
+
+ this.encrypted = crypto.publicKeyEncrypt(
+ this.publicKeyAlgorithm,
+ key.mpi,
+ mpi);
+};
+
+/**
+ * Decrypts the session key (only for public key encrypted session key
+ * packets (tag 1)
+ *
+ * @param {module:packet/secret_key} key
+ * Private key with secMPIs unlocked
+ * @return {String} The unencrypted session key
+ */
+PublicKeyEncryptedSessionKey.prototype.decrypt = function (key) {
+ var result = crypto.publicKeyDecrypt(
+ this.publicKeyAlgorithm,
+ key.mpi,
+ this.encrypted).toBytes();
+
+ var checksum = util.readNumber(result.substr(result.length - 2));
+
+ var decoded = crypto.pkcs1.eme.decode(
+ result,
+ key.mpi[0].byteLength());
+
+ key = decoded.substring(1, decoded.length - 2);
+
+ if (checksum != util.calc_checksum(key)) {
+ throw new Error('Checksum mismatch');
+ } else {
+ this.sessionKey = key;
+ this.sessionKeyAlgorithm =
+ enums.read(enums.symmetric, decoded.charCodeAt(0));
+ }
};
@@ -217,13 +219,13 @@ module.exports = function public_key_encrypted_session_key() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/public_subkey-PublicSubkey.html b/doc/public_subkey-PublicSubkey.html
new file mode 100644
index 00000000..1273dc26
--- /dev/null
+++ b/doc/public_subkey-PublicSubkey.html
@@ -0,0 +1,154 @@
+
+
+
+
+ JSDoc: Class: PublicSubkey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: PublicSubkey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new PublicSubkey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Extends
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/public_subkey.html b/doc/public_subkey.html
index 102818f5..5c24e600 100644
--- a/doc/public_subkey.html
+++ b/doc/public_subkey.html
@@ -35,72 +35,6 @@
-
-
-
- new (require("packet/public_subkey"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -157,899 +91,19 @@
-
-
-
-
-
Members
+
Classes
-
-
-
-
-
-
-
-
-
- Public key algorithm
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- created :Date
-
-
-
-
-
-
- Key creation date.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A list of multiprecision integers
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ PublicSubkey
+
-
Methods
-
-
-
-
- getFingerprint() → {String}
-
-
-
- Calculates the fingerprint of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string containing the fingerprint
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getKeyId() → {String}
-
-
-
-
-
-
-
- Calculates the key id of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A 8 byte key id
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(input) → {Object}
-
-
-
-
-
-
-
- Internal Parser for public keys as specified in RFC 4880 section
-5.5.2 Public-Key Packet Formats
-called by read_tag<num>
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Input string to read the packet from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- This object with attributes set by the parser
-
-
-
-
-
-
- Type
-
-
-
-Object
-
-
-
-
-
-
-
-
-
-
-
-
-
- readPublicKey()
-
-
-
-
-
-
-
- Alias of read()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {Object}
-
-
-
-
-
-
-
- Same as write_private_key, but has less information because of
-public key.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- {body: [string]OpenPGP packet body contents,
-header: [string] OpenPGP packet header, string: [string] header+body}
-
-
-
-
-
-
- Type
-
-
-
-Object
-
-
-
-
-
-
-
-
-
-
-
-
-
- writeOld()
-
-
-
-
-
-
-
- Write an old version packet - it's used by some of the internal routines.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- writePublicKey()
-
-
-
-
-
-
-
- Alias of write()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1064,13 +118,13 @@ header: [string] OpenPGP packet header, string: [string] header+body}
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/public_subkey.js.html b/doc/public_subkey.js.html
index d62cf500..56ef48a7 100644
--- a/doc/public_subkey.js.html
+++ b/doc/public_subkey.js.html
@@ -47,15 +47,20 @@
* @module packet/public_subkey
*/
+module.exports = PublicSubkey;
+
var publicKey = require('./public_key.js');
/**
* @constructor
* @extends module:packet/public_key
*/
-module.exports = function public_subkey() {
+function PublicSubkey() {
publicKey.call(this);
};
+
+PublicSubkey.prototype = new publicKey();
+PublicSubkey.prototype.constructor = PublicSubkey;
@@ -66,13 +71,13 @@ module.exports = function public_subkey() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/random.html b/doc/random.html
index 2ba5ce58..98c76d80 100644
--- a/doc/random.html
+++ b/doc/random.html
@@ -717,13 +717,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/random.js.html b/doc/random.js.html
index dc5da84d..c67581c7 100644
--- a/doc/random.js.html
+++ b/doc/random.js.html
@@ -144,13 +144,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/ripe-md.html b/doc/ripe-md.html
index 3daeb852..bd032176 100644
--- a/doc/ripe-md.html
+++ b/doc/ripe-md.html
@@ -105,13 +105,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/ripe-md.js.html b/doc/ripe-md.js.html
index e5ada1b5..8a45f251 100644
--- a/doc/ripe-md.js.html
+++ b/doc/ripe-md.js.html
@@ -332,13 +332,13 @@ module.exports = RMDstring;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/rsa.html b/doc/rsa.html
index 9651e799..0cadecd2 100644
--- a/doc/rsa.html
+++ b/doc/rsa.html
@@ -115,13 +115,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/rsa.js.html b/doc/rsa.js.html
index ac4254b8..2d540980 100644
--- a/doc/rsa.js.html
+++ b/doc/rsa.js.html
@@ -187,13 +187,13 @@ module.exports = RSA;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/s2k-S2K.html b/doc/s2k-S2K.html
new file mode 100644
index 00000000..a0f3d20c
--- /dev/null
+++ b/doc/s2k-S2K.html
@@ -0,0 +1,711 @@
+
+
+
+
+ JSDoc: Class: S2K
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: S2K
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new S2K()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+
+
+
+
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ salt :String
+
+
+
+
+
+
+ Eight bytes of salt in a binary string.
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ produce_key(passphrase) → {String}
+
+
+
+
+
+
+
+ Produces a key using the specified passphrase and the defined
+hashAlgorithm
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ passphrase
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Passphrase containing user input
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Produced key with a length corresponding to
+hashAlgorithm hash length
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+ read(input) → {Integer}
+
+
+
+
+
+
+
+ Parsing function for a string-to-key specifier (
RFC 4880 3.7 ).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of string-to-key specifier
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Actual length of the object
+
+
+
+
+
+
+ Type
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ writes an s2k hash based on the inputs.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Produced key of hashAlgorithm hash length
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/s2k.html b/doc/s2k.html
index 7aa006d5..5bc6f166 100644
--- a/doc/s2k.html
+++ b/doc/s2k.html
@@ -35,8 +35,10 @@
+
+
-
Implementation of the String-to-key specifier (RFC4880 3.7)
+
Implementation of the String-to-key specifier (
RFC4880 3.7 )
String-to-key (S2K) specifiers are used to convert passphrase strings
into symmetric-key encryption/decryption keys. They are used in two
@@ -45,74 +47,6 @@ private keyring, and to convert passphrases to encryption keys for
symmetrically encrypted messages.
-
- new (require("type/s2k"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -169,575 +103,19 @@ symmetrically encrypted messages.
-
-
-
-
-
Members
+
Classes
-
-
-
-
-
-
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- salt :String
-
-
-
-
-
-
- Eight bytes of salt in a binary string.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ S2K
+
-
Methods
-
-
-
-
- produce_key(passphrase) → {String}
-
-
-
- Produces a key using the specified passphrase and the defined
-hashAlgorithm
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- passphrase
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Passphrase containing user input
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Produced key with a length corresponding to
-hashAlgorithm hash length
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(input) → {Integer}
-
-
-
-
-
-
-
- Parsing function for a string-to-key specifier (RFC 4880 3.7).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of string-to-key specifier
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Actual length of the object
-
-
-
-
-
-
- Type
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- writes an s2k hash based on the inputs.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Produced key of hashAlgorithm hash length
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -752,13 +130,13 @@ hashAlgorithm hash length
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
diff --git a/doc/s2k.js.html b/doc/s2k.js.html
index 9a0711e4..aa23705d 100644
--- a/doc/s2k.js.html
+++ b/doc/s2k.js.html
@@ -43,7 +43,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
- * Implementation of the String-to-key specifier (RFC4880 3.7)<br/>
+ * Implementation of the String-to-key specifier ({@link http://tools.ietf.org/html/rfc4880#section-3.7|RFC4880 3.7})<br/>
* <br/>
* String-to-key (S2K) specifiers are used to convert passphrase strings
* into symmetric-key encryption/decryption keys. They are used in two
@@ -56,6 +56,8 @@
* @module type/s2k
*/
+module.exports = S2K;
+
var enums = require('../enums.js'),
util = require('../util'),
crypto = require('../crypto');
@@ -63,7 +65,7 @@ var enums = require('../enums.js'),
/**
* @constructor
*/
-module.exports = function s2k() {
+function S2K() {
/** @type {module:enums.hash} */
this.algorithm = 'sha256';
/** @type {module:enums.s2k} */
@@ -73,136 +75,135 @@ module.exports = function s2k() {
* @type {String}
*/
this.salt = crypto.random.getRandomBytes(8);
+}
-
+S2K.prototype.get_count = function () {
// Exponent bias, defined in RFC4880
var expbias = 6;
- this.get_count = function () {
- return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
- };
+ return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
+};
- /**
- * Parsing function for a string-to-key specifier (RFC 4880 3.7).
- * @param {String} input Payload of string-to-key specifier
- * @return {Integer} Actual length of the object
- */
- 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++));
+/**
+ * Parsing function for a string-to-key specifier ({@link http://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
+ * @param {String} input Payload of string-to-key specifier
+ * @return {Integer} Actual length of the object
+ */
+S2K.prototype.read = function (bytes) {
+ var i = 0;
+ this.type = enums.read(enums.s2k, bytes.charCodeAt(i++));
+ this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++));
- switch (this.type) {
- case 'simple':
- break;
+ switch (this.type) {
+ case 'simple':
+ break;
- case 'salted':
- this.salt = bytes.substr(i, 8);
- i += 8;
- break;
+ case 'salted':
+ this.salt = bytes.substr(i, 8);
+ i += 8;
+ break;
- case 'iterated':
- this.salt = bytes.substr(i, 8);
- i += 8;
+ case 'iterated':
+ this.salt = bytes.substr(i, 8);
+ i += 8;
- // Octet 10: count, a one-octet, coded value
- this.c = bytes.charCodeAt(i++);
- break;
+ // Octet 10: count, a one-octet, coded value
+ this.c = bytes.charCodeAt(i++);
+ break;
- case 'gnu':
- if (bytes.substr(i, 3) == "GNU") {
- i += 3; // GNU
- var gnuExtType = 1000 + bytes.charCodeAt(i++);
- if (gnuExtType == 1001) {
- this.type = gnuExtType;
- // GnuPG extension mode 1001 -- don't write secret key at all
- } else {
- throw new Error("Unknown s2k gnu protection mode.");
- }
+ case 'gnu':
+ if (bytes.substr(i, 3) == "GNU") {
+ i += 3; // GNU
+ var gnuExtType = 1000 + bytes.charCodeAt(i++);
+ if (gnuExtType == 1001) {
+ this.type = gnuExtType;
+ // GnuPG extension mode 1001 -- don't write secret key at all
} else {
- throw new Error("Unknown s2k type.");
+ throw new Error("Unknown s2k gnu protection mode.");
}
- break;
-
- default:
+ } else {
throw new Error("Unknown s2k type.");
- }
-
- return i;
- };
-
-
- /**
- * writes an s2k hash based on the inputs.
- * @return {String} Produced key of hashAlgorithm hash length
- */
- this.write = function () {
- var bytes = String.fromCharCode(enums.write(enums.s2k, this.type));
- bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm));
-
- switch (this.type) {
- case 'simple':
- break;
- case 'salted':
- bytes += this.salt;
- break;
- case 'iterated':
- bytes += this.salt;
- bytes += String.fromCharCode(this.c);
- break;
- }
-
- return bytes;
- };
-
- /**
- * Produces a key using the specified passphrase and the defined
- * hashAlgorithm
- * @param {String} passphrase Passphrase containing user input
- * @return {String} Produced key with a length corresponding to
- * hashAlgorithm hash length
- */
- this.produce_key = function (passphrase, numBytes) {
- passphrase = util.encode_utf8(passphrase);
-
- function round(prefix, s2k) {
- var algorithm = enums.write(enums.hash, s2k.algorithm);
-
- switch (s2k.type) {
- case 'simple':
- return crypto.hash.digest(algorithm, prefix + passphrase);
-
- case 'salted':
- return crypto.hash.digest(algorithm,
- prefix + s2k.salt + passphrase);
-
- case 'iterated':
- var isp = [],
- count = s2k.get_count();
- data = s2k.salt + passphrase;
-
- while (isp.length * data.length < count)
- isp.push(data);
-
- isp = isp.join('');
-
- if (isp.length > count)
- isp = isp.substr(0, count);
-
- return crypto.hash.digest(algorithm, prefix + isp);
}
+ break;
+
+ default:
+ throw new Error("Unknown s2k type.");
+ }
+
+ return i;
+};
+
+
+/**
+ * writes an s2k hash based on the inputs.
+ * @return {String} Produced key of hashAlgorithm hash length
+ */
+S2K.prototype.write = function () {
+ var bytes = String.fromCharCode(enums.write(enums.s2k, this.type));
+ bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm));
+
+ switch (this.type) {
+ case 'simple':
+ break;
+ case 'salted':
+ bytes += this.salt;
+ break;
+ case 'iterated':
+ bytes += this.salt;
+ bytes += String.fromCharCode(this.c);
+ break;
+ }
+
+ return bytes;
+};
+
+/**
+ * Produces a key using the specified passphrase and the defined
+ * hashAlgorithm
+ * @param {String} passphrase Passphrase containing user input
+ * @return {String} Produced key with a length corresponding to
+ * hashAlgorithm hash length
+ */
+S2K.prototype.produce_key = function (passphrase, numBytes) {
+ passphrase = util.encode_utf8(passphrase);
+
+ function round(prefix, s2k) {
+ var algorithm = enums.write(enums.hash, s2k.algorithm);
+
+ switch (s2k.type) {
+ case 'simple':
+ return crypto.hash.digest(algorithm, prefix + passphrase);
+
+ case 'salted':
+ return crypto.hash.digest(algorithm,
+ prefix + s2k.salt + passphrase);
+
+ case 'iterated':
+ var isp = [],
+ count = s2k.get_count();
+ data = s2k.salt + passphrase;
+
+ while (isp.length * data.length < count)
+ isp.push(data);
+
+ isp = isp.join('');
+
+ if (isp.length > count)
+ isp = isp.substr(0, count);
+
+ return crypto.hash.digest(algorithm, prefix + isp);
}
+ }
- var result = '',
- prefix = '';
+ var result = '',
+ prefix = '';
- while (result.length <= numBytes) {
- result += round(prefix, this);
- prefix += String.fromCharCode(0);
- }
+ while (result.length <= numBytes) {
+ result += round(prefix, this);
+ prefix += String.fromCharCode(0);
+ }
- return result.substr(0, numBytes);
- };
+ return result.substr(0, numBytes);
};
@@ -214,13 +215,13 @@ module.exports = function s2k() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/secret_key-SecretKey.html b/doc/secret_key-SecretKey.html
new file mode 100644
index 00000000..3c8ba075
--- /dev/null
+++ b/doc/secret_key-SecretKey.html
@@ -0,0 +1,625 @@
+
+
+
+
+ JSDoc: Class: SecretKey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: SecretKey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new SecretKey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Extends
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ decrypt(str_passphrase) → {Boolean}
+
+
+
+
+
+
+
+ Decrypts the private key MPIs which are needed to use the key.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ str_passphrase
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ The passphrase for this private key
+as string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ True if the passphrase was correct or MPI already
+ decrypted; false if not
+
+
+
+
+
+
+ Type
+
+
+
+Boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+ encrypt(passphrase)
+
+
+
+
+
+
+
+ Encrypt the payload. By default, we use aes256 and iterated, salted string
+to key specifier
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ passphrase
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ read(bytes)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ bytes
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Input string to read the packet from
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ Creates an OpenPGP key packet for the given key.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ A string of bytes containing the secret key OpenPGP packet
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/secret_key.html b/doc/secret_key.html
index afbbc2a6..ce29502f 100644
--- a/doc/secret_key.html
+++ b/doc/secret_key.html
@@ -35,83 +35,17 @@
+
+
Implementation of the Key Material Packet (Tag 5,6,7,14)
-RFC4480 5.5:
+
RFC4480 5.5 :
A key material packet contains all the information about a public or
private key. There are four variants of this packet type, and two
major versions. Consequently, this section is complex.
-
- new (require("packet/secret_key"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -174,1122 +108,19 @@ major versions. Consequently, this section is complex.
-
-
-
-
- Members
+ Classes
-
-
-
-
-
-
-
-
-
- Public key algorithm
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- created :Date
-
-
-
-
-
-
- Key creation date.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A list of multiprecision integers
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ SecretKey
+
- Methods
-
-
-
-
- decrypt(str_passphrase) → {Boolean}
-
-
-
- Decrypts the private key MPIs which are needed to use the key.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- str_passphrase
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The passphrase for this private key
-as string
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- True if the passphrase was correct or MPI already
- decrypted; false if not
-
-
-
-
-
-
- Type
-
-
-
-Boolean
-
-
-
-
-
-
-
-
-
-
-
-
-
- encrypt(passphrase)
-
-
-
-
-
-
-
- Encrypt the payload. By default, we use aes256 and iterated, salted string
-to key specifier
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- passphrase
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- getFingerprint() → {String}
-
-
-
-
-
-
-
- Calculates the fingerprint of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string containing the fingerprint
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getKeyId() → {String}
-
-
-
-
-
-
-
- Calculates the key id of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A 8 byte key id
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(bytes)
-
-
-
-
-
-
-
- Internal parser for private keys as specified in RFC 4880 section 5.5.3
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Input string to read the packet from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- readPublicKey()
-
-
-
-
-
-
-
- Alias of read()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Creates an OpenPGP key packet for the given key.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string of bytes containing the secret key OpenPGP packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- writeOld()
-
-
-
-
-
-
-
- Write an old version packet - it's used by some of the internal routines.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- writePublicKey()
-
-
-
-
-
-
-
- Alias of write()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1304,13 +135,13 @@ to key specifier
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/secret_key.js.html b/doc/secret_key.js.html
index 671da250..666768b1 100644
--- a/doc/secret_key.js.html
+++ b/doc/secret_key.js.html
@@ -45,7 +45,7 @@
/**
* Implementation of the Key Material Packet (Tag 5,6,7,14)<br/>
* <br/>
- * RFC4480 5.5:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.5|RFC4480 5.5}:
* A key material packet contains all the information about a public or
* private key. There are four variants of this packet type, and two
* major versions. Consequently, this section is complex.
@@ -58,6 +58,8 @@
* @module packet/secret_key
*/
+module.exports = SecretKey;
+
var publicKey = require('./public_key.js'),
enums = require('../enums.js'),
util = require('../util'),
@@ -69,228 +71,227 @@ var publicKey = require('./public_key.js'),
* @constructor
* @extends module:packet/public_key
*/
-module.exports = function secret_key() {
+function SecretKey() {
publicKey.call(this);
// encrypted secret-key data
this.encrypted = null;
// indicator if secret-key data is available in decrypted form
this.isDecrypted = false;
+}
+SecretKey.prototype = new publicKey();
+SecretKey.prototype.constructor = SecretKey;
- function get_hash_len(hash) {
- if (hash == 'sha1')
- return 20;
- else
- return 2;
- }
-
- function get_hash_fn(hash) {
- if (hash == 'sha1')
- return crypto.hash.sha1;
- else
- return function(c) {
- return util.writeNumber(util.calc_checksum(c), 2);
- };
- }
-
- // Helper function
-
- function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) {
- var hashlen = get_hash_len(hash_algorithm),
- hashfn = get_hash_fn(hash_algorithm);
-
- var hashtext = cleartext.substr(cleartext.length - hashlen);
- cleartext = cleartext.substr(0, cleartext.length - hashlen);
-
- var hash = hashfn(cleartext);
-
- if (hash != hashtext)
- return new Error("Hash mismatch.");
-
- var mpis = crypto.getPrivateMpiCount(algorithm);
-
- var j = 0;
- var mpi = [];
-
- for (var i = 0; i < mpis && j < cleartext.length; i++) {
- mpi[i] = new type_mpi();
- j += mpi[i].read(cleartext.substr(j));
- }
-
- return mpi;
- }
-
- function write_cleartext_mpi(hash_algorithm, algorithm, mpi) {
- var bytes = '';
- var discard = crypto.getPublicMpiCount(algorithm);
-
- for (var i = discard; i < mpi.length; i++) {
- bytes += mpi[i].write();
- }
-
-
- bytes += get_hash_fn(hash_algorithm)(bytes);
-
- return bytes;
- }
-
-
- // 5.5.3. Secret-Key Packet Formats
-
- /**
- * 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) {
- // - A Public-Key or Public-Subkey packet, as described above.
- var len = this.readPublicKey(bytes);
-
- bytes = bytes.substr(len);
-
-
- // - One octet indicating string-to-key usage conventions. Zero
- // indicates that the secret-key data is not encrypted. 255 or 254
- // indicates that a string-to-key specifier is being given. Any
- // other value is a symmetric-key encryption algorithm identifier.
- var isEncrypted = bytes.charCodeAt(0);
-
- if (isEncrypted) {
- this.encrypted = bytes;
- } else {
-
- // - Plain or encrypted multiprecision integers comprising the secret
- // key data. These algorithm-specific fields are as described
- // below.
- var parsedMPI = parse_cleartext_mpi('mod', bytes.substr(1), this.algorithm);
- if (parsedMPI instanceof Error)
- throw parsedMPI;
- this.mpi = this.mpi.concat(parsedMPI);
- this.isDecrypted = true;
- }
+function get_hash_len(hash) {
+ if (hash == 'sha1')
+ return 20;
+ else
+ return 2;
+}
+function get_hash_fn(hash) {
+ if (hash == 'sha1')
+ return crypto.hash.sha1;
+ else
+ return function(c) {
+ return util.writeNumber(util.calc_checksum(c), 2);
};
+}
- /** Creates an OpenPGP key packet for the given key.
- * @return {String} A string of bytes containing the secret key OpenPGP packet
- */
- this.write = function () {
- var bytes = this.writePublicKey();
+// Helper function
- if (!this.encrypted) {
- bytes += String.fromCharCode(0);
+function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) {
+ var hashlen = get_hash_len(hash_algorithm),
+ hashfn = get_hash_fn(hash_algorithm);
- bytes += write_cleartext_mpi('mod', this.algorithm, this.mpi);
- } else {
- bytes += this.encrypted;
- }
+ var hashtext = cleartext.substr(cleartext.length - hashlen);
+ cleartext = cleartext.substr(0, cleartext.length - hashlen);
- return bytes;
- };
+ var hash = hashfn(cleartext);
+ if (hash != hashtext)
+ return new Error("Hash mismatch.");
+ var mpis = crypto.getPrivateMpiCount(algorithm);
+ var j = 0;
+ var mpi = [];
- /** Encrypt the payload. By default, we use aes256 and iterated, salted string
- * to key specifier
- * @param {String} passphrase
- */
- this.encrypt = function (passphrase) {
-
- var s2k = new type_s2k(),
- symmetric = 'aes256',
- cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi),
- key = produceEncryptionKey(s2k, passphrase, symmetric),
- blockLen = crypto.cipher[symmetric].blockSize,
- iv = crypto.random.getRandomBytes(blockLen);
-
-
- this.encrypted = '';
- this.encrypted += String.fromCharCode(254);
- this.encrypted += String.fromCharCode(enums.write(enums.symmetric, symmetric));
- this.encrypted += s2k.write();
- this.encrypted += iv;
-
- this.encrypted += crypto.cfb.normalEncrypt(symmetric, key, cleartext, iv);
- };
-
- function produceEncryptionKey(s2k, passphrase, algorithm) {
- return s2k.produce_key(passphrase,
- crypto.cipher[algorithm].keySize);
+ for (var i = 0; i < mpis && j < cleartext.length; i++) {
+ mpi[i] = new type_mpi();
+ j += mpi[i].read(cleartext.substr(j));
}
- /**
- * Decrypts the private key MPIs which are needed to use the key.
- * @link module:packet/secret_key.isDecrypted should be
- * false otherwise a call to this function is not needed
- *
- * @param {String} str_passphrase The passphrase for this private key
- * as string
- * @return {Boolean} True if the passphrase was correct or MPI already
- * decrypted; false if not
- */
- this.decrypt = function (passphrase) {
- if (this.isDecrypted)
- return true;
+ return mpi;
+}
- var i = 0,
- symmetric,
- key;
+function write_cleartext_mpi(hash_algorithm, algorithm, mpi) {
+ var bytes = '';
+ var discard = crypto.getPublicMpiCount(algorithm);
- var s2k_usage = this.encrypted.charCodeAt(i++);
-
- // - [Optional] If string-to-key usage octet was 255 or 254, a one-
- // octet symmetric encryption algorithm.
- if (s2k_usage == 255 || s2k_usage == 254) {
- symmetric = this.encrypted.charCodeAt(i++);
- symmetric = enums.read(enums.symmetric, symmetric);
-
- // - [Optional] If string-to-key usage octet was 255 or 254, a
- // string-to-key specifier. The length of the string-to-key
- // specifier is implied by its type, as described above.
- var s2k = new type_s2k();
- i += s2k.read(this.encrypted.substr(i));
-
- key = produceEncryptionKey(s2k, passphrase, symmetric);
- } else {
- symmetric = s2k_usage;
- symmetric = enums.read(enums.symmetric, symmetric);
- key = crypto.hash.md5(passphrase);
- }
+ for (var i = discard; i < mpi.length; i++) {
+ bytes += mpi[i].write();
+ }
- // - [Optional] If secret data is encrypted (string-to-key usage octet
- // not zero), an Initial Vector (IV) of the same length as the
- // cipher's block size.
- var iv = this.encrypted.substr(i,
- crypto.cipher[symmetric].blockSize);
+ bytes += get_hash_fn(hash_algorithm)(bytes);
- i += iv.length;
+ return bytes;
+}
- var cleartext,
- ciphertext = this.encrypted.substr(i);
- cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv);
+// 5.5.3. Secret-Key Packet Formats
- var hash = s2k_usage == 254 ?
- 'sha1' :
- 'mod';
+/**
+ * Internal parser for private keys as specified in {@link http://tools.ietf.org/html/rfc4880#section-5.5.3|RFC 4880 section 5.5.3}
+ * @param {String} bytes Input string to read the packet from
+ */
+SecretKey.prototype.read = function (bytes) {
+ // - A Public-Key or Public-Subkey packet, as described above.
+ var len = this.readPublicKey(bytes);
- var parsedMPI = parse_cleartext_mpi(hash, cleartext, this.algorithm);
+ bytes = bytes.substr(len);
+
+
+ // - One octet indicating string-to-key usage conventions. Zero
+ // indicates that the secret-key data is not encrypted. 255 or 254
+ // indicates that a string-to-key specifier is being given. Any
+ // other value is a symmetric-key encryption algorithm identifier.
+ var isEncrypted = bytes.charCodeAt(0);
+
+ if (isEncrypted) {
+ this.encrypted = bytes;
+ } else {
+
+ // - Plain or encrypted multiprecision integers comprising the secret
+ // key data. These algorithm-specific fields are as described
+ // below.
+ var parsedMPI = parse_cleartext_mpi('mod', bytes.substr(1), this.algorithm);
if (parsedMPI instanceof Error)
- return false;
+ throw parsedMPI;
this.mpi = this.mpi.concat(parsedMPI);
this.isDecrypted = true;
- return true;
- };
-
- this.generate = function (bits) {
- this.mpi = crypto.generateMpi(this.algorithm, bits);
- this.isDecrypted = true;
- };
+ }
};
-module.exports.prototype = new publicKey();
+/** Creates an OpenPGP key packet for the given key.
+ * @return {String} A string of bytes containing the secret key OpenPGP packet
+ */
+SecretKey.prototype.write = function () {
+ var bytes = this.writePublicKey();
+
+ if (!this.encrypted) {
+ bytes += String.fromCharCode(0);
+
+ bytes += write_cleartext_mpi('mod', this.algorithm, this.mpi);
+ } else {
+ bytes += this.encrypted;
+ }
+
+ return bytes;
+};
+
+
+
+
+/** Encrypt the payload. By default, we use aes256 and iterated, salted string
+ * to key specifier
+ * @param {String} passphrase
+ */
+SecretKey.prototype.encrypt = function (passphrase) {
+
+ var s2k = new type_s2k(),
+ symmetric = 'aes256',
+ cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi),
+ key = produceEncryptionKey(s2k, passphrase, symmetric),
+ blockLen = crypto.cipher[symmetric].blockSize,
+ iv = crypto.random.getRandomBytes(blockLen);
+
+
+ this.encrypted = '';
+ this.encrypted += String.fromCharCode(254);
+ this.encrypted += String.fromCharCode(enums.write(enums.symmetric, symmetric));
+ this.encrypted += s2k.write();
+ this.encrypted += iv;
+
+ this.encrypted += crypto.cfb.normalEncrypt(symmetric, key, cleartext, iv);
+};
+
+function produceEncryptionKey(s2k, passphrase, algorithm) {
+ return s2k.produce_key(passphrase,
+ crypto.cipher[algorithm].keySize);
+}
+
+/**
+ * Decrypts the private key MPIs which are needed to use the key.
+ * @link module:packet/secret_key.isDecrypted should be
+ * false otherwise a call to this function is not needed
+ *
+ * @param {String} str_passphrase The passphrase for this private key
+ * as string
+ * @return {Boolean} True if the passphrase was correct or MPI already
+ * decrypted; false if not
+ */
+SecretKey.prototype.decrypt = function (passphrase) {
+ if (this.isDecrypted)
+ return true;
+
+ var i = 0,
+ symmetric,
+ key;
+
+ var s2k_usage = this.encrypted.charCodeAt(i++);
+
+ // - [Optional] If string-to-key usage octet was 255 or 254, a one-
+ // octet symmetric encryption algorithm.
+ if (s2k_usage == 255 || s2k_usage == 254) {
+ symmetric = this.encrypted.charCodeAt(i++);
+ symmetric = enums.read(enums.symmetric, symmetric);
+
+ // - [Optional] If string-to-key usage octet was 255 or 254, a
+ // string-to-key specifier. The length of the string-to-key
+ // specifier is implied by its type, as described above.
+ var s2k = new type_s2k();
+ i += s2k.read(this.encrypted.substr(i));
+
+ key = produceEncryptionKey(s2k, passphrase, symmetric);
+ } else {
+ symmetric = s2k_usage;
+ symmetric = enums.read(enums.symmetric, symmetric);
+ key = crypto.hash.md5(passphrase);
+ }
+
+
+ // - [Optional] If secret data is encrypted (string-to-key usage octet
+ // not zero), an Initial Vector (IV) of the same length as the
+ // cipher's block size.
+ var iv = this.encrypted.substr(i,
+ crypto.cipher[symmetric].blockSize);
+
+ i += iv.length;
+
+ var cleartext,
+ ciphertext = this.encrypted.substr(i);
+
+ cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv);
+
+ var hash = s2k_usage == 254 ?
+ 'sha1' :
+ 'mod';
+
+ var parsedMPI = parse_cleartext_mpi(hash, cleartext, this.algorithm);
+ if (parsedMPI instanceof Error)
+ return false;
+ this.mpi = this.mpi.concat(parsedMPI);
+ this.isDecrypted = true;
+ return true;
+};
+
+SecretKey.prototype.generate = function (bits) {
+ this.mpi = crypto.generateMpi(this.algorithm, bits);
+ this.isDecrypted = true;
+};
@@ -301,13 +302,13 @@ module.exports.prototype = new publicKey();
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/secret_subkey-SecretSubkey.html b/doc/secret_subkey-SecretSubkey.html
new file mode 100644
index 00000000..97fa32bf
--- /dev/null
+++ b/doc/secret_subkey-SecretSubkey.html
@@ -0,0 +1,154 @@
+
+
+
+
+ JSDoc: Class: SecretSubkey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: SecretSubkey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new SecretSubkey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Extends
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/secret_subkey.html b/doc/secret_subkey.html
index 8e38f799..84682c88 100644
--- a/doc/secret_subkey.html
+++ b/doc/secret_subkey.html
@@ -35,72 +35,6 @@
-
-
-
- new (require("packet/secret_subkey"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -157,1142 +91,19 @@
-
-
-
-
-
Members
+
Classes
-
-
-
-
-
-
-
-
-
- Public key algorithm
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- created :Date
-
-
-
-
-
-
- Key creation date.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- A list of multiprecision integers
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ SecretSubkey
+
-
Methods
-
-
-
-
- decrypt(str_passphrase) → {Boolean}
-
-
-
- Decrypts the private key MPIs which are needed to use the key.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- str_passphrase
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The passphrase for this private key
-as string
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- True if the passphrase was correct or MPI already
- decrypted; false if not
-
-
-
-
-
-
- Type
-
-
-
-Boolean
-
-
-
-
-
-
-
-
-
-
-
-
-
- encrypt(passphrase)
-
-
-
-
-
-
-
- Encrypt the payload. By default, we use aes256 and iterated, salted string
-to key specifier
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- passphrase
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- getFingerprint() → {String}
-
-
-
-
-
-
-
- Calculates the fingerprint of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string containing the fingerprint
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- getKeyId() → {String}
-
-
-
-
-
-
-
- Calculates the key id of the key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A 8 byte key id
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- read(bytes)
-
-
-
-
-
-
-
- Internal parser for private keys as specified in RFC 4880 section 5.5.3
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Input string to read the packet from
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- readPublicKey()
-
-
-
-
-
-
-
- Alias of read()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Creates an OpenPGP key packet for the given key.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- A string of bytes containing the secret key OpenPGP packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
- writeOld()
-
-
-
-
-
-
-
- Write an old version packet - it's used by some of the internal routines.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- writePublicKey()
-
-
-
-
-
-
-
- Alias of write()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Inherited From:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
- See:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1307,13 +118,13 @@ to key specifier
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:32 GMT+0100 (MEZ)
diff --git a/doc/secret_subkey.js.html b/doc/secret_subkey.js.html
index b727412f..84e91490 100644
--- a/doc/secret_subkey.js.html
+++ b/doc/secret_subkey.js.html
@@ -47,15 +47,20 @@
* @module packet/secret_subkey
*/
+module.exports = SecretSubkey;
+
var secretKey = require('./secret_key.js');
/**
* @constructor
* @extends module:packet/secret_key
*/
-module.exports = function secret_subkey() {
+function SecretSubkey() {
secretKey.call(this);
-};
+}
+
+SecretSubkey.prototype = new secretKey();
+SecretSubkey.prototype.constructor = SecretSubkey;
@@ -66,13 +71,13 @@ module.exports = function secret_subkey() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/sha.html b/doc/sha.html
index ace15ae3..b788a2e4 100644
--- a/doc/sha.html
+++ b/doc/sha.html
@@ -454,13 +454,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/sha.js.html b/doc/sha.js.html
index 16331fa5..dbb79b9f 100644
--- a/doc/sha.js.html
+++ b/doc/sha.js.html
@@ -1160,13 +1160,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/signature-Signature.html b/doc/signature-Signature.html
new file mode 100644
index 00000000..1c6b7b38
--- /dev/null
+++ b/doc/signature-Signature.html
@@ -0,0 +1,827 @@
+
+
+
+
+ JSDoc: Class: Signature
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Signature
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Signature()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ isExpired() → {Boolean}
+
+
+
+
+
+
+
+ Verifies signature expiration date
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ true if expired
+
+
+
+
+
+
+ Type
+
+
+
+Boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ parsing function for a signature packet (tag 2).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ bytes
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ payload of a tag 2 packet
+
+
+
+
+
+
+ position
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ position to start reading from the bytes string
+
+
+
+
+
+
+ len
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ length of the packet or the remaining length of bytes at position
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/signature
+
+
+
+
+
+
+
+
+
+
+
+
+
+ sign(key, data)
+
+
+
+
+
+
+
+ Signs provided data. This needs to be done prior to serialization.
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+module:packet/secret_key
+
+
+
+
+
+
+
+
+
+ private key used to sign the message.
+
+
+
+
+
+
+ data
+
+
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+ Contains packets to be signed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ verify(data, key) → {boolean}
+
+
+
+
+
+
+
+ verifys the signature packet. Note: not signature types are implemented
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ data
+
+
+
+
+
+String
+|
+
+Object
+
+
+
+
+
+
+
+
+
+ data which on the signature applies
+
+
+
+
+
+
+ key
+
+
+
+
+
+module:packet/public_subkey
+|
+
+module:packet/public_key
+
+
+
+
+
+
+
+
+
+ the public key to verify the signature
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ True if message is verified, else false.
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write_all_sub_packets() → {String}
+
+
+
+
+
+
+
+ Creates string of bytes with all subpacket data
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ a string-representation of a all subpacket data
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/signature.html b/doc/signature.html
index 1ae8d1be..cda83d6c 100644
--- a/doc/signature.html
+++ b/doc/signature.html
@@ -154,7 +154,7 @@
-Integer
+module:enums.hash
@@ -164,7 +164,7 @@
- hash Algorithm to use (See RFC4880 9.4)
+ hash Algorithm to use (See RFC 4880 9.4 )
@@ -177,7 +177,7 @@
-Integer
+module:enums.publicKey
@@ -187,7 +187,7 @@
- Asymmetric cipher algorithm to use (See RFC4880 9.1)
+ Asymmetric cipher algorithm to use (See RFC 4880 9.1 )
@@ -379,7 +379,7 @@ integers which is used to sign the data
-Integer
+module:enums.publicKey
@@ -402,7 +402,7 @@ integers which is used to sign the data
-Integer
+module:enums.hash
@@ -575,13 +575,13 @@ integers which is used to sign the data
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:51 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:30 GMT+0100 (MEZ)
diff --git a/doc/signature.js.html b/doc/signature.js.html
index 4fe49a1d..032d26bf 100644
--- a/doc/signature.js.html
+++ b/doc/signature.js.html
@@ -38,8 +38,8 @@ var publicKey = require('./public_key'),
module.exports = {
/**
*
- * @param {Integer} algo public Key algorithm
- * @param {Integer} hash_algo Hash algorithm
+ * @param {module:enums.publicKey} algo public Key algorithm
+ * @param {module:enums.hash} hash_algo Hash algorithm
* @param {Array<module:type/mpi>} msg_MPIs Signature multiprecision integers
* @param {Array<module:type/mpi>} publickey_MPIs Public key multiprecision integers
* @param {String} data Data on where the signature was computed on.
@@ -89,8 +89,8 @@ module.exports = {
/**
* Create a signature on data using the specified algorithm
- * @param {Integer} hash_algo hash Algorithm to use (See RFC4880 9.4)
- * @param {Integer} algo Asymmetric cipher algorithm to use (See RFC4880 9.1)
+ * @param {module:enums.hash} hash_algo hash Algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
+ * @param {module:enums.publicKey} algo Asymmetric cipher algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array<module:type/mpi>} publicMPIs Public key multiprecision integers
* of the private key
* @param {Array<module:type/mpi>} secretMPIs Private key multiprecision
@@ -148,13 +148,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/signature.js_.html b/doc/signature.js_.html
index c45977c7..84f95441 100644
--- a/doc/signature.js_.html
+++ b/doc/signature.js_.html
@@ -45,7 +45,7 @@
/**
* Implementation of the Signature Packet (Tag 2)<br/>
* <br/>
- * RFC4480 5.2:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.2|RFC4480 5.2}:
* A Signature packet describes a binding between some public key and
* some data. The most common signatures are a signature of a file or a
* block of text, and a signature that is a certification of a User ID.
@@ -58,6 +58,8 @@
* @module packet/signature
*/
+module.exports = Signature;
+
var util = require('../util'),
packet = require('./packet.js'),
enums = require('../enums.js'),
@@ -68,7 +70,7 @@ var util = require('../util'),
/**
* @constructor
*/
-module.exports = function signature() {
+function Signature() {
this.version = 4;
this.signatureType = null;
@@ -112,558 +114,557 @@ module.exports = function signature() {
this.embeddedSignature = null;
this.verified = false;
+}
- /**
- * parsing function for a signature packet (tag 2).
- * @param {String} bytes payload of a tag 2 packet
- * @param {Integer} position position to start reading from the bytes string
- * @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) {
- var i = 0;
+/**
+ * parsing function for a signature packet (tag 2).
+ * @param {String} bytes payload of a tag 2 packet
+ * @param {Integer} position position to start reading from the bytes string
+ * @param {Integer} len length of the packet or the remaining length of bytes at position
+ * @return {module:packet/signature} object representation
+ */
+Signature.prototype.read = function (bytes) {
+ var i = 0;
- this.version = bytes.charCodeAt(i++);
- // switch on version (3 and 4)
- switch (this.version) {
- case 3:
- // One-octet length of following hashed material. MUST be 5.
- if (bytes.charCodeAt(i++) != 5)
- util.print_debug("packet/signature.js\n" +
- 'invalid One-octet length of following hashed material.' +
- 'MUST be 5. @:' + (i - 1));
+ this.version = bytes.charCodeAt(i++);
+ // switch on version (3 and 4)
+ switch (this.version) {
+ case 3:
+ // One-octet length of following hashed material. MUST be 5.
+ if (bytes.charCodeAt(i++) != 5)
+ util.print_debug("packet/signature.js\n" +
+ 'invalid One-octet length of following hashed material.' +
+ 'MUST be 5. @:' + (i - 1));
- var sigpos = i;
- // One-octet signature type.
- this.signatureType = bytes.charCodeAt(i++);
+ var sigpos = i;
+ // One-octet signature type.
+ this.signatureType = bytes.charCodeAt(i++);
- // Four-octet creation time.
- this.created = util.readDate(bytes.substr(i, 4));
- i += 4;
+ // Four-octet creation time.
+ this.created = util.readDate(bytes.substr(i, 4));
+ i += 4;
- // storing data appended to data which gets verified
- this.signatureData = bytes.substring(sigpos, i);
+ // storing data appended to data which gets verified
+ this.signatureData = bytes.substring(sigpos, i);
- // Eight-octet Key ID of signer.
- this.issuerKeyId.read(bytes.substring(i, i + 8));
- i += 8;
+ // Eight-octet Key ID of signer.
+ this.issuerKeyId.read(bytes.substring(i, i + 8));
+ i += 8;
- // One-octet public-key algorithm.
- this.publicKeyAlgorithm = bytes.charCodeAt(i++);
+ // One-octet public-key algorithm.
+ this.publicKeyAlgorithm = bytes.charCodeAt(i++);
- // One-octet hash algorithm.
- this.hashAlgorithm = bytes.charCodeAt(i++);
- break;
- case 4:
- this.signatureType = bytes.charCodeAt(i++);
- this.publicKeyAlgorithm = bytes.charCodeAt(i++);
- this.hashAlgorithm = bytes.charCodeAt(i++);
+ // One-octet hash algorithm.
+ this.hashAlgorithm = bytes.charCodeAt(i++);
+ break;
+ case 4:
+ this.signatureType = bytes.charCodeAt(i++);
+ this.publicKeyAlgorithm = bytes.charCodeAt(i++);
+ this.hashAlgorithm = bytes.charCodeAt(i++);
- function subpackets(bytes) {
- // Two-octet scalar octet count for following subpacket data.
- var subpacket_length = util.readNumber(
- bytes.substr(0, 2));
+ function subpackets(bytes) {
+ // Two-octet scalar octet count for following subpacket data.
+ var subpacket_length = util.readNumber(
+ bytes.substr(0, 2));
- var i = 2;
+ var i = 2;
- // subpacket data set (zero or more subpackets)
- var subpacked_read = 0;
- while (i < 2 + subpacket_length) {
+ // subpacket data set (zero or more subpackets)
+ var subpacked_read = 0;
+ while (i < 2 + subpacket_length) {
- var len = packet.readSimpleLength(bytes.substr(i));
- i += len.offset;
+ var len = packet.readSimpleLength(bytes.substr(i));
+ i += len.offset;
- this.read_sub_packet(bytes.substr(i, len.len));
+ this.read_sub_packet(bytes.substr(i, len.len));
- i += len.len;
- }
-
- return i;
+ i += len.len;
}
- // hashed subpackets
- i += subpackets.call(this, bytes.substr(i), true);
-
- // A V4 signature hashes the packet body
- // starting from its first field, the version number, through the end
- // of the hashed subpacket data. Thus, the fields hashed are the
- // signature version, the signature type, the public-key algorithm, the
- // hash algorithm, the hashed subpacket length, and the hashed
- // subpacket body.
- this.signatureData = bytes.substr(0, i);
-
- // unhashed subpackets
- i += subpackets.call(this, bytes.substr(i), false);
-
- break;
- default:
- throw new Error('Version ' + version + ' of the signature is unsupported.');
- }
-
- // Two-octet field holding left 16 bits of signed hash value.
- this.signedHashValue = bytes.substr(i, 2);
- i += 2;
-
- this.signature = bytes.substr(i);
- };
-
- this.write = function () {
- return this.signatureData +
- util.writeNumber(0, 2) + // Number of unsigned subpackets.
- this.signedHashValue +
- this.signature;
- };
-
- /**
- * Signs provided data. This needs to be done prior to serialization.
- * @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) {
- var signatureType = enums.write(enums.signature, this.signatureType),
- publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm),
- hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm);
-
- var result = String.fromCharCode(4);
- result += String.fromCharCode(signatureType);
- result += String.fromCharCode(publicKeyAlgorithm);
- result += String.fromCharCode(hashAlgorithm);
-
- this.issuerKeyId = key.getKeyId();
-
- // Add hashed subpackets
- result += this.write_all_sub_packets();
-
- this.signatureData = result;
-
- var trailer = this.calculateTrailer();
-
- var toHash = this.toSign(signatureType, data) +
- this.signatureData + trailer;
-
- var hash = crypto.hash.digest(hashAlgorithm, toHash);
-
- this.signedHashValue = hash.substr(0, 2);
-
- this.signature = crypto.signature.sign(hashAlgorithm,
- publicKeyAlgorithm, key.mpi, toHash);
- };
-
- /**
- * Creates string of bytes with all subpacket data
- * @return {String} a string-representation of a all subpacket data
- */
- this.write_all_sub_packets = function () {
- var sub = enums.signatureSubpacket;
- var result = '';
- var bytes = '';
- if (this.created !== null) {
- result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
- }
- if (this.signatureExpirationTime !== null) {
- result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4));
- }
- if (this.exportable !== null) {
- result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
- }
- if (this.trustLevel !== null) {
- bytes = String.fromCharCode(this.trustLevel) + String.fromCharCode(this.trustAmount);
- result += write_sub_packet(sub.trust_signature, bytes);
- }
- if (this.regularExpression !== null) {
- result += write_sub_packet(sub.regular_expression, this.regularExpression);
- }
- if (this.revocable !== null) {
- result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
- }
- if (this.keyExpirationTime !== null) {
- result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4));
- }
- if (this.preferredSymmetricAlgorithms !== null) {
- bytes = util.bin2str(this.preferredSymmetricAlgorithms);
- result += write_sub_packet(sub.preferred_symmetric_algorithms, bytes);
- }
- if (this.revocationKeyClass !== null) {
- bytes = String.fromCharCode(this.revocationKeyClass);
- bytes += String.fromCharCode(this.revocationKeyAlgorithm);
- bytes += this.revocationKeyFingerprint;
- result += write_sub_packet(sub.revocation_key, bytes);
- }
- if (!this.issuerKeyId.isNull()) {
- result += write_sub_packet(sub.issuer, this.issuerKeyId.write());
- }
- if (this.notation !== null) {
- for (var name in this.notation) {
- if (this.notation.hasOwnProperty(name)) {
- var value = this.notation[name];
- bytes = String.fromCharCode(0x80);
- bytes += String.fromCharCode(0);
- bytes += String.fromCharCode(0);
- bytes += String.fromCharCode(0);
- // 2 octets of name length
- bytes += util.writeNumber(name.length, 2);
- // 2 octets of value length
- bytes += util.writeNumber(value.length, 2);
- bytes += name + value;
- result += write_sub_packet(sub.notation_data, bytes);
- }
+ return i;
}
- }
- if (this.preferredHashAlgorithms !== null) {
- bytes = util.bin2str(this.preferredHashAlgorithms);
- result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
- }
- if (this.preferredCompressionAlgorithms !== null) {
- bytes = util.bin2str(this.preferredCompressionAlgorithms);
- result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
- }
- if (this.keyServerPreferences !== null) {
- bytes = util.bin2str(this.keyServerPreferences);
- result += write_sub_packet(sub.key_server_preferences, bytes);
- }
- if (this.preferredKeyServer !== null) {
- result += write_sub_packet(sub.preferred_key_server, this.preferredKeyServer);
- }
- if (this.isPrimaryUserID !== null) {
- result += write_sub_packet(sub.primary_user_id, String.fromCharCode(this.isPrimaryUserID ? 1 : 0));
- }
- if (this.policyURI !== null) {
- result += write_sub_packet(sub.policy_uri, this.policyURI);
- }
- if (this.keyFlags !== null) {
- bytes = util.bin2str(this.keyFlags);
- result += write_sub_packet(sub.key_flags, bytes);
- }
- if (this.signersUserId !== null) {
- result += write_sub_packet(sub.signers_user_id, this.signersUserId);
- }
- if (this.reasonForRevocationFlag !== null) {
- bytes = String.fromCharCode(this.reasonForRevocationFlag);
- bytes += this.reasonForRevocationString;
- result += write_sub_packet(sub.reason_for_revocation, bytes);
- }
- if (this.features !== null) {
- bytes = util.bin2str(this.features);
- result += write_sub_packet(sub.features, bytes);
- }
- if (this.signatureTargetPublicKeyAlgorithm !== null) {
- bytes = String.fromCharCode(this.signatureTargetPublicKeyAlgorithm);
- bytes += String.fromCharCode(this.signatureTargetHashAlgorithm);
- bytes += this.signatureTargetHash;
- result += write_sub_packet(sub.signature_target, bytes);
- }
- if (this.embeddedSignature !== null) {
- result += write_sub_packet(sub.embedded_signature, this.embeddedSignature.write());
- }
- result = util.writeNumber(result.length, 2) + result;
- return result;
- };
- /**
- * creates a string representation of a sub signature packet (See RFC 4880 5.2.3.1)
- * @param {Integer} type subpacket signature type. Signature types as described
- * in RFC4880 Section 5.2.3.2
- * @param {String} data data to be included
- * @return {String} a string-representation of a sub signature packet (See RFC 4880 5.2.3.1)
- */
- function write_sub_packet(type, data) {
- var result = "";
- result += packet.writeSimpleLength(data.length + 1);
- result += String.fromCharCode(type);
- result += data;
- return result;
+ // hashed subpackets
+ i += subpackets.call(this, bytes.substr(i), true);
+
+ // A V4 signature hashes the packet body
+ // starting from its first field, the version number, through the end
+ // of the hashed subpacket data. Thus, the fields hashed are the
+ // signature version, the signature type, the public-key algorithm, the
+ // hash algorithm, the hashed subpacket length, and the hashed
+ // subpacket body.
+ this.signatureData = bytes.substr(0, i);
+
+ // unhashed subpackets
+ i += subpackets.call(this, bytes.substr(i), false);
+
+ break;
+ default:
+ throw new Error('Version ' + version + ' of the signature is unsupported.');
}
- // V4 signature sub packets
+ // Two-octet field holding left 16 bits of signed hash value.
+ this.signedHashValue = bytes.substr(i, 2);
+ i += 2;
- this.read_sub_packet = function (bytes) {
- var mypos = 0;
-
- function read_array(prop, bytes) {
- this[prop] = [];
-
- for (var i = 0; i < bytes.length; i++) {
- this[prop].push(bytes.charCodeAt(i));
- }
- }
-
- // The leftwost bit denotes a "critical" packet, but we ignore it.
- var type = bytes.charCodeAt(mypos++) & 0x7F;
- var seconds;
-
- // subpacket type
- switch (type) {
- case 2:
- // Signature Creation Time
- this.created = util.readDate(bytes.substr(mypos));
- break;
- case 3:
- // Signature Expiration Time in seconds
- seconds = util.readNumber(bytes.substr(mypos));
-
- this.signatureNeverExpires = seconds === 0;
- this.signatureExpirationTime = seconds;
-
- break;
- case 4:
- // Exportable Certification
- this.exportable = bytes.charCodeAt(mypos++) == 1;
- break;
- case 5:
- // Trust Signature
- this.trustLevel = bytes.charCodeAt(mypos++);
- this.trustAmount = bytes.charCodeAt(mypos++);
- break;
- case 6:
- // Regular Expression
- this.regularExpression = bytes.substr(mypos);
- break;
- case 7:
- // Revocable
- this.revocable = bytes.charCodeAt(mypos++) == 1;
- break;
- case 9:
- // Key Expiration Time in seconds
- seconds = util.readNumber(bytes.substr(mypos));
-
- this.keyExpirationTime = seconds;
- this.keyNeverExpires = seconds === 0;
-
- break;
- case 11:
- // Preferred Symmetric Algorithms
- this.preferredSymmetricAlgorithms = [];
-
- while (mypos != bytes.length) {
- this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
- }
-
- break;
- case 12:
- // Revocation Key
- // (1 octet of class, 1 octet of public-key algorithm ID, 20
- // octets of
- // fingerprint)
- this.revocationKeyClass = bytes.charCodeAt(mypos++);
- this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
- this.revocationKeyFingerprint = bytes.substr(mypos, 20);
- break;
-
- case 16:
- // Issuer
- this.issuerKeyId.read(bytes.substr(mypos));
- break;
-
- case 20:
- // Notation Data
- // We don't know how to handle anything but a text flagged data.
- if (bytes.charCodeAt(mypos) == 0x80) {
-
- // We extract key/value tuple from the byte stream.
- mypos += 4;
- var m = util.readNumber(bytes.substr(mypos, 2));
- mypos += 2;
- var n = util.readNumber(bytes.substr(mypos, 2));
- mypos += 2;
-
- var name = bytes.substr(mypos, m),
- value = bytes.substr(mypos + m, n);
-
- this.notation = this.notation || {};
- this.notation[name] = value;
- } else throw new Error("Unsupported notation flag.");
- break;
- case 21:
- // Preferred Hash Algorithms
- read_array.call(this, 'preferredHashAlgorithms', bytes.substr(mypos));
- break;
- case 22:
- // Preferred Compression Algorithms
- read_array.call(this, 'preferredCompressionAlgorithms ', bytes.substr(mypos));
- break;
- case 23:
- // Key Server Preferences
- read_array.call(this, 'keyServerPreferencess', bytes.substr(mypos));
- break;
- case 24:
- // Preferred Key Server
- this.preferredKeyServer = bytes.substr(mypos);
- break;
- case 25:
- // Primary User ID
- this.isPrimaryUserID = bytes[mypos++] !== 0;
- break;
- case 26:
- // Policy URI
- this.policyURI = bytes.substr(mypos);
- break;
- case 27:
- // Key Flags
- read_array.call(this, 'keyFlags', bytes.substr(mypos));
- break;
- case 28:
- // Signer's User ID
- this.signersUserId += bytes.substr(mypos);
- break;
- case 29:
- // Reason for Revocation
- this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
- this.reasonForRevocationString = bytes.substr(mypos);
- break;
- case 30:
- // Features
- read_array.call(this, 'features', bytes.substr(mypos));
- break;
- case 31:
- // Signature Target
- // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
- this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
- this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
-
- var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
-
- this.signatureTargetHash = bytes.substr(mypos, len);
- break;
- case 32:
- // Embedded Signature
- this.embeddedSignature = new signature();
- this.embeddedSignature.read(bytes.substr(mypos));
- break;
- default:
- throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
- }
- };
-
- // Produces data to produce signature on
- this.toSign = function (type, data) {
- var t = enums.signature;
-
- switch (type) {
- case t.binary:
- case t.text:
- return data.getBytes();
-
- case t.standalone:
- return '';
-
- case t.cert_generic:
- case t.cert_persona:
- case t.cert_casual:
- case t.cert_positive:
- case t.cert_revocation:
- var packet, tag;
-
- if (data.userid !== undefined) {
- tag = 0xB4;
- packet = data.userid;
- } else if (data.userattribute !== undefined) {
- tag = 0xD1;
- packet = data.userattribute;
- } else throw new Error('Either a userid or userattribute packet needs to be ' +
- 'supplied for certification.');
-
- var bytes = packet.write();
-
- if (this.version == 4) {
- return this.toSign(t.key, data) +
- String.fromCharCode(tag) +
- util.writeNumber(bytes.length, 4) +
- bytes;
- } else if (this.version == 3) {
- return this.toSign(t.key, data) +
- bytes;
- }
- break;
-
- case t.subkey_binding:
- case t.key_binding:
- return this.toSign(t.key, data) + this.toSign(t.key, {
- key: data.bind
- });
-
- case t.key:
- if (data.key === undefined)
- throw new Error('Key packet is required for this sigtature.');
-
- return data.key.writeOld();
-
- case t.key_revocation:
- case t.subkey_revocation:
- return this.toSign(t.key, data);
- case t.timestamp:
- return '';
- case t.third_party:
- throw new Error('Not implemented');
- default:
- throw new Error('Unknown signature type.');
- }
- };
-
-
- this.calculateTrailer = function () {
- // calculating the trailer
- var trailer = '';
- // V3 signatures don't have a trailer
- if (this.version == 3) return trailer;
- trailer += String.fromCharCode(4); // Version
- trailer += String.fromCharCode(0xFF);
- trailer += util.writeNumber(this.signatureData.length, 4);
- return trailer;
- };
-
-
- /**
- * verifys the signature packet. Note: not signature types are implemented
- * @param {String|Object} data data which on the signature applies
- * @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) {
- var signatureType = enums.write(enums.signature, this.signatureType),
- publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm),
- hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm);
-
- var bytes = this.toSign(signatureType, data),
- trailer = this.calculateTrailer();
-
-
- var mpicount = 0;
- // Algorithm-Specific Fields for RSA signatures:
- // - multiprecision number (MPI) of RSA signature value m**d mod n.
- if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
- mpicount = 1;
- // Algorithm-Specific Fields for DSA signatures:
- // - MPI of DSA value r.
- // - MPI of DSA value s.
- else if (publicKeyAlgorithm == 17)
- mpicount = 2;
-
- var mpi = [],
- i = 0;
- for (var j = 0; j < mpicount; j++) {
- mpi[j] = new type_mpi();
- i += mpi[j].read(this.signature.substr(i));
- }
-
- this.verified = crypto.signature.verify(publicKeyAlgorithm,
- hashAlgorithm, mpi, key.mpi,
- bytes + this.signatureData + trailer);
-
- return this.verified;
- };
-
- /**
- * Verifies signature expiration date
- * @return {Boolean} true if expired
- */
- this.isExpired = function () {
- if (!this.signatureNeverExpires) {
- return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
- }
- return false;
- };
+ this.signature = bytes.substr(i);
};
+Signature.prototype.write = function () {
+ return this.signatureData +
+ util.writeNumber(0, 2) + // Number of unsigned subpackets.
+ this.signedHashValue +
+ this.signature;
+};
+
+/**
+ * Signs provided data. This needs to be done prior to serialization.
+ * @param {module:packet/secret_key} key private key used to sign the message.
+ * @param {Object} data Contains packets to be signed.
+ */
+Signature.prototype.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);
+
+ var result = String.fromCharCode(4);
+ result += String.fromCharCode(signatureType);
+ result += String.fromCharCode(publicKeyAlgorithm);
+ result += String.fromCharCode(hashAlgorithm);
+
+ this.issuerKeyId = key.getKeyId();
+
+ // Add hashed subpackets
+ result += this.write_all_sub_packets();
+
+ this.signatureData = result;
+
+ var trailer = this.calculateTrailer();
+
+ var toHash = this.toSign(signatureType, data) +
+ this.signatureData + trailer;
+
+ var hash = crypto.hash.digest(hashAlgorithm, toHash);
+
+ this.signedHashValue = hash.substr(0, 2);
+
+ this.signature = crypto.signature.sign(hashAlgorithm,
+ publicKeyAlgorithm, key.mpi, toHash);
+};
+
+/**
+ * Creates string of bytes with all subpacket data
+ * @return {String} a string-representation of a all subpacket data
+ */
+Signature.prototype.write_all_sub_packets = function () {
+ var sub = enums.signatureSubpacket;
+ var result = '';
+ var bytes = '';
+ if (this.created !== null) {
+ result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
+ }
+ if (this.signatureExpirationTime !== null) {
+ result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4));
+ }
+ if (this.exportable !== null) {
+ result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
+ }
+ if (this.trustLevel !== null) {
+ bytes = String.fromCharCode(this.trustLevel) + String.fromCharCode(this.trustAmount);
+ result += write_sub_packet(sub.trust_signature, bytes);
+ }
+ if (this.regularExpression !== null) {
+ result += write_sub_packet(sub.regular_expression, this.regularExpression);
+ }
+ if (this.revocable !== null) {
+ result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
+ }
+ if (this.keyExpirationTime !== null) {
+ result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4));
+ }
+ if (this.preferredSymmetricAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredSymmetricAlgorithms);
+ result += write_sub_packet(sub.preferred_symmetric_algorithms, bytes);
+ }
+ if (this.revocationKeyClass !== null) {
+ bytes = String.fromCharCode(this.revocationKeyClass);
+ bytes += String.fromCharCode(this.revocationKeyAlgorithm);
+ bytes += this.revocationKeyFingerprint;
+ result += write_sub_packet(sub.revocation_key, bytes);
+ }
+ if (!this.issuerKeyId.isNull()) {
+ result += write_sub_packet(sub.issuer, this.issuerKeyId.write());
+ }
+ if (this.notation !== null) {
+ for (var name in this.notation) {
+ if (this.notation.hasOwnProperty(name)) {
+ var value = this.notation[name];
+ bytes = String.fromCharCode(0x80);
+ bytes += String.fromCharCode(0);
+ bytes += String.fromCharCode(0);
+ bytes += String.fromCharCode(0);
+ // 2 octets of name length
+ bytes += util.writeNumber(name.length, 2);
+ // 2 octets of value length
+ bytes += util.writeNumber(value.length, 2);
+ bytes += name + value;
+ result += write_sub_packet(sub.notation_data, bytes);
+ }
+ }
+ }
+ if (this.preferredHashAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredHashAlgorithms);
+ result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
+ }
+ if (this.preferredCompressionAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredCompressionAlgorithms);
+ result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
+ }
+ if (this.keyServerPreferences !== null) {
+ bytes = util.bin2str(this.keyServerPreferences);
+ result += write_sub_packet(sub.key_server_preferences, bytes);
+ }
+ if (this.preferredKeyServer !== null) {
+ result += write_sub_packet(sub.preferred_key_server, this.preferredKeyServer);
+ }
+ if (this.isPrimaryUserID !== null) {
+ result += write_sub_packet(sub.primary_user_id, String.fromCharCode(this.isPrimaryUserID ? 1 : 0));
+ }
+ if (this.policyURI !== null) {
+ result += write_sub_packet(sub.policy_uri, this.policyURI);
+ }
+ if (this.keyFlags !== null) {
+ bytes = util.bin2str(this.keyFlags);
+ result += write_sub_packet(sub.key_flags, bytes);
+ }
+ if (this.signersUserId !== null) {
+ result += write_sub_packet(sub.signers_user_id, this.signersUserId);
+ }
+ if (this.reasonForRevocationFlag !== null) {
+ bytes = String.fromCharCode(this.reasonForRevocationFlag);
+ bytes += this.reasonForRevocationString;
+ result += write_sub_packet(sub.reason_for_revocation, bytes);
+ }
+ if (this.features !== null) {
+ bytes = util.bin2str(this.features);
+ result += write_sub_packet(sub.features, bytes);
+ }
+ if (this.signatureTargetPublicKeyAlgorithm !== null) {
+ bytes = String.fromCharCode(this.signatureTargetPublicKeyAlgorithm);
+ bytes += String.fromCharCode(this.signatureTargetHashAlgorithm);
+ bytes += this.signatureTargetHash;
+ result += write_sub_packet(sub.signature_target, bytes);
+ }
+ if (this.embeddedSignature !== null) {
+ result += write_sub_packet(sub.embedded_signature, this.embeddedSignature.write());
+ }
+ result = util.writeNumber(result.length, 2) + result;
+ return result;
+};
+
+/**
+ * creates a string representation of a sub signature packet (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.1|RFC 4880 5.2.3.1})
+ * @param {Integer} type subpacket signature type. Signature types as described
+ * in {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.2|RFC4880 Section 5.2.3.2}
+ * @param {String} data data to be included
+ * @return {String} a string-representation of a sub signature packet (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.1|RFC 4880 5.2.3.1})
+ */
+function write_sub_packet(type, data) {
+ var result = "";
+ result += packet.writeSimpleLength(data.length + 1);
+ result += String.fromCharCode(type);
+ result += data;
+ return result;
+}
+
+// V4 signature sub packets
+
+Signature.prototype.read_sub_packet = function (bytes) {
+ var mypos = 0;
+
+ function read_array(prop, bytes) {
+ this[prop] = [];
+
+ for (var i = 0; i < bytes.length; i++) {
+ this[prop].push(bytes.charCodeAt(i));
+ }
+ }
+
+ // The leftwost bit denotes a "critical" packet, but we ignore it.
+ var type = bytes.charCodeAt(mypos++) & 0x7F;
+ var seconds;
+
+ // subpacket type
+ switch (type) {
+ case 2:
+ // Signature Creation Time
+ this.created = util.readDate(bytes.substr(mypos));
+ break;
+ case 3:
+ // Signature Expiration Time in seconds
+ seconds = util.readNumber(bytes.substr(mypos));
+
+ this.signatureNeverExpires = seconds === 0;
+ this.signatureExpirationTime = seconds;
+
+ break;
+ case 4:
+ // Exportable Certification
+ this.exportable = bytes.charCodeAt(mypos++) == 1;
+ break;
+ case 5:
+ // Trust Signature
+ this.trustLevel = bytes.charCodeAt(mypos++);
+ this.trustAmount = bytes.charCodeAt(mypos++);
+ break;
+ case 6:
+ // Regular Expression
+ this.regularExpression = bytes.substr(mypos);
+ break;
+ case 7:
+ // Revocable
+ this.revocable = bytes.charCodeAt(mypos++) == 1;
+ break;
+ case 9:
+ // Key Expiration Time in seconds
+ seconds = util.readNumber(bytes.substr(mypos));
+
+ this.keyExpirationTime = seconds;
+ this.keyNeverExpires = seconds === 0;
+
+ break;
+ case 11:
+ // Preferred Symmetric Algorithms
+ this.preferredSymmetricAlgorithms = [];
+
+ while (mypos != bytes.length) {
+ this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
+ }
+
+ break;
+ case 12:
+ // Revocation Key
+ // (1 octet of class, 1 octet of public-key algorithm ID, 20
+ // octets of
+ // fingerprint)
+ this.revocationKeyClass = bytes.charCodeAt(mypos++);
+ this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
+ this.revocationKeyFingerprint = bytes.substr(mypos, 20);
+ break;
+
+ case 16:
+ // Issuer
+ this.issuerKeyId.read(bytes.substr(mypos));
+ break;
+
+ case 20:
+ // Notation Data
+ // We don't know how to handle anything but a text flagged data.
+ if (bytes.charCodeAt(mypos) == 0x80) {
+
+ // We extract key/value tuple from the byte stream.
+ mypos += 4;
+ var m = util.readNumber(bytes.substr(mypos, 2));
+ mypos += 2;
+ var n = util.readNumber(bytes.substr(mypos, 2));
+ mypos += 2;
+
+ var name = bytes.substr(mypos, m),
+ value = bytes.substr(mypos + m, n);
+
+ this.notation = this.notation || {};
+ this.notation[name] = value;
+ } else throw new Error("Unsupported notation flag.");
+ break;
+ case 21:
+ // Preferred Hash Algorithms
+ read_array.call(this, 'preferredHashAlgorithms', bytes.substr(mypos));
+ break;
+ case 22:
+ // Preferred Compression Algorithms
+ read_array.call(this, 'preferredCompressionAlgorithms ', bytes.substr(mypos));
+ break;
+ case 23:
+ // Key Server Preferences
+ read_array.call(this, 'keyServerPreferencess', bytes.substr(mypos));
+ break;
+ case 24:
+ // Preferred Key Server
+ this.preferredKeyServer = bytes.substr(mypos);
+ break;
+ case 25:
+ // Primary User ID
+ this.isPrimaryUserID = bytes[mypos++] !== 0;
+ break;
+ case 26:
+ // Policy URI
+ this.policyURI = bytes.substr(mypos);
+ break;
+ case 27:
+ // Key Flags
+ read_array.call(this, 'keyFlags', bytes.substr(mypos));
+ break;
+ case 28:
+ // Signer's User ID
+ this.signersUserId += bytes.substr(mypos);
+ break;
+ case 29:
+ // Reason for Revocation
+ this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
+ this.reasonForRevocationString = bytes.substr(mypos);
+ break;
+ case 30:
+ // Features
+ read_array.call(this, 'features', bytes.substr(mypos));
+ break;
+ case 31:
+ // Signature Target
+ // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
+ this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
+ this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
+
+ var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
+
+ this.signatureTargetHash = bytes.substr(mypos, len);
+ break;
+ case 32:
+ // Embedded Signature
+ this.embeddedSignature = new Signature();
+ this.embeddedSignature.read(bytes.substr(mypos));
+ break;
+ default:
+ throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
+ }
+};
+
+// Produces data to produce signature on
+Signature.prototype.toSign = function (type, data) {
+ var t = enums.signature;
+
+ switch (type) {
+ case t.binary:
+ case t.text:
+ return data.getBytes();
+
+ case t.standalone:
+ return '';
+
+ case t.cert_generic:
+ case t.cert_persona:
+ case t.cert_casual:
+ case t.cert_positive:
+ case t.cert_revocation:
+ var packet, tag;
+
+ if (data.userid !== undefined) {
+ tag = 0xB4;
+ packet = data.userid;
+ } else if (data.userattribute !== undefined) {
+ tag = 0xD1;
+ packet = data.userattribute;
+ } else throw new Error('Either a userid or userattribute packet needs to be ' +
+ 'supplied for certification.');
+
+ var bytes = packet.write();
+
+ if (this.version == 4) {
+ return this.toSign(t.key, data) +
+ String.fromCharCode(tag) +
+ util.writeNumber(bytes.length, 4) +
+ bytes;
+ } else if (this.version == 3) {
+ return this.toSign(t.key, data) +
+ bytes;
+ }
+ break;
+
+ case t.subkey_binding:
+ case t.key_binding:
+ return this.toSign(t.key, data) + this.toSign(t.key, {
+ key: data.bind
+ });
+
+ case t.key:
+ if (data.key === undefined)
+ throw new Error('Key packet is required for this sigtature.');
+
+ return data.key.writeOld();
+
+ case t.key_revocation:
+ case t.subkey_revocation:
+ return this.toSign(t.key, data);
+ case t.timestamp:
+ return '';
+ case t.third_party:
+ throw new Error('Not implemented');
+ default:
+ throw new Error('Unknown signature type.');
+ }
+};
+
+
+Signature.prototype.calculateTrailer = function () {
+ // calculating the trailer
+ var trailer = '';
+ // V3 signatures don't have a trailer
+ if (this.version == 3) return trailer;
+ trailer += String.fromCharCode(4); // Version
+ trailer += String.fromCharCode(0xFF);
+ trailer += util.writeNumber(this.signatureData.length, 4);
+ return trailer;
+};
+
+
+/**
+ * verifys the signature packet. Note: not signature types are implemented
+ * @param {String|Object} data data which on the signature applies
+ * @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.
+ */
+Signature.prototype.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);
+
+ var bytes = this.toSign(signatureType, data),
+ trailer = this.calculateTrailer();
+
+
+ var mpicount = 0;
+ // Algorithm-Specific Fields for RSA signatures:
+ // - multiprecision number (MPI) of RSA signature value m**d mod n.
+ if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
+ mpicount = 1;
+ // Algorithm-Specific Fields for DSA signatures:
+ // - MPI of DSA value r.
+ // - MPI of DSA value s.
+ else if (publicKeyAlgorithm == 17)
+ mpicount = 2;
+
+ var mpi = [],
+ i = 0;
+ for (var j = 0; j < mpicount; j++) {
+ mpi[j] = new type_mpi();
+ i += mpi[j].read(this.signature.substr(i));
+ }
+
+ this.verified = crypto.signature.verify(publicKeyAlgorithm,
+ hashAlgorithm, mpi, key.mpi,
+ bytes + this.signatureData + trailer);
+
+ return this.verified;
+};
+
+/**
+ * Verifies signature expiration date
+ * @return {Boolean} true if expired
+ */
+Signature.prototype.isExpired = function () {
+ if (!this.signatureNeverExpires) {
+ return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
+ }
+ return false;
+};
@@ -674,13 +675,13 @@ module.exports = function signature() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/signature_.html b/doc/signature_.html
index 20353cd9..d96cd1a3 100644
--- a/doc/signature_.html
+++ b/doc/signature_.html
@@ -35,83 +35,17 @@
+
+
Implementation of the Signature Packet (Tag 2)
-RFC4480 5.2:
+
RFC4480 5.2 :
A Signature packet describes a binding between some public key and
some data. The most common signatures are a signature of a file or a
block of text, and a signature that is a certification of a User ID.
-
- new (require("packet/signature"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -174,6 +108,13 @@ block of text, and a signature that is a certification of a User ID.
+ Classes
+
+
+ Signature
+
+
+
@@ -184,681 +125,6 @@ block of text, and a signature that is a certification of a User ID.
-
- isExpired() → {Boolean}
-
-
-
-
-
-
-
- Verifies signature expiration date
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- true if expired
-
-
-
-
-
-
- Type
-
-
-
-Boolean
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- parsing function for a signature packet (tag 2).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- bytes
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- payload of a tag 2 packet
-
-
-
-
-
-
- position
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- position to start reading from the bytes string
-
-
-
-
-
-
- len
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- length of the packet or the remaining length of bytes at position
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/signature
-
-
-
-
-
-
-
-
-
-
-
-
-
- sign(key, data)
-
-
-
-
-
-
-
- Signs provided data. This needs to be done prior to serialization.
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- key
-
-
-
-
-
-module:packet/secret_key
-
-
-
-
-
-
-
-
-
- private key used to sign the message.
-
-
-
-
-
-
- data
-
-
-
-
-
-Object
-
-
-
-
-
-
-
-
-
- Contains packets to be signed.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- verify(data, key) → {boolean}
-
-
-
-
-
-
-
- verifys the signature packet. Note: not signature types are implemented
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- data
-
-
-
-
-
-String
-|
-
-Object
-
-
-
-
-
-
-
-
-
- data which on the signature applies
-
-
-
-
-
-
- key
-
-
-
-
-
-module:packet/public_subkey
-|
-
-module:packet/public_key
-
-
-
-
-
-
-
-
-
- the public key to verify the signature
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- True if message is verified, else false.
-
-
-
-
-
-
- Type
-
-
-
-boolean
-
-
-
-
-
-
-
-
-
-
-
-
-
- write_all_sub_packets() → {String}
-
-
-
-
-
-
-
- Creates string of bytes with all subpacket data
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- a string-representation of a all subpacket data
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
<inner> write_sub_packet(type, data) → {String}
@@ -868,7 +134,7 @@ block of text, and a signature that is a certification of a User ID.
- creates a string representation of a sub signature packet (See RFC 4880 5.2.3.1)
+ creates a string representation of a sub signature packet (See
RFC 4880 5.2.3.1 )
@@ -918,8 +184,8 @@ block of text, and a signature that is a certification of a User ID.
- subpacket signature type. Signature types as described
-in RFC4880 Section 5.2.3.2
+ subpacket signature type. Signature types as described
+in RFC4880 Section 5.2.3.2
@@ -973,7 +239,7 @@ in RFC4880 Section 5.2.3.2
Source:
@@ -998,7 +264,7 @@ in RFC4880 Section 5.2.3.2
- a string-representation of a sub signature packet (See RFC 4880 5.2.3.1)
+ a string-representation of a sub signature packet (See
RFC 4880 5.2.3.1 )
@@ -1036,13 +302,13 @@ in RFC4880 Section 5.2.3.2
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/sym_encrypted_integrity_protected-SymEncryptedIntegrityProtected.html b/doc/sym_encrypted_integrity_protected-SymEncryptedIntegrityProtected.html
new file mode 100644
index 00000000..180217b5
--- /dev/null
+++ b/doc/sym_encrypted_integrity_protected-SymEncryptedIntegrityProtected.html
@@ -0,0 +1,439 @@
+
+
+
+
+ JSDoc: Class: SymEncryptedIntegrityProtected
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: SymEncryptedIntegrityProtected
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new SymEncryptedIntegrityProtected()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+ encrypted
+
+
+
+
+
+
+ The encrypted payload.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ modification :Boolean
+
+
+
+
+
+
+ If after decrypting the packet this is set to true,
+a modification has been detected and thus the contents
+should be discarded.
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ decrypt(sessionKeyAlgorithm, key) → {String}
+
+
+
+
+
+
+
+ Decrypts the encrypted data contained in this object read_packet must
+have been called before
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ sessionKeyAlgorithm
+
+
+
+
+
+module:enums.symmetric
+
+
+
+
+
+
+
+
+
+ The selected symmetric encryption algorithm to be used
+
+
+
+
+
+
+ key
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ The key of cipher blocksize length to be used
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The decrypted data of this packet
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/sym_encrypted_integrity_protected.html b/doc/sym_encrypted_integrity_protected.html
index dbf224f6..19b6b478 100644
--- a/doc/sym_encrypted_integrity_protected.html
+++ b/doc/sym_encrypted_integrity_protected.html
@@ -35,85 +35,20 @@
+
+
Implementation of the Sym. Encrypted Integrity Protected Data
Packet (Tag 18)
-RFC4880 5.13: The Symmetrically Encrypted Integrity Protected Data packet is
+
RFC4880 5.13 :
+The Symmetrically Encrypted Integrity Protected Data packet is
a variant of the Symmetrically Encrypted Data packet. It is a new feature
created for OpenPGP that addresses the problem of detecting a modification to
encrypted data. It is used in combination with a Modification Detection Code
packet.
-
- new (require("packet/sym_encrypted_integrity_protected"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -168,304 +103,20 @@ packet.
-
-
-
-
- Members
+ Classes
-
-
- encrypted
-
-
-
-
-
-
- The encrypted payload.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- modification :Boolean
-
-
-
-
-
-
- If after decrypting the packet this is set to true,
-a modification has been detected and thus the contents
-should be discarded.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ SymEncryptedIntegrityProtected
+
- Methods
-
-
-
-
- decrypt(sessionKeyAlgorithm, key) → {String}
-
-
-
-
-
-
-
- Decrypts the encrypted data contained in this object read_packet must
-have been called before
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- sessionKeyAlgorithm
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- The selected symmetric encryption algorithm to be used
-
-
-
-
-
-
- key
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- The key of cipher blocksize length to be used
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The decrypted data of this packet
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -479,13 +130,13 @@ have been called before
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/sym_encrypted_integrity_protected.js.html b/doc/sym_encrypted_integrity_protected.js.html
index e4d6569d..e5688d30 100644
--- a/doc/sym_encrypted_integrity_protected.js.html
+++ b/doc/sym_encrypted_integrity_protected.js.html
@@ -46,7 +46,8 @@
* Implementation of the Sym. Encrypted Integrity Protected Data
* Packet (Tag 18)<br/>
* <br/>
- * RFC4880 5.13: The Symmetrically Encrypted Integrity Protected Data packet is
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.13|RFC4880 5.13}:
+ * The Symmetrically Encrypted Integrity Protected Data packet is
* a variant of the Symmetrically Encrypted Data packet. It is a new feature
* created for OpenPGP that addresses the problem of detecting a modification to
* encrypted data. It is used in combination with a Modification Detection Code
@@ -56,13 +57,15 @@
* @module packet/sym_encrypted_integrity_protected
*/
+module.exports = SymEncryptedIntegrityProtected;
+
var util = require('../util'),
crypto = require('../crypto');
/**
* @constructor
*/
-module.exports = function sym_encrypted_integrity_protected() {
+function SymEncryptedIntegrityProtected() {
/** The encrypted payload. */
this.encrypted = null; // string
/**
@@ -73,78 +76,77 @@ module.exports = function sym_encrypted_integrity_protected() {
*/
this.modification = false;
this.packets = null;
+}
+
+SymEncryptedIntegrityProtected.prototype.read = function (bytes) {
+ // - A one-octet version number. The only currently defined value is 1.
+ var version = bytes.charCodeAt(0);
+
+ if (version != 1) {
+ throw new Error('Invalid packet version.');
+ }
+
+ // - Encrypted data, the output of the selected symmetric-key cipher
+ // operating in Cipher Feedback mode with shift amount equal to the
+ // block size of the cipher (CFB-n where n is the block size).
+ this.encrypted = bytes.substr(1);
+};
+
+SymEncryptedIntegrityProtected.prototype.write = function () {
+
+ // 1 = Version
+ return String.fromCharCode(1) + this.encrypted;
+};
+
+SymEncryptedIntegrityProtected.prototype.encrypt = function (sessionKeyAlgorithm, key) {
+ var bytes = this.packets.write();
+
+ var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
+ var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
+ 1);
+
+ var tohash = bytes;
- this.read = function (bytes) {
- // - A one-octet version number. The only currently defined value is 1.
- var version = bytes.charCodeAt(0);
-
- if (version != 1) {
- throw new Error('Invalid packet version.');
- }
-
- // - Encrypted data, the output of the selected symmetric-key cipher
- // operating in Cipher Feedback mode with shift amount equal to the
- // block size of the cipher (CFB-n where n is the block size).
- this.encrypted = bytes.substr(1);
- };
-
- this.write = function () {
-
- // 1 = Version
- return String.fromCharCode(1) + this.encrypted;
- };
-
- this.encrypt = function (sessionKeyAlgorithm, key) {
- var bytes = this.packets.write();
-
- var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
- var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
- 1);
-
- var tohash = bytes;
+ // Modification detection code packet.
+ tohash += String.fromCharCode(0xD3);
+ tohash += String.fromCharCode(0x14);
- // Modification detection code packet.
- tohash += String.fromCharCode(0xD3);
- tohash += String.fromCharCode(0x14);
+ tohash += crypto.hash.sha1(prefix + tohash);
- tohash += crypto.hash.sha1(prefix + tohash);
+ this.encrypted = crypto.cfb.encrypt(prefixrandom,
+ sessionKeyAlgorithm, tohash, key, false).substring(0,
+ prefix.length + tohash.length);
+};
+
+/**
+ * Decrypts the encrypted data contained in this object read_packet must
+ * have been called before
+ *
+ * @param {module:enums.symmetric} sessionKeyAlgorithm
+ * The selected symmetric encryption algorithm to be used
+ * @param {String} key The key of cipher blocksize length to be used
+ * @return {String} The decrypted data of this packet
+ */
+SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm, key) {
+ var decrypted = crypto.cfb.decrypt(
+ sessionKeyAlgorithm, key, this.encrypted, false);
- this.encrypted = crypto.cfb.encrypt(prefixrandom,
- sessionKeyAlgorithm, tohash, key, false).substring(0,
- prefix.length + tohash.length);
- };
-
- /**
- * Decrypts the encrypted data contained in this object read_packet must
- * have been called before
- *
- * @param {Integer} sessionKeyAlgorithm
- * The selected symmetric encryption algorithm to be used
- * @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) {
- var decrypted = crypto.cfb.decrypt(
- sessionKeyAlgorithm, key, this.encrypted, false);
+ // there must be a modification detection code packet as the
+ // last packet and everything gets hashed except the hash itself
+ this.hash = crypto.hash.sha1(
+ crypto.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted) + decrypted.substring(0, decrypted.length - 20));
- // there must be a modification detection code packet as the
- // last packet and everything gets hashed except the hash itself
- this.hash = crypto.hash.sha1(
- crypto.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted) + decrypted.substring(0, decrypted.length - 20));
+ var mdc = decrypted.substr(decrypted.length - 20, 20);
-
- var mdc = decrypted.substr(decrypted.length - 20, 20);
-
- if (this.hash != mdc) {
- throw new Error('Modification detected.');
- } else
- this.packets.read(decrypted.substr(0, decrypted.length - 22));
- };
+ if (this.hash != mdc) {
+ throw new Error('Modification detected.');
+ } else
+ this.packets.read(decrypted.substr(0, decrypted.length - 22));
};
@@ -156,13 +158,13 @@ module.exports = function sym_encrypted_integrity_protected() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/sym_encrypted_session_key-SymEncryptedSessionKey.html b/doc/sym_encrypted_session_key-SymEncryptedSessionKey.html
new file mode 100644
index 00000000..40baedf1
--- /dev/null
+++ b/doc/sym_encrypted_session_key-SymEncryptedSessionKey.html
@@ -0,0 +1,430 @@
+
+
+
+
+ JSDoc: Class: SymEncryptedSessionKey
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: SymEncryptedSessionKey
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new SymEncryptedSessionKey()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ decrypt() → {String}
+
+
+
+
+
+
+
+ Decrypts the session key (only for public key encrypted session key
+packets (tag 1)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ The unencrypted session key
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parsing function for a symmetric encrypted session key packet (tag 3).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Payload of a tag 1 packet
+
+
+
+
+
+
+ position
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Position to start reading from the input string
+
+
+
+
+
+
+ len
+
+
+
+
+
+Integer
+
+
+
+
+
+
+
+
+
+ Length of the packet or the remaining length of
+ input at position
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ Object representation
+
+
+
+
+
+
+ Type
+
+
+
+module:packet/sym_encrypted_session_key
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/sym_encrypted_session_key.html b/doc/sym_encrypted_session_key.html
index a713f78b..77178ceb 100644
--- a/doc/sym_encrypted_session_key.html
+++ b/doc/sym_encrypted_session_key.html
@@ -35,10 +35,12 @@
+
+
Public-Key Encrypted Session Key Packets (Tag 1)
-RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+
RFC4880 5.1 : A Public-Key Encrypted Session Key packet holds the session key
used to encrypt a message. Zero or more Public-Key Encrypted Session Key
packets and/or Symmetric-Key Encrypted Session Key packets may precede a
Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -51,74 +53,6 @@ public key, decrypts the session key, and then uses the session key to
decrypt the message.
-
- new (require("packet/sym_encrypted_session_key"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -175,298 +109,23 @@ decrypt the message.
-
-
-
-
-
-
- Methods
+ Classes
-
-
- decrypt() → {String}
-
-
-
-
-
-
-
- Decrypts the session key (only for public key encrypted session key
-packets (tag 1)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- The unencrypted session key
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Parsing function for a symmetric encrypted session key packet (tag 3).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Payload of a tag 1 packet
-
-
-
-
-
-
- position
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Position to start reading from the input string
-
-
-
-
-
-
- len
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Length of the packet or the remaining length of
- input at position
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- Object representation
-
-
-
-
-
-
- Type
-
-
-
-module:packet/sym_encrypted_session_key
-
-
-
-
-
-
-
-
-
-
+ SymEncryptedSessionKey
+
+
+
+
+
+
+
@@ -477,13 +136,13 @@ packets (tag 1)
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/sym_encrypted_session_key.js.html b/doc/sym_encrypted_session_key.js.html
index f5d78f9d..9ebe9929 100644
--- a/doc/sym_encrypted_session_key.js.html
+++ b/doc/sym_encrypted_session_key.js.html
@@ -45,7 +45,7 @@
/**
* Public-Key Encrypted Session Key Packets (Tag 1)<br/>
* <br/>
- * RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}: A Public-Key Encrypted Session Key packet holds the session key
* used to encrypt a message. Zero or more Public-Key Encrypted Session Key
* packets and/or Symmetric-Key Encrypted Session Key packets may precede a
* Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -66,104 +66,106 @@ var type_s2k = require('../type/s2k.js'),
enums = require('../enums.js'),
crypto = require('../crypto');
+module.exports = SymEncryptedSessionKey;
+
/**
* @constructor
*/
-module.exports = function sym_encrypted_session_key() {
+function SymEncryptedSessionKey() {
this.tag = 3;
this.sessionKeyEncryptionAlgorithm = null;
this.sessionKeyAlgorithm = 'aes256';
this.encrypted = null;
this.s2k = new type_s2k();
+}
- /**
- * Parsing function for a symmetric encrypted session key packet (tag 3).
- *
- * @param {String} input Payload of a tag 1 packet
- * @param {Integer} position Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/sym_encrypted_session_key} Object representation
- */
- this.read = function(bytes) {
- // A one-octet version number. The only currently defined version is 4.
- this.version = bytes.charCodeAt(0);
+/**
+ * Parsing function for a symmetric encrypted session key packet (tag 3).
+ *
+ * @param {String} input Payload of a tag 1 packet
+ * @param {Integer} position Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/sym_encrypted_session_key} Object representation
+ */
+SymEncryptedSessionKey.prototype.read = function(bytes) {
+ // A one-octet version number. The only currently defined version is 4.
+ this.version = bytes.charCodeAt(0);
- // A one-octet number describing the symmetric algorithm used.
- var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
+ // A one-octet number describing the symmetric algorithm used.
+ var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
- // A string-to-key (S2K) specifier, length as defined above.
- var s2klength = this.s2k.read(bytes.substr(2));
+ // A string-to-key (S2K) specifier, length as defined above.
+ var s2klength = this.s2k.read(bytes.substr(2));
- // Optionally, the encrypted session key itself, which is decrypted
- // with the string-to-key object.
- var done = s2klength + 2;
+ // Optionally, the encrypted session key itself, which is decrypted
+ // with the string-to-key object.
+ var done = s2klength + 2;
- if (done < bytes.length) {
- this.encrypted = bytes.substr(done);
- this.sessionKeyEncryptionAlgorithm = algo;
- } else
- this.sessionKeyAlgorithm = algo;
- };
+ if (done < bytes.length) {
+ this.encrypted = bytes.substr(done);
+ this.sessionKeyEncryptionAlgorithm = algo;
+ } else
+ this.sessionKeyAlgorithm = algo;
+};
- this.write = function() {
- var algo = this.encrypted === null ?
- this.sessionKeyAlgorithm :
- this.sessionKeyEncryptionAlgorithm;
+SymEncryptedSessionKey.prototype.write = function() {
+ var algo = this.encrypted === null ?
+ this.sessionKeyAlgorithm :
+ this.sessionKeyEncryptionAlgorithm;
- var bytes = String.fromCharCode(this.version) +
- String.fromCharCode(enums.write(enums.symmetric, algo)) +
- this.s2k.write();
+ var bytes = String.fromCharCode(this.version) +
+ String.fromCharCode(enums.write(enums.symmetric, algo)) +
+ this.s2k.write();
- if (this.encrypted !== null)
- bytes += this.encrypted;
- return bytes;
- };
+ if (this.encrypted !== null)
+ bytes += this.encrypted;
+ return bytes;
+};
- /**
- * Decrypts the session key (only for public key encrypted session key
- * packets (tag 1)
- *
- * @return {String} The unencrypted session key
- */
- this.decrypt = function(passphrase) {
- var algo = this.sessionKeyEncryptionAlgorithm !== null ?
- this.sessionKeyEncryptionAlgorithm :
- this.sessionKeyAlgorithm;
+/**
+ * Decrypts the session key (only for public key encrypted session key
+ * packets (tag 1)
+ *
+ * @return {String} The unencrypted session key
+ */
+SymEncryptedSessionKey.prototype.decrypt = function(passphrase) {
+ var algo = this.sessionKeyEncryptionAlgorithm !== null ?
+ this.sessionKeyEncryptionAlgorithm :
+ this.sessionKeyAlgorithm;
- var length = crypto.cipher[algo].keySize;
- var key = this.s2k.produce_key(passphrase, length);
+ var length = crypto.cipher[algo].keySize;
+ var key = this.s2k.produce_key(passphrase, length);
- if (this.encrypted === null) {
- this.sessionKey = key;
+ if (this.encrypted === null) {
+ this.sessionKey = key;
- } else {
- var decrypted = crypto.cfb.decrypt(
- this.sessionKeyEncryptionAlgorithm, key, this.encrypted, true);
+ } else {
+ var decrypted = crypto.cfb.decrypt(
+ this.sessionKeyEncryptionAlgorithm, key, this.encrypted, true);
- this.sessionKeyAlgorithm = enums.read(enums.symmetric,
- decrypted[0].keyCodeAt());
+ this.sessionKeyAlgorithm = enums.read(enums.symmetric,
+ decrypted[0].keyCodeAt());
- this.sessionKey = decrypted.substr(1);
- }
- };
+ this.sessionKey = decrypted.substr(1);
+ }
+};
- this.encrypt = function(passphrase) {
- var length = crypto.getKeyLength(this.sessionKeyEncryptionAlgorithm);
- var key = this.s2k.produce_key(passphrase, length);
+SymEncryptedSessionKey.prototype.encrypt = function(passphrase) {
+ var length = crypto.getKeyLength(this.sessionKeyEncryptionAlgorithm);
+ var key = this.s2k.produce_key(passphrase, length);
- var private_key = String.fromCharCode(
- enums.write(enums.symmetric, this.sessionKeyAlgorithm)) +
+ var private_key = String.fromCharCode(
+ enums.write(enums.symmetric, this.sessionKeyAlgorithm)) +
- crypto.getRandomBytes(
- crypto.getKeyLength(this.sessionKeyAlgorithm));
+ crypto.getRandomBytes(
+ crypto.getKeyLength(this.sessionKeyAlgorithm));
- this.encrypted = crypto.cfb.encrypt(
- crypto.getPrefixRandom(this.sessionKeyEncryptionAlgorithm),
- this.sessionKeyEncryptionAlgorithm, key, private_key, true);
- };
+ this.encrypted = crypto.cfb.encrypt(
+ crypto.getPrefixRandom(this.sessionKeyEncryptionAlgorithm),
+ this.sessionKeyEncryptionAlgorithm, key, private_key, true);
};
@@ -175,13 +177,13 @@ module.exports = function sym_encrypted_session_key() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/symmetrically_encrypted-SymmetricallyEncrypted.html b/doc/symmetrically_encrypted-SymmetricallyEncrypted.html
new file mode 100644
index 00000000..e8dcb93b
--- /dev/null
+++ b/doc/symmetrically_encrypted-SymmetricallyEncrypted.html
@@ -0,0 +1,361 @@
+
+
+
+
+ JSDoc: Class: SymmetricallyEncrypted
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: SymmetricallyEncrypted
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new SymmetricallyEncrypted()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+
+
+
+
+
+
+
+ Decrypted packets contained within.
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ decrypt(sessionKeyAlgorithm, key)
+
+
+
+
+
+
+
+ Symmetrically decrypt the packet data
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ sessionKeyAlgorithm
+
+
+
+
+
+module:enums.symmetric
+
+
+
+
+
+
+
+
+
+ Symmetric key algorithm to use // See RFC4880 9.2
+
+
+
+
+
+
+ key
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ Key as string with the corresponding length to the
+ algorithm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/symmetrically_encrypted.html b/doc/symmetrically_encrypted.html
index 9b944889..f3b18bec 100644
--- a/doc/symmetrically_encrypted.html
+++ b/doc/symmetrically_encrypted.html
@@ -35,84 +35,18 @@
+
+
Implementation of the Symmetrically Encrypted Data Packet (Tag 9)
-RFC4880 5.7: The Symmetrically Encrypted Data packet contains data encrypted
+
RFC4880 5.7 : The Symmetrically Encrypted Data packet contains data encrypted
with a symmetric-key algorithm. When it has been decrypted, it contains other
packets (usually a literal data packet or compressed data packet, but in
theory other Symmetrically Encrypted Data packets or sequences of packets
that form whole OpenPGP messages).
-
- new (require("packet/symmetrically_encrypted"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -165,226 +99,20 @@ that form whole OpenPGP messages).
-
-
-
-
- Members
+ Classes
-
-
-
-
-
-
-
-
-
- Decrypted packets contained within.
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ SymmetricallyEncrypted
+
- Methods
-
-
-
-
- decrypt(sessionKeyAlgorithm, key)
-
-
-
-
-
-
-
- Symmetrically decrypt the packet data
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- sessionKeyAlgorithm
-
-
-
-
-
-Integer
-
-
-
-
-
-
-
-
-
- Symmetric key algorithm to use // See RFC4880 9.2
-
-
-
-
-
-
- key
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- Key as string with the corresponding length to the
- algorithm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -398,13 +126,13 @@ that form whole OpenPGP messages).
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/symmetrically_encrypted.js.html b/doc/symmetrically_encrypted.js.html
index c5a176e5..fbaff632 100644
--- a/doc/symmetrically_encrypted.js.html
+++ b/doc/symmetrically_encrypted.js.html
@@ -45,7 +45,7 @@
/**
* Implementation of the Symmetrically Encrypted Data Packet (Tag 9)<br/>
* <br/>
- * RFC4880 5.7: The Symmetrically Encrypted Data packet contains data encrypted
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.7|RFC4880 5.7}: The Symmetrically Encrypted Data packet contains data encrypted
* with a symmetric-key algorithm. When it has been decrypted, it contains other
* packets (usually a literal data packet or compressed data packet, but in
* theory other Symmetrically Encrypted Data packets or sequences of packets
@@ -54,47 +54,49 @@
* @module packet/symmetrically_encrypted
*/
+module.exports = SymmetricallyEncrypted;
+
var crypto = require('../crypto');
/**
* @constructor
*/
-module.exports = function symmetrically_encrypted() {
+function SymmetricallyEncrypted() {
this.encrypted = null;
/** Decrypted packets contained within.
* @type {module:packet/packetlist} */
this.packets = null;
+}
- this.read = function(bytes) {
- this.encrypted = bytes;
- };
+SymmetricallyEncrypted.prototype.read = function (bytes) {
+ this.encrypted = bytes;
+};
- this.write = function() {
- return this.encrypted;
- };
+SymmetricallyEncrypted.prototype.write = function () {
+ return this.encrypted;
+};
- /**
- * Symmetrically decrypt the packet data
- *
- * @param {Integer} sessionKeyAlgorithm
- * Symmetric key algorithm to use // See RFC4880 9.2
- * @param {String} key
- * Key as string with the corresponding length to the
- * algorithm
- */
- this.decrypt = function(sessionKeyAlgorithm, key) {
- var decrypted = crypto.cfb.decrypt(
- sessionKeyAlgorithm, key, this.encrypted, true);
+/**
+ * Symmetrically decrypt the packet data
+ *
+ * @param {module:enums.symmetric} sessionKeyAlgorithm
+ * Symmetric key algorithm to use // See {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880 9.2}
+ * @param {String} key
+ * Key as string with the corresponding length to the
+ * algorithm
+ */
+SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) {
+ var decrypted = crypto.cfb.decrypt(
+ sessionKeyAlgorithm, key, this.encrypted, true);
- this.packets.read(decrypted);
- };
+ this.packets.read(decrypted);
+};
- this.encrypt = function(algo, key) {
- var data = this.packets.write();
+SymmetricallyEncrypted.prototype.encrypt = function (algo, key) {
+ var data = this.packets.write();
- this.encrypted = crypto.cfb.encrypt(
- crypto.getPrefixRandom(algo), algo, data, key, true);
- };
+ this.encrypted = crypto.cfb.encrypt(
+ crypto.getPrefixRandom(algo), algo, data, key, true);
};
@@ -106,13 +108,13 @@ module.exports = function symmetrically_encrypted() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/trust-Trust.html b/doc/trust-Trust.html
new file mode 100644
index 00000000..9e02fa95
--- /dev/null
+++ b/doc/trust-Trust.html
@@ -0,0 +1,148 @@
+
+
+
+
+ JSDoc: Class: Trust
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Trust
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Trust()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/trust.html b/doc/trust.html
index 0d8a52ab..f5a63b79 100644
--- a/doc/trust.html
+++ b/doc/trust.html
@@ -35,72 +35,6 @@
-
-
-
- new (require("packet/trust"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -151,6 +85,13 @@
+
Classes
+
+
+ Trust
+
+
+
@@ -171,13 +112,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/trust.js.html b/doc/trust.js.html
index 902786ac..5c0e0920 100644
--- a/doc/trust.js.html
+++ b/doc/trust.js.html
@@ -29,11 +29,12 @@
* @module packet/trust
*/
+module.exports = Trust;
+
/**
* @constructor
*/
-module.exports = function trust() {
-
+function Trust() {
};
@@ -45,13 +46,13 @@ module.exports = function trust() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/twofish.html b/doc/twofish.html
index 2a76fb05..f2fa58a3 100644
--- a/doc/twofish.html
+++ b/doc/twofish.html
@@ -105,13 +105,13 @@
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:50 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:29 GMT+0100 (MEZ)
diff --git a/doc/twofish.js.html b/doc/twofish.js.html
index f74eef85..5c25a5c7 100644
--- a/doc/twofish.js.html
+++ b/doc/twofish.js.html
@@ -417,13 +417,13 @@ module.exports.blockSize = TF.prototype.blockSize = 16;
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/user_attribute-UserAttribute.html b/doc/user_attribute-UserAttribute.html
new file mode 100644
index 00000000..a4e75d85
--- /dev/null
+++ b/doc/user_attribute-UserAttribute.html
@@ -0,0 +1,269 @@
+
+
+
+
+ JSDoc: Class: UserAttribute
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: UserAttribute
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new UserAttribute()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ read(input)
+
+
+
+
+
+
+
+ parsing function for a user attribute packet (tag 17).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ payload of a tag 17 packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/user_attribute.html b/doc/user_attribute.html
index 9383369d..7c934c5f 100644
--- a/doc/user_attribute.html
+++ b/doc/user_attribute.html
@@ -35,6 +35,8 @@
+
+
Implementation of the User Attribute Packet (Tag 17)
@@ -54,74 +56,6 @@ an implementation may use any method desired.
module packet/user_attribute
-
- new (require("packet/user_attribute"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -168,137 +102,23 @@ module packet/user_attribute
-
-
-
-
-
-
- Methods
+ Classes
-
-
- read(input)
-
-
-
-
-
-
-
- parsing function for a user attribute packet (tag 17).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- payload of a tag 17 packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ UserAttribute
+
+
+
+
+
+
+
@@ -309,13 +129,13 @@ module packet/user_attribute
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:54 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/user_attribute.js.html b/doc/user_attribute.js.html
index b7114362..2da88b27 100644
--- a/doc/user_attribute.js.html
+++ b/doc/user_attribute.js.html
@@ -65,27 +65,28 @@
var util = require('../util'),
packet = require('./packet.js');
+module.exports = UserAttribute;
+
/**
* @constructor
*/
-module.exports = function user_attribute() {
- this.tag = 17;
+function UserAttribute() {
this.attributes = [];
+}
- /**
- * parsing function for a user attribute packet (tag 17).
- * @param {String} input payload of a tag 17 packet
- */
- this.read = function(bytes) {
- var i = 0;
- while (i < bytes.length) {
- var len = packet.readSimpleLength(bytes.substr(i));
- i += len.offset;
+/**
+ * parsing function for a user attribute packet (tag 17).
+ * @param {String} input payload of a tag 17 packet
+ */
+UserAttribute.prototype.read = function(bytes) {
+ var i = 0;
+ while (i < bytes.length) {
+ var len = packet.readSimpleLength(bytes.substr(i));
+ i += len.offset;
- this.attributes.push(bytes.substr(i, len.len));
- i += len.len;
- }
- };
+ this.attributes.push(bytes.substr(i, len.len));
+ i += len.len;
+ }
};
@@ -97,13 +98,13 @@ module.exports = function user_attribute() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/userid-Userid.html b/doc/userid-Userid.html
new file mode 100644
index 00000000..dce6c0a0
--- /dev/null
+++ b/doc/userid-Userid.html
@@ -0,0 +1,429 @@
+
+
+
+
+ JSDoc: Class: Userid
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Userid
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ new Userid()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Members
+
+
+
+
+ userid :String
+
+
+
+
+
+
+ A string containing the user id. Usually in the form
+John Doe
+
+
+
+
+ Type:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Methods
+
+
+
+
+ read(input)
+
+
+
+
+
+
+
+ Parsing function for a user id packet (tag 13).
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ input
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+ payload of a tag 13 packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ write() → {String}
+
+
+
+
+
+
+
+ Creates a string representation of the user id packet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+ string representation
+
+
+
+
+
+
+ Type
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Modules Classes
+
+
+
+
+
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/doc/userid.html b/doc/userid.html
index 8cb0ecc9..24661b0b 100644
--- a/doc/userid.html
+++ b/doc/userid.html
@@ -35,6 +35,8 @@
+
+
Implementation of the User ID Packet (Tag 13)
@@ -45,74 +47,6 @@ restrictions on its content. The packet length in the header
specifies the length of the User ID.
-
- new (require("packet/userid"))()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -165,293 +99,19 @@ specifies the length of the User ID.
-
-
-
-
- Members
+ Classes
-
-
- userid :String
-
-
-
-
-
-
- A string containing the user id. Usually in the form
-John Doe
-
-
-
-
- Type:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Userid
+
- Methods
-
-
-
-
- read(input)
-
-
-
- Parsing function for a user id packet (tag 13).
-
-
-
-
-
-
-
-
- Parameters:
-
-
-
-
-
-
- Name
-
-
- Type
-
-
-
-
-
- Description
-
-
-
-
-
-
-
-
- input
-
-
-
-
-
-String
-
-
-
-
-
-
-
-
-
- payload of a tag 13 packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- write() → {String}
-
-
-
-
-
-
-
- Creates a string representation of the user id packet
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Returns:
-
-
-
- string representation
-
-
-
-
-
-
- Type
-
-
-
-String
-
-
-
-
-
-
-
-
-
-
-
-
@@ -466,13 +126,13 @@ John Doe
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:33 GMT+0100 (MEZ)
diff --git a/doc/userid.js.html b/doc/userid.js.html
index 4f13b28b..61ad9d89 100644
--- a/doc/userid.js.html
+++ b/doc/userid.js.html
@@ -54,34 +54,35 @@
* @module packet/userid
*/
+module.exports = Userid;
+
var util = require('../util');
/**
* @constructor
*/
-module.exports = function userid() {
+function Userid() {
/** A string containing the user id. Usually in the form
* John Doe <john@example.com>
* @type {String}
*/
this.userid = '';
+}
+/**
+ * Parsing function for a user id packet (tag 13).
+ * @param {String} input payload of a tag 13 packet
+ */
+Userid.prototype.read = function (bytes) {
+ this.userid = util.decode_utf8(bytes);
+};
- /**
- * Parsing function for a user id packet (tag 13).
- * @param {String} input payload of a tag 13 packet
- */
- this.read = function (bytes) {
- this.userid = util.decode_utf8(bytes);
- };
-
- /**
- * Creates a string representation of the user id packet
- * @return {String} string representation
- */
- this.write = function () {
- return util.encode_utf8(this.userid);
- };
+/**
+ * Creates a string representation of the user id packet
+ * @return {String} string representation
+ */
+Userid.prototype.write = function () {
+ return util.encode_utf8(this.userid);
};
@@ -93,13 +94,13 @@ module.exports = function userid() {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/doc/util.html b/doc/util.html
index 8d42e510..a05b38ac 100644
--- a/doc/util.html
+++ b/doc/util.html
@@ -2000,13 +2000,13 @@ the same as bin2str.
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:55 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:34 GMT+0100 (MEZ)
diff --git a/doc/util.js.html b/doc/util.js.html
index d35d1efa..af3f67b3 100644
--- a/doc/util.js.html
+++ b/doc/util.js.html
@@ -339,13 +339,13 @@ module.exports = {
- Modules Classes
+ Modules Classes
- Documentation generated by JSDoc 3.2.2 on Mon Jan 06 2014 16:27:49 GMT+0100 (MEZ)
+ Documentation generated by JSDoc 3.2.0 on Mon Jan 06 2014 19:29:27 GMT+0100 (MEZ)
diff --git a/example/encryption.html b/example/encryption.html
index 6f22d0cf..a756154e 100644
--- a/example/encryption.html
+++ b/example/encryption.html
@@ -135,13 +135,13 @@ function run(encrypt) {
var sesskey = null;
// Find the private (sub)key for the session key of the message
for (var i = 0; i< msg[0].sessionKeys.length; i++) {
- if (priv_key[0].privateKeyPacket.publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
+ if (priv_key[0].privateKeyPacket.PublicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
keymat = { key: priv_key[0], keymaterial: priv_key[0].privateKeyPacket};
sesskey = msg[0].sessionKeys[i];
break;
}
for (var j = 0; j < priv_key[0].subKeys.length; j++) {
- if (priv_key[0].subKeys[j].publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
+ if (priv_key[0].subKeys[j].PublicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
keymat = { key: priv_key[0], keymaterial: priv_key[0].subKeys[j]};
sesskey = msg[0].sessionKeys[i];
break;
diff --git a/jsdoc.template/publish.js b/jsdoc.template/publish.js
index ad23b506..a2b66856 100644
--- a/jsdoc.template/publish.js
+++ b/jsdoc.template/publish.js
@@ -227,7 +227,7 @@ function buildNav(members) {
if (members.classes.length) {
members.classes.forEach(function(c) {
if ( !hasOwnProp.call(seen, c.longname) ) {
- classNav += ''+linkto(c.longname, c.name)+' ';
+ classNav += ''+linkto(c.longname, c.longname.replace(/^module:/,''))+' ';
}
seen[c.longname] = true;
});
diff --git a/src/cleartext.js b/src/cleartext.js
index e7d8f260..4c1604ae 100644
--- a/src/cleartext.js
+++ b/src/cleartext.js
@@ -31,7 +31,7 @@ var config = require('./config'),
/**
* @class
* @classdesc Class that represents an OpenPGP cleartext signed message.
- * See http://tools.ietf.org/html/rfc4880#section-7
+ * See {@link http://tools.ietf.org/html/rfc4880#section-7}
* @param {String} text The cleartext of the signed message
* @param {module:packet/packetlist} packetlist The packetlist with signature packets or undefined
* if message not yet signed
@@ -43,7 +43,7 @@ function CleartextMessage(text, packetlist) {
}
// normalize EOL to canonical form
this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g,"\r\n");
- this.packets = packetlist || new packet.list();
+ this.packets = packetlist || new packet.List();
}
/**
@@ -64,11 +64,11 @@ CleartextMessage.prototype.getSigningKeyIds = function() {
* @param {Array} privateKeys private keys with decrypted secret key data for signing
*/
CleartextMessage.prototype.sign = function(privateKeys) {
- var packetlist = new packet.list();
- var literalDataPacket = new packet.literal();
+ var packetlist = new packet.List();
+ var literalDataPacket = new packet.Literal();
literalDataPacket.setText(this.text);
for (var i = 0; i < privateKeys.length; i++) {
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = enums.signature.text;
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
var signingKeyPacket = privateKeys[i].getSigningKeyPacket();
@@ -88,7 +88,7 @@ CleartextMessage.prototype.sign = function(privateKeys) {
CleartextMessage.prototype.verify = function(publicKeys) {
var result = [];
var signatureList = this.packets.filterByTag(enums.packet.signature);
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
// we assume that cleartext signature is generated based on UTF8 cleartext
literalDataPacket.setText(this.text);
publicKeys.forEach(function(pubKey) {
@@ -140,7 +140,7 @@ function readArmored(armoredText) {
if (input.type !== enums.armor.signed) {
throw new Error('No cleartext signed message.');
}
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input.data);
var newMessage = new CleartextMessage(input.text, packetlist);
return newMessage;
diff --git a/src/config/localStorage.js b/src/config/localStorage.js
index 7f77e861..fe59fdf3 100644
--- a/src/config/localStorage.js
+++ b/src/config/localStorage.js
@@ -3,29 +3,31 @@
* @module config/localStorage
*/
+module.exports = LocalStorage;
+
/**
* @constructor
*/
-module.exports = function localStorage() {
+function LocalStorage() {
+}
- /**
- * Reads the config out of the HTML5 local storage
- * and initializes the object config.
- * if config is null the default config will be used
- */
- this.read = function () {
- var cf = JSON.parse(window.localStorage.getItem("config"));
- if (cf === null) {
- this.config = this.default_config;
- this.write();
- } else
- this.config = cf;
- };
-
- /**
- * Writes the config to HTML5 local storage
- */
- this.write = function () {
- window.localStorage.setItem("config", JSON.stringify(this.config));
- };
+/**
+ * Reads the config out of the HTML5 local storage
+ * and initializes the object config.
+ * if config is null the default config will be used
+ */
+LocalStorage.prototype.read = function () {
+ var cf = JSON.parse(window.localStorage.getItem("config"));
+ if (cf === null) {
+ this.config = this.default_config;
+ this.write();
+ } else
+ this.config = cf;
+};
+
+/**
+ * Writes the config to HTML5 local storage
+ */
+LocalStorage.prototype.write = function () {
+ window.localStorage.setItem("config", JSON.stringify(this.config));
};
diff --git a/src/crypto/cfb.js b/src/crypto/cfb.js
index 939d7d24..f28218bf 100644
--- a/src/crypto/cfb.js
+++ b/src/crypto/cfb.js
@@ -32,7 +32,7 @@ module.exports = {
* @param {String} prefixrandom random bytes of block_size length provided
* as a string to be used in prefixing the data
* @param {String} cipherfn the algorithm cipher class to encrypt
- * data in one block_size encryption, @see module:crypto/cipher.
+ * data in one block_size encryption, {@link module:crypto/cipher}.
* @param {String} plaintext data to be encrypted provided as a string
* @param {String} key binary string representation of key to be used to encrypt the plaintext.
* This will be passed to the cipherfn
@@ -174,7 +174,7 @@ module.exports = {
* This function decrypts a given plaintext using the specified
* blockcipher to decrypt a message
* @param {String} cipherfn the algorithm cipher class to decrypt
- * data in one block_size encryption, @see module:crypto/cipher.
+ * data in one block_size encryption, {@link module:crypto/cipher}.
* @param {String} key binary string representation of key to be used to decrypt the ciphertext.
* This will be passed to the cipherfn
* @param {String} ciphertext to be decrypted provided as a string
diff --git a/src/crypto/crypto.js b/src/crypto/crypto.js
index d6760ba7..8537123e 100644
--- a/src/crypto/crypto.js
+++ b/src/crypto/crypto.js
@@ -34,7 +34,7 @@ module.exports = {
/**
* Encrypts data using the specified public key multiprecision integers
* and the specified algorithm.
- * @param {Integer} algo Algorithm to be used (See RFC4880 9.1)
+ * @param {module:enums.publicKey} algo Algorithm to be used (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array} publicMPIs Algorithm dependent multiprecision integers
* @param {module:type/mpi} data Data to be encrypted as MPI
* @return {Array} if RSA an module:type/mpi;
@@ -75,7 +75,7 @@ module.exports = {
/**
* Decrypts data using the specified public key multiprecision integers of the private key,
* the specified secretMPIs of the private key and the specified algorithm.
- * @param {Integer} algo Algorithm to be used (See RFC4880 9.1)
+ * @param {module:enums.publicKey} algo Algorithm to be used (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array} publicMPIs Algorithm dependent multiprecision integers
* of the public key part of the private key
* @param {Array} secretMPIs Algorithm dependent multiprecision integers
@@ -207,7 +207,7 @@ module.exports = {
/**
* generate random byte prefix as string for the specified algorithm
- * @param {Integer} algo Algorithm to use (see RFC4880 9.2)
+ * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2})
* @return {String} Random bytes with length equal to the block
* size of the cipher
*/
@@ -217,7 +217,7 @@ module.exports = {
/**
* Generating a session key for the specified symmetric algorithm
- * @param {Integer} algo Algorithm to use (see RFC4880 9.2)
+ * @param {module:enums.symmetric} algo Algorithm to use (see {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2})
* @return {String} Random bytes as a string to be used as a key
*/
generateSessionKey: function(algo) {
diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js
index 7086e037..9dcd6a99 100644
--- a/src/crypto/hash/index.js
+++ b/src/crypto/hash/index.js
@@ -22,7 +22,7 @@ module.exports = {
/**
* Create a hash on the specified data using the specified algorithm
- * @param {Integer} algo Hash algorithm type (see RFC4880 9.4)
+ * @param {module:enums.hash} algo Hash algorithm type (see {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
* @param {String} data Data to be hashed
* @return {String} hash value
*/
@@ -56,7 +56,7 @@ module.exports = {
/**
* Returns the hash size in bytes of the specified hash algorithm type
- * @param {Integer} algo Hash algorithm type (See RFC4880 9.4)
+ * @param {module:enums.hash} algo Hash algorithm type (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
* @return {Integer} Size in bytes of the resulting hash
*/
getHashByteLength: function(algo) {
diff --git a/src/crypto/pkcs1.js b/src/crypto/pkcs1.js
index 330da878..3d70ebe7 100644
--- a/src/crypto/pkcs1.js
+++ b/src/crypto/pkcs1.js
@@ -26,7 +26,7 @@
*/
/**
- * ASN1 object identifiers for hashes (See RFC4880 5.2.2)
+ * ASN1 object identifiers for hashes (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.2})
*/
hash_headers = [];
hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04,
@@ -56,7 +56,7 @@ var crypto = require('./crypto.js'),
module.exports = {
eme: {
/**
- * create a EME-PKCS1-v1_5 padding (See RFC4880 13.1.1)
+ * create a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1})
* @param {String} message message to be padded
* @param {Integer} length Length to the resulting message
* @return {String} EME-PKCS1 padded message
@@ -76,9 +76,9 @@ module.exports = {
},
/**
- * decodes a EME-PKCS1-v1_5 padding (See RFC4880 13.1.2)
+ * decodes a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.2|RFC 4880 13.1.2})
* @param {String} message EME-PKCS1 padded message
- * @return {String} decoded message
+ * @return {String} decoded message
*/
decode: function(message, len) {
if (message.length < len)
@@ -95,7 +95,7 @@ module.exports = {
emsa: {
/**
- * create a EMSA-PKCS1-v1_5 padding (See RFC4880 13.1.3)
+ * create a EMSA-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})
* @param {Integer} algo Hash algorithm type used
* @param {String} data Data to be hashed
* @param {Integer} keylength Key size of the public mpi in bytes
@@ -121,7 +121,7 @@ module.exports = {
},
/**
- * extract the hash out of an EMSA-PKCS1-v1.5 padding (See RFC4880 13.1.3)
+ * extract the hash out of an EMSA-PKCS1-v1.5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})
* @param {String} data Hash in pkcs1 encoding
* @returns {String} The hash as string
*/
diff --git a/src/crypto/signature.js b/src/crypto/signature.js
index 930d7baa..664329be 100644
--- a/src/crypto/signature.js
+++ b/src/crypto/signature.js
@@ -11,8 +11,8 @@ var publicKey = require('./public_key'),
module.exports = {
/**
*
- * @param {Integer} algo public Key algorithm
- * @param {Integer} hash_algo Hash algorithm
+ * @param {module:enums.publicKey} algo public Key algorithm
+ * @param {module:enums.hash} hash_algo Hash algorithm
* @param {Array} msg_MPIs Signature multiprecision integers
* @param {Array} publickey_MPIs Public key multiprecision integers
* @param {String} data Data on where the signature was computed on.
@@ -62,8 +62,8 @@ module.exports = {
/**
* Create a signature on data using the specified algorithm
- * @param {Integer} hash_algo hash Algorithm to use (See RFC4880 9.4)
- * @param {Integer} algo Asymmetric cipher algorithm to use (See RFC4880 9.1)
+ * @param {module:enums.hash} hash_algo hash Algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC 4880 9.4})
+ * @param {module:enums.publicKey} algo Asymmetric cipher algorithm to use (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1})
* @param {Array} publicMPIs Public key multiprecision integers
* of the private key
* @param {Array} secretMPIs Private key multiprecision
diff --git a/src/enums.js b/src/enums.js
index 97ab8f99..f1eb61b1 100644
--- a/src/enums.js
+++ b/src/enums.js
@@ -15,7 +15,7 @@ module.exports = {
gnu: 101
},
- /** RFC4880, section 9.1
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880, section 9.1}
* @enum {Integer}
* @readonly
*/
@@ -27,7 +27,7 @@ module.exports = {
dsa: 17
},
- /** RFC4880, section 9.2
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
* @enum {Integer}
* @readonly
*/
@@ -44,7 +44,7 @@ module.exports = {
twofish: 10
},
- /** RFC4880, section 9.3
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
* @enum {Integer}
* @readonly
*/
@@ -57,7 +57,7 @@ module.exports = {
bzip2: 3
},
- /** RFC4880, section 9.4
+ /** {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
* @enum {Integer}
* @readonly
*/
@@ -76,23 +76,23 @@ module.exports = {
* @readonly
*/
packet: {
- public_key_encrypted_session_key: 1,
+ publicKeyEncryptedSessionKey: 1,
signature: 2,
- sym_encrypted_session_key: 3,
- one_pass_signature: 4,
- secret_key: 5,
- public_key: 6,
- secret_subkey: 7,
+ symEncryptedSessionKey: 3,
+ onePassSignature: 4,
+ secretKey: 5,
+ publicKey: 6,
+ secretSubkey: 7,
compressed: 8,
- symmetrically_encrypted: 9,
+ symmetricallyEncrypted: 9,
marker: 10,
literal: 11,
trust: 12,
userid: 13,
- public_subkey: 14,
- user_attribute: 17,
- sym_encrypted_integrity_protected: 18,
- modification_detection_code: 19
+ publicSubkey: 14,
+ userAttribute: 17,
+ symEncryptedIntegrityProtected: 18,
+ modificationDetectionCode: 19
},
/** Data types in the literal packet
diff --git a/src/key.js b/src/key.js
index ddea303e..9bf95f89 100644
--- a/src/key.js
+++ b/src/key.js
@@ -59,19 +59,19 @@ Key.prototype.packetlist2structure = function(packetlist) {
var user, primaryKeyId, subKey;
for (var i = 0; i < packetlist.length; i++) {
switch (packetlist[i].tag) {
- case enums.packet.public_key:
- case enums.packet.secret_key:
+ case enums.packet.publicKey:
+ case enums.packet.secretKey:
this.primaryKey = packetlist[i];
primaryKeyId = this.primaryKey.getKeyId();
break;
case enums.packet.userid:
- case enums.packet.user_attribute:
+ case enums.packet.userAttribute:
user = new User(packetlist[i]);
if (!this.users) this.users = [];
this.users.push(user);
break;
- case enums.packet.public_subkey:
- case enums.packet.secret_subkey:
+ case enums.packet.publicSubkey:
+ case enums.packet.secretSubkey:
user = null;
if (!this.subKeys) this.subKeys = [];
subKey = new SubKey(packetlist[i]);
@@ -124,7 +124,7 @@ Key.prototype.packetlist2structure = function(packetlist) {
* @return {module:packet/packetlist} The packets that form a key
*/
Key.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.primaryKey);
packetlist.push(this.revocationSignature);
packetlist.concat(this.directSignatures);
@@ -201,7 +201,7 @@ function findKey(keys, keyIds) {
* @return {(module:packet/public_subkey|module:packet/public_key|null)}
*/
Key.prototype.getPublicKeyPacket = function(keyIds) {
- if (this.primaryKey.tag == enums.packet.public_key) {
+ if (this.primaryKey.tag == enums.packet.publicKey) {
return findKey(this.getAllKeyPackets(), keyIds);
} else {
return null;
@@ -214,7 +214,7 @@ Key.prototype.getPublicKeyPacket = function(keyIds) {
* @return {(module:packet/secret_subkey|module:packet/secret_key|null)}
*/
Key.prototype.getPrivateKeyPacket = function(keyIds) {
- if (this.primaryKey.tag == enums.packet.secret_key) {
+ if (this.primaryKey.tag == enums.packet.secretKey) {
return findKey(this.getAllKeyPackets(), keyIds);
} else {
return null;
@@ -240,7 +240,7 @@ Key.prototype.getUserIds = function() {
* @return {Boolean}
*/
Key.prototype.isPublic = function() {
- return this.primaryKey.tag == enums.packet.public_key;
+ return this.primaryKey.tag == enums.packet.publicKey;
};
/**
@@ -248,7 +248,7 @@ Key.prototype.isPublic = function() {
* @return {Boolean}
*/
Key.prototype.isPrivate = function() {
- return this.primaryKey.tag == enums.packet.secret_key;
+ return this.primaryKey.tag == enums.packet.secretKey;
};
/**
@@ -256,20 +256,20 @@ Key.prototype.isPrivate = function() {
* @return {module:key~Key} new public Key
*/
Key.prototype.toPublic = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
var keyPackets = this.toPacketlist();
var bytes;
for (var i = 0; i < keyPackets.length; i++) {
switch (keyPackets[i].tag) {
- case enums.packet.secret_key:
+ case enums.packet.secretKey:
bytes = keyPackets[i].writePublicKey();
- var pubKeyPacket = new packet.public_key();
+ var pubKeyPacket = new packet.PublicKey();
pubKeyPacket.read(bytes);
packetlist.push(pubKeyPacket);
break;
- case enums.packet.secret_subkey:
+ case enums.packet.secretSubkey:
bytes = keyPackets[i].writePublicKey();
- var pubSubkeyPacket = new packet.public_subkey();
+ var pubSubkeyPacket = new packet.PublicSubkey();
pubSubkeyPacket.read(bytes);
packetlist.push(pubSubkeyPacket);
break;
@@ -423,7 +423,7 @@ Key.prototype.verifyPrimaryKey = function() {
return enums.keyStatus.expired;
}
// check for at least one self signature. Self signature of user ID not mandatory
- // See http://tools.ietf.org/html/rfc4880#section-11.1
+ // See {@link http://tools.ietf.org/html/rfc4880#section-11.1}
var selfSigned = false;
for (var i = 0; i < this.users.length; i++) {
if (this.users[i].userId && this.users[i].selfCertifications) {
@@ -487,7 +487,7 @@ function User(userPacket) {
return new User(userPacket);
}
this.userId = userPacket.tag == enums.packet.userid ? userPacket : null;
- this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null;
+ this.userAttribute = userPacket.tag == enums.packet.userAttribute ? userPacket : null;
this.selfCertifications = null;
this.otherCertifications = null;
this.revocationCertifications = null;
@@ -498,7 +498,7 @@ function User(userPacket) {
* @return {module:packet/packetlist}
*/
User.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.userId || this.userAttribute);
packetlist.concat(this.revocationCertifications);
packetlist.concat(this.selfCertifications);
@@ -604,7 +604,7 @@ function SubKey(subKeyPacket) {
* @return {module:packet/packetlist}
*/
SubKey.prototype.toPacketlist = function() {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.push(this.subKey);
packetlist.push(this.revocationSignature);
packetlist.push(this.bindingSignature);
@@ -682,9 +682,9 @@ function readArmored(armoredText) {
if (!(input.type == enums.armor.public_key || input.type == enums.armor.private_key)) {
throw new Error('Armored text not of type key');
}
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input.data);
- var keyIndex = packetlist.indexOfTag(enums.packet.public_key, enums.packet.secret_key);
+ var keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
if (keyIndex.length === 0) {
throw new Error('No key packet found in armored text');
}
@@ -708,8 +708,8 @@ function readArmored(armoredText) {
/**
* Generates a new OpenPGP key. Currently only supports RSA keys.
* Primary and subkey will be of same type.
- * @param {Integer} keyType to indicate what type of key to make.
- * RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ * @param {module:enums.publicKey} keyType to indicate what type of key to make.
+ * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1}
* @param {Integer} numBits number of bits for the key creation.
* @param {String} userId assumes already in form of "User Name "
* @param {String} passphrase The passphrase used to encrypt the resulting private key
@@ -717,20 +717,20 @@ function readArmored(armoredText) {
* @static
*/
function generate(keyType, numBits, userId, passphrase) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
- var secretKeyPacket = new packet.secret_key();
+ var secretKeyPacket = new packet.SecretKey();
secretKeyPacket.algorithm = enums.read(enums.publicKey, keyType);
secretKeyPacket.generate(numBits);
secretKeyPacket.encrypt(passphrase);
- var userIdPacket = new packet.userid();
+ var userIdPacket = new packet.Userid();
userIdPacket.read(userId);
var dataToSign = {};
dataToSign.userid = userIdPacket;
dataToSign.key = secretKeyPacket;
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = enums.signature.cert_generic;
signaturePacket.publicKeyAlgorithm = keyType;
//TODO we should load preferred hash from config, or as input to this function
@@ -738,7 +738,7 @@ function generate(keyType, numBits, userId, passphrase) {
signaturePacket.keyFlags = [enums.keyFlags.certify_keys | enums.keyFlags.sign_data];
signaturePacket.sign(secretKeyPacket, dataToSign);
- var secretSubkeyPacket = new packet.secret_subkey();
+ var secretSubkeyPacket = new packet.SecretSubkey();
secretSubkeyPacket.algorithm = enums.read(enums.publicKey, keyType);
secretSubkeyPacket.generate(numBits);
secretSubkeyPacket.encrypt(passphrase);
@@ -746,7 +746,7 @@ function generate(keyType, numBits, userId, passphrase) {
dataToSign = {};
dataToSign.key = secretKeyPacket;
dataToSign.bind = secretSubkeyPacket;
- var subkeySignaturePacket = new packet.signature();
+ var subkeySignaturePacket = new packet.Signature();
subkeySignaturePacket.signatureType = enums.signature.subkey_binding;
subkeySignaturePacket.publicKeyAlgorithm = keyType;
//TODO we should load preferred hash from config, or as input to this function
diff --git a/src/keyring/keyring.js b/src/keyring/keyring.js
index 22f33db3..8876da6d 100644
--- a/src/keyring/keyring.js
+++ b/src/keyring/keyring.js
@@ -31,160 +31,159 @@ var openpgp = require('openpgp');
* @return {Boolean} True if the input matches the specified key
*/
-/**
+module.exports = Keyring;
+
+ /**
* Initialization routine for the keyring. This method reads the
* keyring from HTML5 local storage and initializes this instance.
* @constructor
* @param {class} [storeHandler] class implementing load() and store() methods
*/
-module.exports = function(storeHandler) {
- if (!storeHandler) {
- storeHandler = new (require('./localstore.js'))();
- }
- this.storeHandler = storeHandler;
+function Keyring(storeHandler) {
+ this.storeHandler = storeHandler || new (require('./localstore.js'))();
this.keys = this.storeHandler.load();
-
- /**
- * Calls the storeHandler to save the keys
- */
- this.store = function () {
- this.storeHandler.store(this.keys);
- };
-
- /**
- * Clear the keyring - erase all the keys
- */
- this.clear = function() {
- this.keys = [];
- };
-
- /**
- * Checks a key to see if it matches the specified email address
- * @param {String} email email address to search for
- * @param {module:key~Key} key The key to be checked.
- * @return {Boolean} True if the email address is defined in the specified key
- */
- function emailCheck(email, key) {
- email = email.toLowerCase();
- var keyEmails = key.getUserIds();
- for (var i; i < keyEmails.length; i++) {
- //we need to get just the email from the userid key
- keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();
- if (keyEmail == email) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Checks a key to see if it matches the specified keyid
- * @param {String} id hex string keyid to search for
- * @param {module:key~Key} key the key to be checked.
- * @return {Boolean} true if the email address is defined in the specified key
- * @inner
- */
- function idCheck(id, key) {
- var keyids = key.getKeyIds();
- for (var i = 0; i < keyids.length; i++) {
- if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * searches all public keys in the keyring matching the address or address part of the user ids
- * @param {Array} keys array of keys to search
- * @param {module:keyring/keyring.checkCallback} identityFunction callback function which checks for a match
- * @param {String} identityInput input to check against
- * @param {module:enums.packet} keyType packet types of keys to check
- * @return {Array} array of keys which match
- */
- function checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) {
- var results = [];
- for (var p = 0; p < keys.length; p++) {
- var key = keys[p];
- switch (keyType) {
- case openpgp.enums.packet.public_key:
- if (key.isPublic() && identityFunction(identityInput, key)) {
- results.push(key);
- }
- break;
- case openpgp.enums.packet.private_key:
- if (key.isPrivate() && identityFunction(identityInput, key)) {
- results.push(key);
- }
- break;
- }
- }
- return results;
- }
-
- /**
- * searches all public keys in the keyring matching the address or address part of the user ids
- * @param {String} email email address to search for
- * @return {Array} The public keys associated with provided email address.
- */
- this.getPublicKeyForAddress = function (email) {
- return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.public_key);
- };
-
- /**
- * Searches the keyring for a private key containing the specified email address
- * @param {String} email email address to search for
- * @return {Array} private keys found
- */
- this.getPrivateKeyForAddress = function (email) {
- return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secret_key);
- };
-
- /**
- * Searches the keyring for public keys having the specified key id
- * @param {String} keyId provided as string of hex number (lowercase)
- * @return {Array} public keys found
- */
- this.getKeysForKeyId = function (keyId) {
- return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.public_key);
- };
-
- /**
- * Imports a key from an ascii armored message
- * @param {String} armored message to read the keys/key from
- */
- this.importKey = function (armored) {
- this.keys = this.keys.concat(openpgp.key.readArmored(armored).keys);
-
- return true;
- };
-
- /**
- * returns the armored message representation of the key at key ring index
- * @param {Integer} index the index of the key within the array
- * @return {String} armored message representing the key object
- */
- this.exportKey = function (index) {
- return this.keys[index].armor();
- };
-
- /**
- * Removes a public key from the public key keyring at the specified index
- * @param {Integer} index the index of the public key within the publicKeys array
- * @return {module:key~Key} The public key object which has been removed
- */
- this.removeKey = function (index) {
- var removed = this.keys.splice(index, 1);
-
- return removed;
- };
-
- /**
- * returns the armored message representation of the public key portion of the key at key ring index
- * @param {Integer} index the index of the key within the array
- * @return {String} armored message representing the public key object
- */
- this.exportPublicKey = function (index) {
- return this.keys[index].toPublic().armor();
- };
+};
+
+/**
+ * Calls the storeHandler to save the keys
+ */
+Keyring.prototype.store = function () {
+ this.storeHandler.store(this.keys);
+};
+
+/**
+ * Clear the keyring - erase all the keys
+ */
+Keyring.prototype.clear = function() {
+ this.keys = [];
+};
+
+/**
+ * Checks a key to see if it matches the specified email address
+ * @param {String} email email address to search for
+ * @param {module:key~Key} key The key to be checked.
+ * @return {Boolean} True if the email address is defined in the specified key
+ */
+function emailCheck(email, key) {
+ email = email.toLowerCase();
+ var keyEmails = key.getUserIds();
+ for (var i; i < keyEmails.length; i++) {
+ //we need to get just the email from the userid key
+ keyEmail = keyEmails[i].split('<')[1].split('>')[0].trim().toLowerCase();
+ if (keyEmail == email) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Checks a key to see if it matches the specified keyid
+ * @param {String} id hex string keyid to search for
+ * @param {module:key~Key} key the key to be checked.
+ * @return {Boolean} true if the email address is defined in the specified key
+ * @inner
+ */
+function idCheck(id, key) {
+ var keyids = key.getKeyIds();
+ for (var i = 0; i < keyids.length; i++) {
+ if (openpgp.util.hexstrdump(keyids[i].write()) == id) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * searches all public keys in the keyring matching the address or address part of the user ids
+ * @param {Array} keys array of keys to search
+ * @param {module:keyring/keyring.checkCallback} identityFunction callback function which checks for a match
+ * @param {String} identityInput input to check against
+ * @param {module:enums.packet} keyType packet types of keys to check
+ * @return {Array} array of keys which match
+ */
+function checkForIdentityAndKeyTypeMatch(keys, identityFunction, identityInput, keyType) {
+ var results = [];
+ for (var p = 0; p < keys.length; p++) {
+ var key = keys[p];
+ switch (keyType) {
+ case openpgp.enums.packet.publicKey:
+ if (key.isPublic() && identityFunction(identityInput, key)) {
+ results.push(key);
+ }
+ break;
+ case openpgp.enums.packet.private_key:
+ if (key.isPrivate() && identityFunction(identityInput, key)) {
+ results.push(key);
+ }
+ break;
+ }
+ }
+ return results;
+}
+
+/**
+ * searches all public keys in the keyring matching the address or address part of the user ids
+ * @param {String} email email address to search for
+ * @return {Array} The public keys associated with provided email address.
+ */
+Keyring.prototype.getPublicKeyForAddress = function (email) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.publicKey);
+};
+
+/**
+ * Searches the keyring for a private key containing the specified email address
+ * @param {String} email email address to search for
+ * @return {Array} private keys found
+ */
+Keyring.prototype.getPrivateKeyForAddress = function (email) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, emailCheck, email, openpgp.enums.packet.secretKey);
+};
+
+/**
+ * Searches the keyring for public keys having the specified key id
+ * @param {String} keyId provided as string of hex number (lowercase)
+ * @return {Array} public keys found
+ */
+Keyring.prototype.getKeysForKeyId = function (keyId) {
+ return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.publicKey);
+};
+
+/**
+ * Imports a key from an ascii armored message
+ * @param {String} armored message to read the keys/key from
+ */
+Keyring.prototype.importKey = function (armored) {
+ this.keys = this.keys.concat(openpgp.key.readArmored(armored).keys);
+
+ return true;
+};
+
+/**
+ * returns the armored message representation of the key at key ring index
+ * @param {Integer} index the index of the key within the array
+ * @return {String} armored message representing the key object
+ */
+Keyring.prototype.exportKey = function (index) {
+ return this.keys[index].armor();
+};
+
+/**
+ * Removes a public key from the public key keyring at the specified index
+ * @param {Integer} index the index of the public key within the publicKeys array
+ * @return {module:key~Key} The public key object which has been removed
+ */
+Keyring.prototype.removeKey = function (index) {
+ var removed = this.keys.splice(index, 1);
+
+ return removed;
+};
+
+/**
+ * returns the armored message representation of the public key portion of the key at key ring index
+ * @param {Integer} index the index of the key within the array
+ * @return {String} armored message representing the public key object
+ */
+Keyring.prototype.exportPublicKey = function (index) {
+ return this.keys[index].toPublic().armor();
};
diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js
index 4fc1fd8b..c9c18411 100644
--- a/src/keyring/localstore.js
+++ b/src/keyring/localstore.js
@@ -20,37 +20,39 @@
* @requires openpgp
* @module keyring/localstore
*/
+module.exports = LocalStore;
var openpgp = require('openpgp');
-module.exports = function () {
- /**
- * Load the keyring from HTML5 local storage and initializes this instance.
- * @return {Array} array of keys retrieved from localstore
- */
- this.load = function () {
- var armoredKeys = JSON.parse(window.localStorage.getItem("armoredKeys"));
- var keys = [];
- if (armoredKeys !== null && armoredKeys.length !== 0) {
- var key;
- for (var i = 0; i < armoredKeys.length; i++) {
- key = openpgp.key.readArmored(armoredKeys[i]);
- keys.push(key);
- }
- }
- return keys;
- };
+function LocalStore() {
+}
- /**
- * Saves the current state of the keyring to HTML5 local storage.
- * The privateKeys array and publicKeys array gets Stringified using JSON
- * @param {Array} keys array of keys to save in localstore
- */
- this.store = function (keys) {
- var armoredKeys = [];
- for (var i = 0; i < keys.length; i++) {
- armoredKeys.push(keys[i].armor());
+/**
+ * Load the keyring from HTML5 local storage and initializes this instance.
+ * @return {Array} array of keys retrieved from localstore
+ */
+LocalStore.prototype.load = function () {
+ var armoredKeys = JSON.parse(window.localStorage.getItem("armoredKeys"));
+ var keys = [];
+ if (armoredKeys !== null && armoredKeys.length !== 0) {
+ var key;
+ for (var i = 0; i < armoredKeys.length; i++) {
+ key = openpgp.key.readArmored(armoredKeys[i]);
+ keys.push(key);
}
- window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
- };
+ }
+ return keys;
+};
+
+/**
+ * Saves the current state of the keyring to HTML5 local storage.
+ * The privateKeys array and publicKeys array gets Stringified using JSON
+ * @param {Array} keys array of keys to save in localstore
+ */
+LocalStore.prototype.store = function (keys) {
+ var armoredKeys = [];
+ for (var i = 0; i < keys.length; i++) {
+ armoredKeys.push(keys[i].armor());
+ }
+ window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
};
diff --git a/src/message.js b/src/message.js
index f2c9dfae..7fee348c 100644
--- a/src/message.js
+++ b/src/message.js
@@ -35,14 +35,14 @@ var packet = require('./packet'),
* @classdesc Class that represents an OpenPGP message.
* Can be an encrypted message, signed message, compressed message or literal message
* @param {module:packet/packetlist} packetlist The packets that form this message
- * See http://tools.ietf.org/html/rfc4880#section-11.3
+ * See {@link http://tools.ietf.org/html/rfc4880#section-11.3}
*/
function Message(packetlist) {
if (!(this instanceof Message)) {
return new Message(packetlist);
}
- this.packets = packetlist || new packet.list();
+ this.packets = packetlist || new packet.List();
}
/**
@@ -51,7 +51,7 @@ function Message(packetlist) {
*/
Message.prototype.getEncryptionKeyIds = function() {
var keyIds = [];
- var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
+ var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
pkESKeyPacketlist.forEach(function(packet) {
keyIds.push(packet.publicKeyId);
});
@@ -66,7 +66,7 @@ Message.prototype.getSigningKeyIds = function() {
var keyIds = [];
var msg = this.unwrapCompressed();
// search for one pass signatures
- var onePassSigList = msg.packets.filterByTag(enums.packet.one_pass_signature);
+ var onePassSigList = msg.packets.filterByTag(enums.packet.onePassSignature);
onePassSigList.forEach(function(packet) {
keyIds.push(packet.signingKeyId);
});
@@ -93,7 +93,7 @@ Message.prototype.decrypt = function(privateKey) {
}
var privateKeyPacket = privateKey.getPrivateKeyPacket(encryptionKeyIds);
if (!privateKeyPacket.isDecrypted) throw new Error('Private key is not decrypted.');
- var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
+ var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.publicKeyEncryptedSessionKey);
var pkESKeyPacket;
for (var i = 0; i < pkESKeyPacketlist.length; i++) {
if (pkESKeyPacketlist[i].publicKeyId.equals(privateKeyPacket.getKeyId())) {
@@ -103,7 +103,7 @@ Message.prototype.decrypt = function(privateKey) {
}
}
if (pkESKeyPacket) {
- var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetrically_encrypted, enums.packet.sym_encrypted_integrity_protected);
+ var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetricallyEncrypted, enums.packet.symEncryptedIntegrityProtected);
if (symEncryptedPacketlist.length !== 0) {
var symEncryptedPacket = symEncryptedPacketlist[0];
symEncryptedPacket.decrypt(pkESKeyPacket.sessionKeyAlgorithm, pkESKeyPacket.sessionKey);
@@ -140,13 +140,13 @@ Message.prototype.getText = function() {
* @return {Array} new message with encrypted content
*/
Message.prototype.encrypt = function(keys) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
//TODO get preferred algo from signature
var sessionKey = crypto.generateSessionKey(enums.read(enums.symmetric, config.encryption_cipher));
keys.forEach(function(key) {
var encryptionKeyPacket = key.getEncryptionKeyPacket();
if (encryptionKeyPacket) {
- var pkESKeyPacket = new packet.public_key_encrypted_session_key();
+ var pkESKeyPacket = new packet.PublicKeyEncryptedSessionKey();
pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId();
pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm;
pkESKeyPacket.sessionKey = sessionKey;
@@ -160,9 +160,9 @@ Message.prototype.encrypt = function(keys) {
});
var symEncryptedPacket;
if (config.integrity_protect) {
- symEncryptedPacket = new packet.sym_encrypted_integrity_protected();
+ symEncryptedPacket = new packet.SymEncryptedIntegrityProtected();
} else {
- symEncryptedPacket = new packet.symmetrically_encrypted();
+ symEncryptedPacket = new packet.SymmetricallyEncrypted();
}
symEncryptedPacket.packets = this.packets;
//TODO get preferred algo from signature
@@ -178,7 +178,7 @@ Message.prototype.encrypt = function(keys) {
*/
Message.prototype.sign = function(privateKeys) {
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
var literalDataPacket = this.packets.findPacket(enums.packet.literal);
if (!literalDataPacket) throw new Error('No literal data packet to sign.');
@@ -188,7 +188,7 @@ Message.prototype.sign = function(privateKeys) {
enums.signature.binary : enums.signature.text;
var i;
for (i = 0; i < privateKeys.length; i++) {
- var onePassSig = new packet.one_pass_signature();
+ var onePassSig = new packet.OnePassSignature();
onePassSig.type = signatureType;
//TODO get preferred hashg algo from key signature
onePassSig.hashAlgorithm = config.prefer_hash_algorithm;
@@ -204,7 +204,7 @@ Message.prototype.sign = function(privateKeys) {
packetlist.push(literalDataPacket);
for (i = privateKeys.length - 1; i >= 0; i--) {
- var signaturePacket = new packet.signature();
+ var signaturePacket = new packet.Signature();
signaturePacket.signatureType = signatureType;
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
@@ -273,7 +273,7 @@ function readArmored(armoredText) {
//TODO how do we want to handle bad text? Exception throwing
//TODO don't accept non-message armored texts
var input = armor.decode(armoredText).data;
- var packetlist = new packet.list();
+ var packetlist = new packet.List();
packetlist.read(input);
var newMessage = new Message(packetlist);
return newMessage;
@@ -286,10 +286,10 @@ function readArmored(armoredText) {
* @static
*/
function fromText(text) {
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
// text will be converted to UTF8
literalDataPacket.setText(text);
- var literalDataPacketlist = new packet.list();
+ var literalDataPacketlist = new packet.List();
literalDataPacketlist.push(literalDataPacket);
var newMessage = new Message(literalDataPacketlist);
return newMessage;
@@ -302,9 +302,9 @@ function fromText(text) {
* @static
*/
function fromBinary(bytes) {
- var literalDataPacket = new packet.literal();
+ var literalDataPacket = new packet.Literal();
literalDataPacket.setBytes(bytes, enums.read(enums.literal, enums.literal.binary));
- var literalDataPacketlist = new packet.list();
+ var literalDataPacketlist = new packet.List();
literalDataPacketlist.push(literalDataPacket);
var newMessage = new Message(literalDataPacketlist);
return newMessage;
diff --git a/src/openpgp.js b/src/openpgp.js
index a3308eac..8fa44259 100644
--- a/src/openpgp.js
+++ b/src/openpgp.js
@@ -138,8 +138,8 @@ function verifyClearSignedMessage(publicKeys, message) {
/**
* Generates a new OpenPGP key pair. Currently only supports RSA keys.
* Primary and subkey will be of same type.
- * @param {Integer} keyType to indicate what type of key to make.
- * RSA is 1. See http://tools.ietf.org/html/rfc4880#section-9.1
+ * @param {module:enums.publicKey} keyType to indicate what type of key to make.
+ * RSA is 1. See {@link http://tools.ietf.org/html/rfc4880#section-9.1}
* @param {Integer} numBits number of bits for the key creation. (should be 1024+, generally)
* @param {String} userId assumes already in form of "User Name "
* @param {String} passphrase The passphrase used to encrypt the resulting private key
diff --git a/src/packet/all_packets.js b/src/packet/all_packets.js
index c85c7851..9f743830 100644
--- a/src/packet/all_packets.js
+++ b/src/packet/all_packets.js
@@ -8,41 +8,58 @@ var enums = require('../enums.js');
module.exports = {
/** @see module:packet/compressed */
- compressed: require('./compressed.js'),
+ Compressed: require('./compressed.js'),
/** @see module:packet/sym_encrypted_integrity_protected */
- sym_encrypted_integrity_protected: require('./sym_encrypted_integrity_protected.js'),
+ SymEncryptedIntegrityProtected: require('./sym_encrypted_integrity_protected.js'),
/** @see module:packet/public_key_encrypted_session_key */
- public_key_encrypted_session_key: require('./public_key_encrypted_session_key.js'),
+ PublicKeyEncryptedSessionKey: require('./public_key_encrypted_session_key.js'),
/** @see module:packet/sym_encrypted_session_key */
- sym_encrypted_session_key: require('./sym_encrypted_session_key.js'),
+ SymEncryptedSessionKey: require('./sym_encrypted_session_key.js'),
/** @see module:packet/literal */
- literal: require('./literal.js'),
+ Literal: require('./literal.js'),
/** @see module:packet/public_key */
- public_key: require('./public_key.js'),
+ PublicKey: require('./public_key.js'),
/** @see module:packet/symmetrically_encrypted */
- symmetrically_encrypted: require('./symmetrically_encrypted.js'),
+ SymmetricallyEncrypted: require('./symmetrically_encrypted.js'),
/** @see module:packet/marker */
- marker: require('./marker.js'),
+ Marker: require('./marker.js'),
/** @see module:packet/public_subkey */
- public_subkey: require('./public_subkey.js'),
+ PublicSubkey: require('./public_subkey.js'),
/** @see module:packet/user_attribute */
- user_attribute: require('./user_attribute.js'),
+ UserAttribute: require('./user_attribute.js'),
/** @see module:packet/one_pass_signature */
- one_pass_signature: require('./one_pass_signature.js'),
+ OnePassSignature: require('./one_pass_signature.js'),
/** @see module:packet/secret_key */
- secret_key: require('./secret_key.js'),
+ SecretKey: require('./secret_key.js'),
/** @see module:packet/userid */
- userid: require('./userid.js'),
+ Userid: require('./userid.js'),
/** @see module:packet/secret_subkey */
- secret_subkey: require('./secret_subkey.js'),
+ SecretSubkey: require('./secret_subkey.js'),
/** @see module:packet/signature */
- signature: require('./signature.js'),
+ Signature: require('./signature.js'),
/** @see module:packet/trust */
- trust: require('./trust.js')
+ Trust: require('./trust.js'),
+ /**
+ * Allocate a new packet
+ * @param {String} tag property name from {@link module:enums.packet}
+ * @returns {Object} new packet object with type based on tag
+ */
+ newPacketFromTag: function (tag) {
+ return new this[packetClassFromTagName(tag)]();
+ }
};
+/**
+ * Convert tag name to class name
+ * @param {String} tag property name from {@link module:enums.packet}
+ * @returns {String}
+ */
+function packetClassFromTagName(tag) {
+ return tag.substr(0, 1).toUpperCase() + tag.substr(1);
+}
+
for (var i in enums.packet) {
- var packetClass = module.exports[i];
+ var packetClass = module.exports[packetClassFromTagName(i)];
if (packetClass !== undefined)
packetClass.prototype.tag = enums.packet[i];
diff --git a/src/packet/compressed.js b/src/packet/compressed.js
index 53edb353..3b80e9ba 100644
--- a/src/packet/compressed.js
+++ b/src/packet/compressed.js
@@ -18,7 +18,7 @@
/**
* Implementation of the Compressed Data Packet (Tag 8)
*
- * RFC4880 5.6: The Compressed Data packet contains compressed data. Typically,
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.6|RFC4880 5.6}: The Compressed Data packet contains compressed data. Typically,
* this packet is found as the contents of an encrypted packet, or following
* a Signature or One-Pass Signature packet, and contains a literal data packet.
* @requires compression/jxg
@@ -27,6 +27,8 @@
* @module packet/compressed
*/
+module.exports = Compressed;
+
var enums = require('../enums.js'),
JXG = require('../compression/jxg.js'),
base64 = require('../encoding/base64.js');
@@ -34,7 +36,7 @@ var enums = require('../enums.js'),
/**
* @constructor
*/
-module.exports = function compressed() {
+function Compressed() {
/**
* List of packets
* @type {module:packet/packetlist}
@@ -51,118 +53,117 @@ module.exports = function compressed() {
* @type {String}
*/
this.compressed = null;
+}
+/**
+ * Parsing function for the packet.
+ * @param {String} bytes Payload of a tag 8 packet
+ */
+Compressed.prototype.read = function (bytes) {
+ // One octet that gives the algorithm used to compress the packet.
+ this.algorithm = enums.read(enums.compression, bytes.charCodeAt(0));
- /**
- * Parsing function for the packet.
- * @param {String} bytes Payload of a tag 8 packet
- */
- this.read = function(bytes) {
- // One octet that gives the algorithm used to compress the packet.
- this.algorithm = enums.read(enums.compression, bytes.charCodeAt(0));
+ // Compressed data, which makes up the remainder of the packet.
+ this.compressed = bytes.substr(1);
- // Compressed data, which makes up the remainder of the packet.
- this.compressed = bytes.substr(1);
-
- this.decompress();
- };
-
-
-
- /**
- * Return the compressed packet.
- * @return {String} binary compressed packet
- */
- this.write = function() {
- if (this.compressed === null)
- this.compress();
-
- return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
- };
-
-
- /**
- * Decompression method for decompressing the compressed data
- * read by read_packet
- */
- this.decompress = function() {
- var decompressed, compdata, radix;
-
- switch (this.algorithm) {
- case 'uncompressed':
- decompressed = this.compressed;
- break;
-
- case 'zip':
- compData = this.compressed;
-
- radix = base64.encode(compData).replace(/\n/g, "");
- // no header in this case, directly call deflate
- var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
-
- decompressed = unescape(jxg_obj.deflate()[0][0]);
- break;
-
- case 'zlib':
- //RFC 1950. Bits 0-3 Compression Method
- var compressionMethod = this.compressed.charCodeAt(0) % 0x10;
-
- //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size.
- // 2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary
- // (how is this defined). Basic checksum, and compression level.
-
- if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
- // remove 4 bytes ADLER32 checksum from the end
- compData = this.compressed.substring(0, this.compressed.length - 4);
- radix = base64.encode(compData).replace(/\n/g, "");
- //TODO check ADLER32 checksum
- decompressed = JXG.decompress(radix);
- break;
-
- } else {
- throw new Error("Compression algorithm ZLIB only supports " +
- "DEFLATE compression method.");
- }
- break;
-
- case 'bzip2':
- // TODO: need to implement this
- throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
-
- default:
- throw new Error("Compression algorithm unknown :" + this.alogrithm);
- }
-
- this.packets.read(decompressed);
- };
-
- /**
- * Compress the packet data (member decompressedData)
- */
- this.compress = function() {
- switch (this.algorithm) {
-
- case 'uncompressed':
- // - Uncompressed
- this.compressed = this.packets.write();
- break;
-
- case 'zip':
- // - ZIP [RFC1951]
- throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
-
- case 'zlib':
- // - ZLIB [RFC1950]
- // TODO: need to implement this
- throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
-
- case 'bzip2':
- // - BZip2 [BZ2]
- // TODO: need to implement this
- throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
-
- default:
- throw new Error("Compression algorithm unknown :" + this.type);
- }
- };
+ this.decompress();
+};
+
+
+
+/**
+ * Return the compressed packet.
+ * @return {String} binary compressed packet
+ */
+Compressed.prototype.write = function () {
+ if (this.compressed === null)
+ this.compress();
+
+ return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
+};
+
+
+/**
+ * Decompression method for decompressing the compressed data
+ * read by read_packet
+ */
+Compressed.prototype.decompress = function () {
+ var decompressed, compdata, radix;
+
+ switch (this.algorithm) {
+ case 'uncompressed':
+ decompressed = this.compressed;
+ break;
+
+ case 'zip':
+ compData = this.compressed;
+
+ radix = base64.encode(compData).replace(/\n/g, "");
+ // no header in this case, directly call deflate
+ var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
+
+ decompressed = unescape(jxg_obj.deflate()[0][0]);
+ break;
+
+ case 'zlib':
+ //RFC 1950. Bits 0-3 Compression Method
+ var compressionMethod = this.compressed.charCodeAt(0) % 0x10;
+
+ //Bits 4-7 RFC 1950 are LZ77 Window. Generally this value is 7 == 32k window size.
+ // 2nd Byte in RFC 1950 is for "FLAGs" Allows for a Dictionary
+ // (how is this defined). Basic checksum, and compression level.
+
+ if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
+ // remove 4 bytes ADLER32 checksum from the end
+ compData = this.compressed.substring(0, this.compressed.length - 4);
+ radix = base64.encode(compData).replace(/\n/g, "");
+ //TODO check ADLER32 checksum
+ decompressed = JXG.decompress(radix);
+ break;
+
+ } else {
+ throw new Error("Compression algorithm ZLIB only supports " +
+ "DEFLATE compression method.");
+ }
+ break;
+
+ case 'bzip2':
+ // TODO: need to implement this
+ throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
+
+ default:
+ throw new Error("Compression algorithm unknown :" + this.alogrithm);
+ }
+
+ this.packets.read(decompressed);
+};
+
+/**
+ * Compress the packet data (member decompressedData)
+ */
+Compressed.prototype.compress = function () {
+ switch (this.algorithm) {
+
+ case 'uncompressed':
+ // - Uncompressed
+ this.compressed = this.packets.write();
+ break;
+
+ case 'zip':
+ // - ZIP [RFC1951]
+ throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
+
+ case 'zlib':
+ // - ZLIB [RFC1950]
+ // TODO: need to implement this
+ throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
+
+ case 'bzip2':
+ // - BZip2 [BZ2]
+ // TODO: need to implement this
+ throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
+
+ default:
+ throw new Error("Compression algorithm unknown :" + this.type);
+ }
};
diff --git a/src/packet/index.js b/src/packet/index.js
index 4396464c..be4e31f2 100644
--- a/src/packet/index.js
+++ b/src/packet/index.js
@@ -1,7 +1,11 @@
var enums = require('../enums.js');
module.exports = {
- list: require('./packetlist.js')
+ /**
+ * @name module:packet.List
+ * @see module:packet/packetlist
+ */
+ List: require('./packetlist.js')
};
var packets = require('./all_packets.js');
diff --git a/src/packet/literal.js b/src/packet/literal.js
index 7b2f5a7a..130f2162 100644
--- a/src/packet/literal.js
+++ b/src/packet/literal.js
@@ -18,112 +18,113 @@
/**
* Implementation of the Literal Data Packet (Tag 11)
*
- * RFC4880 5.9: A Literal Data packet contains the body of a message; data that
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.9|RFC4880 5.9}: A Literal Data packet contains the body of a message; data that
* is not to be further interpreted.
* @requires enums
* @requires util
* @module packet/literal
*/
+module.exports = Literal;
+
var util = require('../util'),
enums = require('../enums.js');
/**
* @constructor
*/
-module.exports = function literal() {
+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();
+}
-
- /**
- * Set the packet data to a javascript native string, end of line
- * 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) {
- // normalize EOL to \r\n
- text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
- // encode UTF8
- this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
- };
-
- /**
- * Returns literal data packets as native JavaScript string
- * with normalized end of line to \n
- * @return {String} literal data as text
- */
- this.getText = function () {
- // decode UTF8
- var text = util.decode_utf8(this.data);
- // normalize EOL to \n
- return text.replace(/\r\n/g, '\n');
- };
-
- /**
- * Set the packet data to value represented by the provided string of bytes.
- * @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.format = format;
- this.data = bytes;
- };
-
-
- /**
- * Get the byte sequence representing the literal packet data
- * @returns {String} A sequence of bytes
- */
- this.getBytes = function () {
- return this.data;
- };
-
-
- /**
- * Parsing function for a literal data packet (tag 11).
- *
- * @param {String} input Payload of a tag 11 packet
- * @param {Integer} position
- * Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/literal} object representation
- */
- this.read = function (bytes) {
- // - A one-octet field that describes how the data is formatted.
-
- var format = enums.read(enums.literal, bytes.charCodeAt(0));
-
- var filename_len = bytes.charCodeAt(1);
- this.filename = util.decode_utf8(bytes.substr(2, filename_len));
-
- this.date = util.readDate(bytes.substr(2 + filename_len, 4));
-
- var data = bytes.substring(6 + filename_len);
-
- this.setBytes(data, format);
- };
-
- /**
- * Creates a string representation of the packet
- *
- * @param {String} data The data to be inserted as body
- * @return {String} string-representation of the packet
- */
- this.write = function () {
- var filename = util.encode_utf8("msg.txt");
-
- var data = this.getBytes();
-
- var result = '';
- result += String.fromCharCode(enums.write(enums.literal, this.format));
- result += String.fromCharCode(filename.length);
- result += filename;
- result += util.writeDate(this.date);
- result += data;
- return result;
- };
+/**
+ * Set the packet data to a javascript native string, end of line
+ * will be normalized to \r\n and by default text is converted to UTF8
+ * @param {String} text Any native javascript string
+ */
+Literal.prototype.setText = function (text) {
+ // normalize EOL to \r\n
+ text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
+ // encode UTF8
+ this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
+};
+
+/**
+ * Returns literal data packets as native JavaScript string
+ * with normalized end of line to \n
+ * @return {String} literal data as text
+ */
+Literal.prototype.getText = function () {
+ // decode UTF8
+ var text = util.decode_utf8(this.data);
+ // normalize EOL to \n
+ return text.replace(/\r\n/g, '\n');
+};
+
+/**
+ * Set the packet data to value represented by the provided string of bytes.
+ * @param {String} bytes The string of bytes
+ * @param {utf8|binary|text} format The format of the string of bytes
+ */
+Literal.prototype.setBytes = function (bytes, format) {
+ this.format = format;
+ this.data = bytes;
+};
+
+
+/**
+ * Get the byte sequence representing the literal packet data
+ * @returns {String} A sequence of bytes
+ */
+Literal.prototype.getBytes = function () {
+ return this.data;
+};
+
+
+/**
+ * Parsing function for a literal data packet (tag 11).
+ *
+ * @param {String} input Payload of a tag 11 packet
+ * @param {Integer} position
+ * Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/literal} object representation
+ */
+Literal.prototype.read = function (bytes) {
+ // - A one-octet field that describes how the data is formatted.
+
+ var format = enums.read(enums.literal, bytes.charCodeAt(0));
+
+ var filename_len = bytes.charCodeAt(1);
+ this.filename = util.decode_utf8(bytes.substr(2, filename_len));
+
+ this.date = util.readDate(bytes.substr(2 + filename_len, 4));
+
+ var data = bytes.substring(6 + filename_len);
+
+ this.setBytes(data, format);
+};
+
+/**
+ * Creates a string representation of the packet
+ *
+ * @param {String} data The data to be inserted as body
+ * @return {String} string-representation of the packet
+ */
+Literal.prototype.write = function () {
+ var filename = util.encode_utf8("msg.txt");
+
+ var data = this.getBytes();
+
+ var result = '';
+ result += String.fromCharCode(enums.write(enums.literal, this.format));
+ result += String.fromCharCode(filename.length);
+ result += filename;
+ result += util.writeDate(this.date);
+ result += data;
+ return result;
};
diff --git a/src/packet/marker.js b/src/packet/marker.js
index d1770d76..75ee8a77 100644
--- a/src/packet/marker.js
+++ b/src/packet/marker.js
@@ -19,7 +19,7 @@
/**
* Implementation of the strange "Marker packet" (Tag 10)
*
- * RFC4880 5.8: An experimental version of PGP used this packet as the Literal
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.8|RFC4880 5.8}: An experimental version of PGP used this packet as the Literal
* packet, but no released version of PGP generated Literal packets with this
* tag. With PGP 5.x, this packet has been reassigned and is reserved for use as
* the Marker packet.
@@ -28,27 +28,30 @@
* @module packet/marker
*/
+module.exports = Marker;
+
/**
* @constructor
*/
-module.exports = function marker() {
- /**
- * Parsing function for a literal data packet (tag 10).
- *
- * @param {String} input Payload of a tag 10 packet
- * @param {Integer} position
- * Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/marker} Object representation
- */
- this.read = function (bytes) {
- if (bytes.charCodeAt(0) == 0x50 && // P
- bytes.charCodeAt(1) == 0x47 && // G
- bytes.charCodeAt(2) == 0x50) // P
- return true;
- // marker packet does not contain "PGP"
- return false;
- };
+function Marker() {
+}
+
+/**
+ * Parsing function for a literal data packet (tag 10).
+ *
+ * @param {String} input Payload of a tag 10 packet
+ * @param {Integer} position
+ * Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/marker} Object representation
+ */
+Marker.prototype.read = function (bytes) {
+ if (bytes.charCodeAt(0) == 0x50 && // P
+ bytes.charCodeAt(1) == 0x47 && // G
+ bytes.charCodeAt(2) == 0x50) // P
+ return true;
+ // marker packet does not contain "PGP"
+ return false;
};
diff --git a/src/packet/one_pass_signature.js b/src/packet/one_pass_signature.js
index 5e616435..d5f53a9d 100644
--- a/src/packet/one_pass_signature.js
+++ b/src/packet/one_pass_signature.js
@@ -18,8 +18,7 @@
/**
* Implementation of the One-Pass Signature Packets (Tag 4)
*
- * RFC4880 5.4:
- * The One-Pass Signature packet precedes the signed data and contains
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.4|RFC4880 5.4}: The One-Pass Signature packet precedes the signed data and contains
* enough information to allow the receiver to begin calculating any
* hashes needed to verify the signature. It allows the Signature
* packet to be placed at the end of the message, so that the signer
@@ -29,67 +28,69 @@
* @module packet/one_pass_signature
*/
+module.exports = OnePassSignature;
+
var enums = require('../enums.js'),
type_keyid = require('../type/keyid.js');
/**
* @constructor
*/
-module.exports = function one_pass_signature() {
+function OnePassSignature() {
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)
- this.publicKeyAlgorithm = null; // A one-octet number describing the public-key algorithm used. (See RFC4880 9.1)
+ this.type = null; // A one-octet signature type. Signature types are described in {@link http://tools.ietf.org/html/rfc4880#section-5.2.1|RFC4880 Section 5.2.1}.
+ this.hashAlgorithm = null; // A one-octet number describing the hash algorithm used. (See {@link http://tools.ietf.org/html/rfc4880#section-9.4|RFC4880 9.4})
+ this.publicKeyAlgorithm = null; // A one-octet number describing the public-key algorithm used. (See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880 9.1})
this.signingKeyId = null; // An eight-octet number holding the Key ID of the signing key.
this.flags = null; // A one-octet number holding a flag showing whether the signature is nested. A zero value indicates that the next packet is another One-Pass Signature packet that describes another signature to be applied to the same message data.
+}
- /**
- * parsing function for a one-pass signature packet (tag 4).
- * @param {String} bytes payload of a tag 4 packet
- * @return {module:packet/one_pass_signature} object representation
- */
- this.read = function (bytes) {
- var mypos = 0;
- // A one-octet version number. The current version is 3.
- this.version = bytes.charCodeAt(mypos++);
+/**
+ * parsing function for a one-pass signature packet (tag 4).
+ * @param {String} bytes payload of a tag 4 packet
+ * @return {module:packet/one_pass_signature} object representation
+ */
+OnePassSignature.prototype.read = function (bytes) {
+ var mypos = 0;
+ // A one-octet version number. The current version is 3.
+ this.version = bytes.charCodeAt(mypos++);
- // A one-octet signature type. Signature types are described in
- // Section 5.2.1.
- this.type = enums.read(enums.signature, bytes.charCodeAt(mypos++));
+ // A one-octet signature type. Signature types are described in
+ // Section 5.2.1.
+ this.type = enums.read(enums.signature, bytes.charCodeAt(mypos++));
- // A one-octet number describing the hash algorithm used.
- this.hashAlgorithm = enums.read(enums.hash, bytes.charCodeAt(mypos++));
+ // A one-octet number describing the hash algorithm used.
+ this.hashAlgorithm = enums.read(enums.hash, bytes.charCodeAt(mypos++));
- // A one-octet number describing the public-key algorithm used.
- this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(mypos++));
+ // A one-octet number describing the public-key algorithm used.
+ this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(mypos++));
- // An eight-octet number holding the Key ID of the signing key.
- this.signingKeyId = new type_keyid();
- this.signingKeyId.read(bytes.substr(mypos));
- mypos += 8;
+ // An eight-octet number holding the Key ID of the signing key.
+ this.signingKeyId = new type_keyid();
+ this.signingKeyId.read(bytes.substr(mypos));
+ mypos += 8;
- // A one-octet number holding a flag showing whether the signature
- // is nested. A zero value indicates that the next packet is
- // another One-Pass Signature packet that describes another
- // signature to be applied to the same message data.
- this.flags = bytes.charCodeAt(mypos++);
- return this;
- };
-
- /**
- * creates a string representation of a one-pass signature packet
- * @return {String} a string representation of a one-pass signature packet
- */
- this.write = function () {
- var result = "";
-
- result += String.fromCharCode(3);
- result += String.fromCharCode(enums.write(enums.signature, this.type));
- result += String.fromCharCode(enums.write(enums.hash, this.hashAlgorithm));
- result += String.fromCharCode(enums.write(enums.publicKey, this.publicKeyAlgorithm));
- result += this.signingKeyId.write();
- result += String.fromCharCode(this.flags);
-
- return result;
- };
+ // A one-octet number holding a flag showing whether the signature
+ // is nested. A zero value indicates that the next packet is
+ // another One-Pass Signature packet that describes another
+ // signature to be applied to the same message data.
+ this.flags = bytes.charCodeAt(mypos++);
+ return this;
+};
+
+/**
+ * creates a string representation of a one-pass signature packet
+ * @return {String} a string representation of a one-pass signature packet
+ */
+OnePassSignature.prototype.write = function () {
+ var result = "";
+
+ result += String.fromCharCode(3);
+ result += String.fromCharCode(enums.write(enums.signature, this.type));
+ result += String.fromCharCode(enums.write(enums.hash, this.hashAlgorithm));
+ result += String.fromCharCode(enums.write(enums.publicKey, this.publicKeyAlgorithm));
+ result += this.signingKeyId.write();
+ result += String.fromCharCode(this.flags);
+
+ return result;
};
diff --git a/src/packet/packet.js b/src/packet/packet.js
index 317ff0d2..661d5f47 100644
--- a/src/packet/packet.js
+++ b/src/packet/packet.js
@@ -24,7 +24,6 @@
var enums = require('../enums.js'),
util = require('../util');
-
module.exports = {
readSimpleLength: function(bytes) {
var len = 0,
diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js
index 7ed4637f..07284b7f 100644
--- a/src/packet/packetlist.js
+++ b/src/packet/packetlist.js
@@ -8,6 +8,8 @@
* @module packet/packetlist
*/
+module.exports = Packetlist;
+
var packetParser = require('./packet.js'),
packets = require('./all_packets.js'),
enums = require('../enums.js');
@@ -15,162 +17,161 @@ var packetParser = require('./packet.js'),
/**
* @constructor
*/
-module.exports = function packetlist() {
+function Packetlist() {
/** The number of packets contained within the list.
* @readonly
* @type {Integer} */
this.length = 0;
+}
+/**
+ * Reads a stream of binary data and interprents it as a list of packets.
+ * @param {String} A binary string of bytes.
+ */
+Packetlist.prototype.read = function (bytes) {
+ var i = 0;
- /**
- * 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) {
- var i = 0;
+ while (i < bytes.length) {
+ var parsed = packetParser.read(bytes, i, bytes.length - i);
+ i = parsed.offset;
- while (i < bytes.length) {
- var parsed = packetParser.read(bytes, i, bytes.length - i);
- i = parsed.offset;
+ var tag = enums.read(enums.packet, parsed.tag);
+ var packet = packets.newPacketFromTag(tag);
- var tag = enums.read(enums.packet, parsed.tag);
- var packet = new packets[tag]();
+ this.push(packet);
- this.push(packet);
-
- packet.read(parsed.packet);
- }
- };
-
- /**
- * Creates a binary representation of openpgp objects contained within the
- * class instance.
- * @returns {String} A binary string of bytes containing valid openpgp packets.
- */
- this.write = function () {
- var bytes = '';
-
- for (var i = 0; i < this.length; i++) {
- var packetbytes = this[i].write();
- bytes += packetParser.writeHeader(this[i].tag, packetbytes.length);
- bytes += packetbytes;
- }
-
- return bytes;
- };
-
- /**
- * 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) {
- if (!packet) return;
-
- packet.packets = packet.packets || new packetlist();
-
- this[this.length] = packet;
- this.length++;
- };
-
- /**
- * Creates a new packetList with all packets that pass the test implemented by the provided function.
- */
- this.filter = function (callback) {
-
- var filtered = new packetlist();
-
- for (var i = 0; i < this.length; i++) {
- if (callback(this[i], i, this)) {
- filtered.push(this[i]);
- }
- }
-
- return filtered;
- };
-
- /**
- * Creates a new packetList with all packets from the given types
- */
- this.filterByTag = function () {
- var args = Array.prototype.slice.call(arguments);
- var filtered = new packetlist();
- var that = this;
-
- for (var i = 0; i < this.length; i++) {
- if (args.some(function(packetType) {return that[i].tag == packetType;})) {
- filtered.push(this[i]);
- }
- }
-
- return filtered;
- };
-
- /**
- * Executes the provided callback once for each element
- */
- this.forEach = function (callback) {
- for (var i = 0; i < this.length; i++) {
- callback(this[i]);
- }
- };
-
- /**
- * Traverses packet tree and returns first matching packet
- * @param {module:enums.packet} type The packet type
- * @return {module:packet/packet|null}
- */
- this.findPacket = function (type) {
- var packetlist = this.filterByTag(type);
- if (packetlist.length) {
- return packetlist[0];
- } else {
- var found = null;
- for (var i = 0; i < this.length; i++) {
- if (this[i].packets.length) {
- found = this[i].packets.findPacket(type);
- if (found) return found;
- }
- }
- }
- return null;
- };
-
- /**
- * Returns array of found indices by tag
- */
- this.indexOfTag = function () {
- var args = Array.prototype.slice.call(arguments);
- var tagIndex = [];
- var that = this;
- for (var i = 0; i < this.length; i++) {
- if (args.some(function(packetType) {return that[i].tag == packetType;})) {
- tagIndex.push(i);
- }
- }
- return tagIndex;
- };
-
- /**
- * Returns slice of packetlist
- */
- this.slice = function (begin, end) {
- if (!end) {
- end = this.length;
- }
- var part = new packetlist();
- for (var i = begin; i < end; i++) {
- part.push(this[i]);
- }
- return part;
- };
-
- /**
- * Concatenates packetlist or array of packets
- */
- this.concat = function (packetlist) {
- if (packetlist) {
- for (var i = 0; i < packetlist.length; i++) {
- this.push(packetlist[i]);
- }
- }
- };
+ packet.read(parsed.packet);
+ }
+};
+
+/**
+ * Creates a binary representation of openpgp objects contained within the
+ * class instance.
+ * @returns {String} A binary string of bytes containing valid openpgp packets.
+ */
+Packetlist.prototype.write = function () {
+ var bytes = '';
+
+ for (var i = 0; i < this.length; i++) {
+ var packetbytes = this[i].write();
+ bytes += packetParser.writeHeader(this[i].tag, packetbytes.length);
+ bytes += packetbytes;
+ }
+
+ return bytes;
+};
+
+/**
+ * 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.
+ */
+Packetlist.prototype.push = function (packet) {
+ if (!packet) return;
+
+ packet.packets = packet.packets || new Packetlist();
+
+ this[this.length] = packet;
+ this.length++;
+};
+
+/**
+* Creates a new PacketList with all packets that pass the test implemented by the provided function.
+*/
+Packetlist.prototype.filter = function (callback) {
+
+ var filtered = new Packetlist();
+
+ for (var i = 0; i < this.length; i++) {
+ if (callback(this[i], i, this)) {
+ filtered.push(this[i]);
+ }
+ }
+
+ return filtered;
+};
+
+/**
+* Creates a new PacketList with all packets from the given types
+*/
+Packetlist.prototype.filterByTag = function () {
+ var args = Array.prototype.slice.call(arguments);
+ var filtered = new Packetlist();
+ var that = this;
+
+ for (var i = 0; i < this.length; i++) {
+ if (args.some(function(packetType) {return that[i].tag == packetType;})) {
+ filtered.push(this[i]);
+ }
+ }
+
+ return filtered;
+};
+
+/**
+* Executes the provided callback once for each element
+*/
+Packetlist.prototype.forEach = function (callback) {
+ for (var i = 0; i < this.length; i++) {
+ callback(this[i]);
+ }
+};
+
+/**
+ * Traverses packet tree and returns first matching packet
+ * @param {module:enums.packet} type The packet type
+ * @return {module:packet/packet|null}
+ */
+Packetlist.prototype.findPacket = function (type) {
+ var packetlist = this.filterByTag(type);
+ if (packetlist.length) {
+ return packetlist[0];
+ } else {
+ var found = null;
+ for (var i = 0; i < this.length; i++) {
+ if (this[i].packets.length) {
+ found = this[i].packets.findPacket(type);
+ if (found) return found;
+ }
+ }
+ }
+ return null;
+};
+
+/**
+ * Returns array of found indices by tag
+ */
+Packetlist.prototype.indexOfTag = function () {
+ var args = Array.prototype.slice.call(arguments);
+ var tagIndex = [];
+ var that = this;
+ for (var i = 0; i < this.length; i++) {
+ if (args.some(function(packetType) {return that[i].tag == packetType;})) {
+ tagIndex.push(i);
+ }
+ }
+ return tagIndex;
+};
+
+/**
+ * Returns slice of packetlist
+ */
+Packetlist.prototype.slice = function (begin, end) {
+ if (!end) {
+ end = this.length;
+ }
+ var part = new Packetlist();
+ for (var i = begin; i < end; i++) {
+ part.push(this[i]);
+ }
+ return part;
+};
+
+/**
+ * Concatenates packetlist or array of packets
+ */
+Packetlist.prototype.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 5813134c..5fa835af 100644
--- a/src/packet/public_key.js
+++ b/src/packet/public_key.js
@@ -18,7 +18,7 @@
/**
* Implementation of the Key Material Packet (Tag 5,6,7,14)
*
- * RFC4480 5.5:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.5|RFC4480 5.5}:
* A key material packet contains all the information about a public or
* private key. There are four variants of this packet type, and two
* major versions. Consequently, this section is complex.
@@ -30,6 +30,8 @@
* @module packet/public_key
*/
+module.exports = PublicKey;
+
var util = require('../util'),
type_mpi = require('../type/mpi.js'),
type_keyid = require('../type/keyid.js'),
@@ -39,7 +41,7 @@ var util = require('../util'),
/**
* @constructor
*/
-module.exports = function public_key() {
+function PublicKey() {
this.version = 4;
/** Key creation date.
* @type {Date} */
@@ -52,136 +54,132 @@ module.exports = function public_key() {
this.algorithm = 'rsa_sign';
// time in days (V3 only)
this.expirationTimeV3 = 0;
+}
+/**
+ * Internal Parser for public keys as specified in {@link http://tools.ietf.org/html/rfc4880#section-5.5.2|RFC 4880 section 5.5.2 Public-Key Packet Formats}
+ * called by read_tag<num>
+ * @param {String} input Input string to read the packet from
+ * @return {Object} This object with attributes set by the parser
+ */
+PublicKey.prototype.read = function (bytes) {
+ var pos = 0;
+ // A one-octet version number (3 or 4).
+ this.version = bytes.charCodeAt(pos++);
- /**
- * Internal Parser for public keys as specified in RFC 4880 section
- * 5.5.2 Public-Key Packet Formats
- * called by read_tag<num>
- * @param {String} input Input string to read the packet from
- * @return {Object} This object with attributes set by the parser
- */
- this.read = function (bytes) {
- var pos = 0;
- // A one-octet version number (3 or 4).
- this.version = bytes.charCodeAt(pos++);
+ if (this.version == 3 || this.version == 4) {
+ // - A four-octet number denoting the time that the key was created.
+ this.created = util.readDate(bytes.substr(pos, 4));
+ pos += 4;
- if (this.version == 3 || this.version == 4) {
- // - A four-octet number denoting the time that the key was created.
- this.created = util.readDate(bytes.substr(pos, 4));
- pos += 4;
-
- if (this.version == 3) {
- // - A two-octet number denoting the time in days that this key is
- // valid. If this number is zero, then it does not expire.
- this.expirationTimeV3 = util.readNumber(bytes.substr(pos, 2));
- pos += 2;
- }
-
- // - A one-octet number denoting the public-key algorithm of this key.
- this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(pos++));
-
- var mpicount = crypto.getPublicMpiCount(this.algorithm);
- this.mpi = [];
-
- var bmpi = bytes.substr(pos);
- var p = 0;
-
- for (var i = 0; i < mpicount && p < bmpi.length; i++) {
-
- this.mpi[i] = new type_mpi();
-
- p += this.mpi[i].read(bmpi.substr(p));
-
- if (p > bmpi.length) {
- throw new Error('Error reading MPI @:' + p);
- }
- }
-
- return p + 6;
- } else {
- throw new Error('Version ' + version + ' of the key packet is unsupported.');
- }
- };
-
- /**
- * Alias of read()
- * @function module:packet/public_key#readPublicKey
- * @see module:packet/public_key#read
- */
- this.readPublicKey = this.read;
-
- /**
- * Same as write_private_key, but has less information because of
- * public key.
- * @return {Object} {body: [string]OpenPGP packet body contents,
- * header: [string] OpenPGP packet header, string: [string] header+body}
- */
- this.write = function () {
- // Version
- var result = String.fromCharCode(this.version);
- result += util.writeDate(this.created);
if (this.version == 3) {
- result += util.writeNumber(this.expirationTimeV3, 2);
+ // - A two-octet number denoting the time in days that this key is
+ // valid. If this number is zero, then it does not expire.
+ this.expirationTimeV3 = util.readNumber(bytes.substr(pos, 2));
+ pos += 2;
}
- result += String.fromCharCode(enums.write(enums.publicKey, this.algorithm));
+
+ // - A one-octet number denoting the public-key algorithm of this key.
+ this.algorithm = enums.read(enums.publicKey, bytes.charCodeAt(pos++));
var mpicount = crypto.getPublicMpiCount(this.algorithm);
+ this.mpi = [];
- for (var i = 0; i < mpicount; i++) {
- result += this.mpi[i].write();
- }
+ var bmpi = bytes.substr(pos);
+ var p = 0;
- return result;
- };
+ for (var i = 0; i < mpicount && p < bmpi.length; i++) {
- /**
- * Alias of write()
- * @function module:packet/public_key#writePublicKey
- * @see module:packet/public_key#write
- */
- this.writePublicKey = this.write;
+ this.mpi[i] = new type_mpi();
- /**
- * Write an old version packet - it's used by some of the internal routines.
- */
- this.writeOld = function () {
- var bytes = this.writePublicKey();
+ p += this.mpi[i].read(bmpi.substr(p));
- return String.fromCharCode(0x99) +
- util.writeNumber(bytes.length, 2) +
- bytes;
- };
-
- /**
- * Calculates the key id of the key
- * @return {String} A 8 byte key id
- */
- this.getKeyId = function () {
- var keyid = new type_keyid();
- if (this.version == 4) {
- keyid.read(this.getFingerprint().substr(12, 8));
- } else if (this.version == 3) {
- keyid.read(this.mpi[0].write().substr(-8));
- }
- return keyid;
- };
-
- /**
- * Calculates the fingerprint of the key
- * @return {String} A string containing the fingerprint
- */
- this.getFingerprint = function () {
- var toHash = '';
- if (this.version == 4) {
- toHash = this.writeOld();
- return crypto.hash.sha1(toHash);
- } else if (this.version == 3) {
- var mpicount = crypto.getPublicMpiCount(this.algorithm);
- for (var i = 0; i < mpicount; i++) {
- toHash += this.mpi[i].toBytes();
+ if (p > bmpi.length) {
+ throw new Error('Error reading MPI @:' + p);
}
- return crypto.hash.md5(toHash);
}
- };
+
+ return p + 6;
+ } else {
+ throw new Error('Version ' + version + ' of the key packet is unsupported.');
+ }
+};
+
+/**
+ * Alias of read()
+ * @see module:packet/public_key~PublicKey#read
+ */
+PublicKey.prototype.readPublicKey = PublicKey.prototype.read;
+
+/**
+ * Same as write_private_key, but has less information because of
+ * public key.
+ * @return {Object} {body: [string]OpenPGP packet body contents,
+ * header: [string] OpenPGP packet header, string: [string] header+body}
+ */
+PublicKey.prototype.write = function () {
+ // Version
+ var result = String.fromCharCode(this.version);
+ result += util.writeDate(this.created);
+ if (this.version == 3) {
+ result += util.writeNumber(this.expirationTimeV3, 2);
+ }
+ result += String.fromCharCode(enums.write(enums.publicKey, this.algorithm));
+
+ var mpicount = crypto.getPublicMpiCount(this.algorithm);
+
+ for (var i = 0; i < mpicount; i++) {
+ result += this.mpi[i].write();
+ }
+
+ return result;
+};
+
+/**
+ * Alias of write()
+ * @see module:packet/public_key~PublicKey#write
+ */
+PublicKey.prototype.writePublicKey = PublicKey.prototype.write;
+
+/**
+ * Write an old version packet - it's used by some of the internal routines.
+ */
+PublicKey.prototype.writeOld = function () {
+ var bytes = this.writePublicKey();
+
+ return String.fromCharCode(0x99) +
+ util.writeNumber(bytes.length, 2) +
+ bytes;
+};
+
+/**
+ * Calculates the key id of the key
+ * @return {String} A 8 byte key id
+ */
+PublicKey.prototype.getKeyId = function () {
+ var keyid = new type_keyid();
+ if (this.version == 4) {
+ keyid.read(this.getFingerprint().substr(12, 8));
+ } else if (this.version == 3) {
+ keyid.read(this.mpi[0].write().substr(-8));
+ }
+ return keyid;
+};
+
+/**
+ * Calculates the fingerprint of the key
+ * @return {String} A string containing the fingerprint
+ */
+PublicKey.prototype.getFingerprint = function () {
+ var toHash = '';
+ if (this.version == 4) {
+ toHash = this.writeOld();
+ return crypto.hash.sha1(toHash);
+ } else if (this.version == 3) {
+ var mpicount = crypto.getPublicMpiCount(this.algorithm);
+ for (var i = 0; i < mpicount; i++) {
+ toHash += this.mpi[i].toBytes();
+ }
+ return crypto.hash.md5(toHash);
+ }
};
diff --git a/src/packet/public_key_encrypted_session_key.js b/src/packet/public_key_encrypted_session_key.js
index 2aa42b72..bac2168b 100644
--- a/src/packet/public_key_encrypted_session_key.js
+++ b/src/packet/public_key_encrypted_session_key.js
@@ -18,7 +18,7 @@
/**
* Public-Key Encrypted Session Key Packets (Tag 1)
*
- * RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}: A Public-Key Encrypted Session Key packet holds the session key
* used to encrypt a message. Zero or more Public-Key Encrypted Session Key
* packets and/or Symmetric-Key Encrypted Session Key packets may precede a
* Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -37,6 +37,8 @@
* @module packet/public_key_encrypted_session_key
*/
+module.exports = PublicKeyEncryptedSessionKey;
+
var type_keyid = require('../type/keyid.js'),
util = require('../util'),
type_mpi = require('../type/mpi.js'),
@@ -46,7 +48,7 @@ var type_keyid = require('../type/keyid.js'),
/**
* @constructor
*/
-module.exports = function public_key_encrypted_session_key() {
+function PublicKeyEncryptedSessionKey() {
this.version = 3;
this.publicKeyId = new type_keyid();
@@ -57,126 +59,126 @@ module.exports = function public_key_encrypted_session_key() {
/** @type {Array} */
this.encrypted = [];
+}
- /**
- * Parsing function for a publickey encrypted session key packet (tag 1).
- *
- * @param {String} input Payload of a tag 1 packet
- * @param {Integer} position Position to start reading from the input string
- * @param {Integer} len Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/public_key_encrypted_session_key} Object representation
- */
- this.read = function (bytes) {
+/**
+ * Parsing function for a publickey encrypted session key packet (tag 1).
+ *
+ * @param {String} input Payload of a tag 1 packet
+ * @param {Integer} position Position to start reading from the input string
+ * @param {Integer} len Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/public_key_encrypted_session_key} Object representation
+ */
+PublicKeyEncryptedSessionKey.prototype.read = function (bytes) {
- this.version = bytes.charCodeAt(0);
- this.publicKeyId.read(bytes.substr(1));
- this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
+ this.version = bytes.charCodeAt(0);
+ this.publicKeyId.read(bytes.substr(1));
+ this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes.charCodeAt(9));
- var i = 10;
+ var i = 10;
- var integerCount = (function(algo) {
- switch (algo) {
- case 'rsa_encrypt':
- case 'rsa_encrypt_sign':
- return 1;
+ var integerCount = (function(algo) {
+ switch (algo) {
+ case 'rsa_encrypt':
+ case 'rsa_encrypt_sign':
+ return 1;
- case 'elgamal':
- return 2;
+ case 'elgamal':
+ return 2;
- default:
- throw new Error("Invalid algorithm.");
- }
- })(this.publicKeyAlgorithm);
-
- this.encrypted = [];
-
- for (var j = 0; j < integerCount; j++) {
- var mpi = new type_mpi();
- i += mpi.read(bytes.substr(i));
- this.encrypted.push(mpi);
+ default:
+ throw new Error("Invalid algorithm.");
}
- };
+ })(this.publicKeyAlgorithm);
- /**
- * Create a string representation of a tag 1 packet
- *
- * @param {String} publicKeyId
- * The public key id corresponding to publicMPIs key as string
- * @param {Array} publicMPIs
- * Multiprecision integer objects describing the public key
- * @param {Integer} pubalgo
- * The corresponding public key algorithm // See RFC4880 9.1
- * @param {Integer} symmalgo
- * The symmetric cipher algorithm used to encrypt the data
- * within an encrypteddatapacket or encryptedintegrity-
- * protecteddatapacket
- * following this packet //See RFC4880 9.2
- * @param {String} sessionkey
- * A string of randombytes representing the session key
- * @return {String} The string representation
- */
- this.write = function () {
-
- var result = String.fromCharCode(this.version);
- result += this.publicKeyId.write();
- result += String.fromCharCode(
- enums.write(enums.publicKey, this.publicKeyAlgorithm));
-
- for (var i = 0; i < this.encrypted.length; i++) {
- result += this.encrypted[i].write();
- }
-
- return result;
- };
-
- this.encrypt = function (key) {
- var data = String.fromCharCode(
- enums.write(enums.symmetric, this.sessionKeyAlgorithm));
-
- data += this.sessionKey;
- var checksum = util.calc_checksum(this.sessionKey);
- data += util.writeNumber(checksum, 2);
+ this.encrypted = [];
+ for (var j = 0; j < integerCount; j++) {
var mpi = new type_mpi();
- mpi.fromBytes(crypto.pkcs1.eme.encode(
- data,
- key.mpi[0].byteLength()));
-
- this.encrypted = crypto.publicKeyEncrypt(
- this.publicKeyAlgorithm,
- key.mpi,
- mpi);
- };
-
- /**
- * Decrypts the session key (only for public key encrypted session key
- * packets (tag 1)
- *
- * @param {module:packet/secret_key} key
- * Private key with secMPIs unlocked
- * @return {String} The unencrypted session key
- */
- this.decrypt = function (key) {
- var result = crypto.publicKeyDecrypt(
- this.publicKeyAlgorithm,
- key.mpi,
- this.encrypted).toBytes();
-
- var checksum = util.readNumber(result.substr(result.length - 2));
-
- var decoded = crypto.pkcs1.eme.decode(
- result,
- key.mpi[0].byteLength());
-
- key = decoded.substring(1, decoded.length - 2);
-
- if (checksum != util.calc_checksum(key)) {
- throw new Error('Checksum mismatch');
- } else {
- this.sessionKey = key;
- this.sessionKeyAlgorithm =
- enums.read(enums.symmetric, decoded.charCodeAt(0));
- }
- };
+ i += mpi.read(bytes.substr(i));
+ this.encrypted.push(mpi);
+ }
+};
+
+/**
+ * Create a string representation of a tag 1 packet
+ *
+ * @param {String} publicKeyId
+ * The public key id corresponding to publicMPIs key as string
+ * @param {Array} publicMPIs
+ * Multiprecision integer objects describing the public key
+ * @param {module:enums.publicKey} pubalgo
+ * The corresponding public key algorithm // See {@link http://tools.ietf.org/html/rfc4880#section-9.1|RFC4880 9.1}
+ * @param {module:enums.symmetric} symmalgo
+ * The symmetric cipher algorithm used to encrypt the data
+ * within an encrypteddatapacket or encryptedintegrity-
+ * protecteddatapacket
+ * following this packet //See {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880 9.2}
+ * @param {String} sessionkey
+ * A string of randombytes representing the session key
+ * @return {String} The string representation
+ */
+PublicKeyEncryptedSessionKey.prototype.write = function () {
+
+ var result = String.fromCharCode(this.version);
+ result += this.publicKeyId.write();
+ result += String.fromCharCode(
+ enums.write(enums.publicKey, this.publicKeyAlgorithm));
+
+ for (var i = 0; i < this.encrypted.length; i++) {
+ result += this.encrypted[i].write();
+ }
+
+ return result;
+};
+
+PublicKeyEncryptedSessionKey.prototype.encrypt = function (key) {
+ var data = String.fromCharCode(
+ enums.write(enums.symmetric, this.sessionKeyAlgorithm));
+
+ data += this.sessionKey;
+ var checksum = util.calc_checksum(this.sessionKey);
+ data += util.writeNumber(checksum, 2);
+
+ var mpi = new type_mpi();
+ mpi.fromBytes(crypto.pkcs1.eme.encode(
+ data,
+ key.mpi[0].byteLength()));
+
+ this.encrypted = crypto.publicKeyEncrypt(
+ this.publicKeyAlgorithm,
+ key.mpi,
+ mpi);
+};
+
+/**
+ * Decrypts the session key (only for public key encrypted session key
+ * packets (tag 1)
+ *
+ * @param {module:packet/secret_key} key
+ * Private key with secMPIs unlocked
+ * @return {String} The unencrypted session key
+ */
+PublicKeyEncryptedSessionKey.prototype.decrypt = function (key) {
+ var result = crypto.publicKeyDecrypt(
+ this.publicKeyAlgorithm,
+ key.mpi,
+ this.encrypted).toBytes();
+
+ var checksum = util.readNumber(result.substr(result.length - 2));
+
+ var decoded = crypto.pkcs1.eme.decode(
+ result,
+ key.mpi[0].byteLength());
+
+ key = decoded.substring(1, decoded.length - 2);
+
+ if (checksum != util.calc_checksum(key)) {
+ throw new Error('Checksum mismatch');
+ } else {
+ this.sessionKey = key;
+ this.sessionKeyAlgorithm =
+ enums.read(enums.symmetric, decoded.charCodeAt(0));
+ }
};
diff --git a/src/packet/public_subkey.js b/src/packet/public_subkey.js
index db36cad7..966db261 100644
--- a/src/packet/public_subkey.js
+++ b/src/packet/public_subkey.js
@@ -20,12 +20,17 @@
* @module packet/public_subkey
*/
+module.exports = PublicSubkey;
+
var publicKey = require('./public_key.js');
/**
* @constructor
* @extends module:packet/public_key
*/
-module.exports = function public_subkey() {
+function PublicSubkey() {
publicKey.call(this);
};
+
+PublicSubkey.prototype = new publicKey();
+PublicSubkey.prototype.constructor = PublicSubkey;
diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js
index 7e477835..15574245 100644
--- a/src/packet/secret_key.js
+++ b/src/packet/secret_key.js
@@ -18,7 +18,7 @@
/**
* Implementation of the Key Material Packet (Tag 5,6,7,14)
*
- * RFC4480 5.5:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.5|RFC4480 5.5}:
* A key material packet contains all the information about a public or
* private key. There are four variants of this packet type, and two
* major versions. Consequently, this section is complex.
@@ -31,6 +31,8 @@
* @module packet/secret_key
*/
+module.exports = SecretKey;
+
var publicKey = require('./public_key.js'),
enums = require('../enums.js'),
util = require('../util'),
@@ -42,225 +44,224 @@ var publicKey = require('./public_key.js'),
* @constructor
* @extends module:packet/public_key
*/
-module.exports = function secret_key() {
+function SecretKey() {
publicKey.call(this);
// encrypted secret-key data
this.encrypted = null;
// indicator if secret-key data is available in decrypted form
this.isDecrypted = false;
+}
+SecretKey.prototype = new publicKey();
+SecretKey.prototype.constructor = SecretKey;
- function get_hash_len(hash) {
- if (hash == 'sha1')
- return 20;
- else
- return 2;
- }
-
- function get_hash_fn(hash) {
- if (hash == 'sha1')
- return crypto.hash.sha1;
- else
- return function(c) {
- return util.writeNumber(util.calc_checksum(c), 2);
- };
- }
-
- // Helper function
-
- function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) {
- var hashlen = get_hash_len(hash_algorithm),
- hashfn = get_hash_fn(hash_algorithm);
-
- var hashtext = cleartext.substr(cleartext.length - hashlen);
- cleartext = cleartext.substr(0, cleartext.length - hashlen);
-
- var hash = hashfn(cleartext);
-
- if (hash != hashtext)
- return new Error("Hash mismatch.");
-
- var mpis = crypto.getPrivateMpiCount(algorithm);
-
- var j = 0;
- var mpi = [];
-
- for (var i = 0; i < mpis && j < cleartext.length; i++) {
- mpi[i] = new type_mpi();
- j += mpi[i].read(cleartext.substr(j));
- }
-
- return mpi;
- }
-
- function write_cleartext_mpi(hash_algorithm, algorithm, mpi) {
- var bytes = '';
- var discard = crypto.getPublicMpiCount(algorithm);
-
- for (var i = discard; i < mpi.length; i++) {
- bytes += mpi[i].write();
- }
-
-
- bytes += get_hash_fn(hash_algorithm)(bytes);
-
- return bytes;
- }
-
-
- // 5.5.3. Secret-Key Packet Formats
-
- /**
- * 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) {
- // - A Public-Key or Public-Subkey packet, as described above.
- var len = this.readPublicKey(bytes);
-
- bytes = bytes.substr(len);
-
-
- // - One octet indicating string-to-key usage conventions. Zero
- // indicates that the secret-key data is not encrypted. 255 or 254
- // indicates that a string-to-key specifier is being given. Any
- // other value is a symmetric-key encryption algorithm identifier.
- var isEncrypted = bytes.charCodeAt(0);
-
- if (isEncrypted) {
- this.encrypted = bytes;
- } else {
-
- // - Plain or encrypted multiprecision integers comprising the secret
- // key data. These algorithm-specific fields are as described
- // below.
- var parsedMPI = parse_cleartext_mpi('mod', bytes.substr(1), this.algorithm);
- if (parsedMPI instanceof Error)
- throw parsedMPI;
- this.mpi = this.mpi.concat(parsedMPI);
- this.isDecrypted = true;
- }
+function get_hash_len(hash) {
+ if (hash == 'sha1')
+ return 20;
+ else
+ return 2;
+}
+function get_hash_fn(hash) {
+ if (hash == 'sha1')
+ return crypto.hash.sha1;
+ else
+ return function(c) {
+ return util.writeNumber(util.calc_checksum(c), 2);
};
+}
- /** Creates an OpenPGP key packet for the given key.
- * @return {String} A string of bytes containing the secret key OpenPGP packet
- */
- this.write = function () {
- var bytes = this.writePublicKey();
+// Helper function
- if (!this.encrypted) {
- bytes += String.fromCharCode(0);
+function parse_cleartext_mpi(hash_algorithm, cleartext, algorithm) {
+ var hashlen = get_hash_len(hash_algorithm),
+ hashfn = get_hash_fn(hash_algorithm);
- bytes += write_cleartext_mpi('mod', this.algorithm, this.mpi);
- } else {
- bytes += this.encrypted;
- }
+ var hashtext = cleartext.substr(cleartext.length - hashlen);
+ cleartext = cleartext.substr(0, cleartext.length - hashlen);
- return bytes;
- };
+ var hash = hashfn(cleartext);
+ if (hash != hashtext)
+ return new Error("Hash mismatch.");
+ var mpis = crypto.getPrivateMpiCount(algorithm);
+ var j = 0;
+ var mpi = [];
- /** Encrypt the payload. By default, we use aes256 and iterated, salted string
- * to key specifier
- * @param {String} passphrase
- */
- this.encrypt = function (passphrase) {
-
- var s2k = new type_s2k(),
- symmetric = 'aes256',
- cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi),
- key = produceEncryptionKey(s2k, passphrase, symmetric),
- blockLen = crypto.cipher[symmetric].blockSize,
- iv = crypto.random.getRandomBytes(blockLen);
-
-
- this.encrypted = '';
- this.encrypted += String.fromCharCode(254);
- this.encrypted += String.fromCharCode(enums.write(enums.symmetric, symmetric));
- this.encrypted += s2k.write();
- this.encrypted += iv;
-
- this.encrypted += crypto.cfb.normalEncrypt(symmetric, key, cleartext, iv);
- };
-
- function produceEncryptionKey(s2k, passphrase, algorithm) {
- return s2k.produce_key(passphrase,
- crypto.cipher[algorithm].keySize);
+ for (var i = 0; i < mpis && j < cleartext.length; i++) {
+ mpi[i] = new type_mpi();
+ j += mpi[i].read(cleartext.substr(j));
}
- /**
- * Decrypts the private key MPIs which are needed to use the key.
- * @link module:packet/secret_key.isDecrypted should be
- * false otherwise a call to this function is not needed
- *
- * @param {String} str_passphrase The passphrase for this private key
- * as string
- * @return {Boolean} True if the passphrase was correct or MPI already
- * decrypted; false if not
- */
- this.decrypt = function (passphrase) {
- if (this.isDecrypted)
- return true;
+ return mpi;
+}
- var i = 0,
- symmetric,
- key;
+function write_cleartext_mpi(hash_algorithm, algorithm, mpi) {
+ var bytes = '';
+ var discard = crypto.getPublicMpiCount(algorithm);
- var s2k_usage = this.encrypted.charCodeAt(i++);
-
- // - [Optional] If string-to-key usage octet was 255 or 254, a one-
- // octet symmetric encryption algorithm.
- if (s2k_usage == 255 || s2k_usage == 254) {
- symmetric = this.encrypted.charCodeAt(i++);
- symmetric = enums.read(enums.symmetric, symmetric);
-
- // - [Optional] If string-to-key usage octet was 255 or 254, a
- // string-to-key specifier. The length of the string-to-key
- // specifier is implied by its type, as described above.
- var s2k = new type_s2k();
- i += s2k.read(this.encrypted.substr(i));
-
- key = produceEncryptionKey(s2k, passphrase, symmetric);
- } else {
- symmetric = s2k_usage;
- symmetric = enums.read(enums.symmetric, symmetric);
- key = crypto.hash.md5(passphrase);
- }
+ for (var i = discard; i < mpi.length; i++) {
+ bytes += mpi[i].write();
+ }
- // - [Optional] If secret data is encrypted (string-to-key usage octet
- // not zero), an Initial Vector (IV) of the same length as the
- // cipher's block size.
- var iv = this.encrypted.substr(i,
- crypto.cipher[symmetric].blockSize);
+ bytes += get_hash_fn(hash_algorithm)(bytes);
- i += iv.length;
+ return bytes;
+}
- var cleartext,
- ciphertext = this.encrypted.substr(i);
- cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv);
+// 5.5.3. Secret-Key Packet Formats
- var hash = s2k_usage == 254 ?
- 'sha1' :
- 'mod';
+/**
+ * Internal parser for private keys as specified in {@link http://tools.ietf.org/html/rfc4880#section-5.5.3|RFC 4880 section 5.5.3}
+ * @param {String} bytes Input string to read the packet from
+ */
+SecretKey.prototype.read = function (bytes) {
+ // - A Public-Key or Public-Subkey packet, as described above.
+ var len = this.readPublicKey(bytes);
- var parsedMPI = parse_cleartext_mpi(hash, cleartext, this.algorithm);
+ bytes = bytes.substr(len);
+
+
+ // - One octet indicating string-to-key usage conventions. Zero
+ // indicates that the secret-key data is not encrypted. 255 or 254
+ // indicates that a string-to-key specifier is being given. Any
+ // other value is a symmetric-key encryption algorithm identifier.
+ var isEncrypted = bytes.charCodeAt(0);
+
+ if (isEncrypted) {
+ this.encrypted = bytes;
+ } else {
+
+ // - Plain or encrypted multiprecision integers comprising the secret
+ // key data. These algorithm-specific fields are as described
+ // below.
+ var parsedMPI = parse_cleartext_mpi('mod', bytes.substr(1), this.algorithm);
if (parsedMPI instanceof Error)
- return false;
+ throw parsedMPI;
this.mpi = this.mpi.concat(parsedMPI);
this.isDecrypted = true;
- return true;
- };
-
- this.generate = function (bits) {
- this.mpi = crypto.generateMpi(this.algorithm, bits);
- this.isDecrypted = true;
- };
+ }
};
-module.exports.prototype = new publicKey();
+/** Creates an OpenPGP key packet for the given key.
+ * @return {String} A string of bytes containing the secret key OpenPGP packet
+ */
+SecretKey.prototype.write = function () {
+ var bytes = this.writePublicKey();
+
+ if (!this.encrypted) {
+ bytes += String.fromCharCode(0);
+
+ bytes += write_cleartext_mpi('mod', this.algorithm, this.mpi);
+ } else {
+ bytes += this.encrypted;
+ }
+
+ return bytes;
+};
+
+
+
+
+/** Encrypt the payload. By default, we use aes256 and iterated, salted string
+ * to key specifier
+ * @param {String} passphrase
+ */
+SecretKey.prototype.encrypt = function (passphrase) {
+
+ var s2k = new type_s2k(),
+ symmetric = 'aes256',
+ cleartext = write_cleartext_mpi('sha1', this.algorithm, this.mpi),
+ key = produceEncryptionKey(s2k, passphrase, symmetric),
+ blockLen = crypto.cipher[symmetric].blockSize,
+ iv = crypto.random.getRandomBytes(blockLen);
+
+
+ this.encrypted = '';
+ this.encrypted += String.fromCharCode(254);
+ this.encrypted += String.fromCharCode(enums.write(enums.symmetric, symmetric));
+ this.encrypted += s2k.write();
+ this.encrypted += iv;
+
+ this.encrypted += crypto.cfb.normalEncrypt(symmetric, key, cleartext, iv);
+};
+
+function produceEncryptionKey(s2k, passphrase, algorithm) {
+ return s2k.produce_key(passphrase,
+ crypto.cipher[algorithm].keySize);
+}
+
+/**
+ * Decrypts the private key MPIs which are needed to use the key.
+ * @link module:packet/secret_key.isDecrypted should be
+ * false otherwise a call to this function is not needed
+ *
+ * @param {String} str_passphrase The passphrase for this private key
+ * as string
+ * @return {Boolean} True if the passphrase was correct or MPI already
+ * decrypted; false if not
+ */
+SecretKey.prototype.decrypt = function (passphrase) {
+ if (this.isDecrypted)
+ return true;
+
+ var i = 0,
+ symmetric,
+ key;
+
+ var s2k_usage = this.encrypted.charCodeAt(i++);
+
+ // - [Optional] If string-to-key usage octet was 255 or 254, a one-
+ // octet symmetric encryption algorithm.
+ if (s2k_usage == 255 || s2k_usage == 254) {
+ symmetric = this.encrypted.charCodeAt(i++);
+ symmetric = enums.read(enums.symmetric, symmetric);
+
+ // - [Optional] If string-to-key usage octet was 255 or 254, a
+ // string-to-key specifier. The length of the string-to-key
+ // specifier is implied by its type, as described above.
+ var s2k = new type_s2k();
+ i += s2k.read(this.encrypted.substr(i));
+
+ key = produceEncryptionKey(s2k, passphrase, symmetric);
+ } else {
+ symmetric = s2k_usage;
+ symmetric = enums.read(enums.symmetric, symmetric);
+ key = crypto.hash.md5(passphrase);
+ }
+
+
+ // - [Optional] If secret data is encrypted (string-to-key usage octet
+ // not zero), an Initial Vector (IV) of the same length as the
+ // cipher's block size.
+ var iv = this.encrypted.substr(i,
+ crypto.cipher[symmetric].blockSize);
+
+ i += iv.length;
+
+ var cleartext,
+ ciphertext = this.encrypted.substr(i);
+
+ cleartext = crypto.cfb.normalDecrypt(symmetric, key, ciphertext, iv);
+
+ var hash = s2k_usage == 254 ?
+ 'sha1' :
+ 'mod';
+
+ var parsedMPI = parse_cleartext_mpi(hash, cleartext, this.algorithm);
+ if (parsedMPI instanceof Error)
+ return false;
+ this.mpi = this.mpi.concat(parsedMPI);
+ this.isDecrypted = true;
+ return true;
+};
+
+SecretKey.prototype.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 84d72306..614c6288 100644
--- a/src/packet/secret_subkey.js
+++ b/src/packet/secret_subkey.js
@@ -20,12 +20,17 @@
* @module packet/secret_subkey
*/
+module.exports = SecretSubkey;
+
var secretKey = require('./secret_key.js');
/**
* @constructor
* @extends module:packet/secret_key
*/
-module.exports = function secret_subkey() {
+function SecretSubkey() {
secretKey.call(this);
-};
+}
+
+SecretSubkey.prototype = new secretKey();
+SecretSubkey.prototype.constructor = SecretSubkey;
diff --git a/src/packet/signature.js b/src/packet/signature.js
index 8c35c48b..4c6abfc2 100644
--- a/src/packet/signature.js
+++ b/src/packet/signature.js
@@ -18,7 +18,7 @@
/**
* Implementation of the Signature Packet (Tag 2)
*
- * RFC4480 5.2:
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.2|RFC4480 5.2}:
* A Signature packet describes a binding between some public key and
* some data. The most common signatures are a signature of a file or a
* block of text, and a signature that is a certification of a User ID.
@@ -31,6 +31,8 @@
* @module packet/signature
*/
+module.exports = Signature;
+
var util = require('../util'),
packet = require('./packet.js'),
enums = require('../enums.js'),
@@ -41,7 +43,7 @@ var util = require('../util'),
/**
* @constructor
*/
-module.exports = function signature() {
+function Signature() {
this.version = 4;
this.signatureType = null;
@@ -85,555 +87,554 @@ module.exports = function signature() {
this.embeddedSignature = null;
this.verified = false;
+}
- /**
- * parsing function for a signature packet (tag 2).
- * @param {String} bytes payload of a tag 2 packet
- * @param {Integer} position position to start reading from the bytes string
- * @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) {
- var i = 0;
+/**
+ * parsing function for a signature packet (tag 2).
+ * @param {String} bytes payload of a tag 2 packet
+ * @param {Integer} position position to start reading from the bytes string
+ * @param {Integer} len length of the packet or the remaining length of bytes at position
+ * @return {module:packet/signature} object representation
+ */
+Signature.prototype.read = function (bytes) {
+ var i = 0;
- this.version = bytes.charCodeAt(i++);
- // switch on version (3 and 4)
- switch (this.version) {
- case 3:
- // One-octet length of following hashed material. MUST be 5.
- if (bytes.charCodeAt(i++) != 5)
- util.print_debug("packet/signature.js\n" +
- 'invalid One-octet length of following hashed material.' +
- 'MUST be 5. @:' + (i - 1));
+ this.version = bytes.charCodeAt(i++);
+ // switch on version (3 and 4)
+ switch (this.version) {
+ case 3:
+ // One-octet length of following hashed material. MUST be 5.
+ if (bytes.charCodeAt(i++) != 5)
+ util.print_debug("packet/signature.js\n" +
+ 'invalid One-octet length of following hashed material.' +
+ 'MUST be 5. @:' + (i - 1));
- var sigpos = i;
- // One-octet signature type.
- this.signatureType = bytes.charCodeAt(i++);
+ var sigpos = i;
+ // One-octet signature type.
+ this.signatureType = bytes.charCodeAt(i++);
- // Four-octet creation time.
- this.created = util.readDate(bytes.substr(i, 4));
- i += 4;
+ // Four-octet creation time.
+ this.created = util.readDate(bytes.substr(i, 4));
+ i += 4;
- // storing data appended to data which gets verified
- this.signatureData = bytes.substring(sigpos, i);
+ // storing data appended to data which gets verified
+ this.signatureData = bytes.substring(sigpos, i);
- // Eight-octet Key ID of signer.
- this.issuerKeyId.read(bytes.substring(i, i + 8));
- i += 8;
+ // Eight-octet Key ID of signer.
+ this.issuerKeyId.read(bytes.substring(i, i + 8));
+ i += 8;
- // One-octet public-key algorithm.
- this.publicKeyAlgorithm = bytes.charCodeAt(i++);
+ // One-octet public-key algorithm.
+ this.publicKeyAlgorithm = bytes.charCodeAt(i++);
- // One-octet hash algorithm.
- this.hashAlgorithm = bytes.charCodeAt(i++);
- break;
- case 4:
- this.signatureType = bytes.charCodeAt(i++);
- this.publicKeyAlgorithm = bytes.charCodeAt(i++);
- this.hashAlgorithm = bytes.charCodeAt(i++);
+ // One-octet hash algorithm.
+ this.hashAlgorithm = bytes.charCodeAt(i++);
+ break;
+ case 4:
+ this.signatureType = bytes.charCodeAt(i++);
+ this.publicKeyAlgorithm = bytes.charCodeAt(i++);
+ this.hashAlgorithm = bytes.charCodeAt(i++);
- function subpackets(bytes) {
- // Two-octet scalar octet count for following subpacket data.
- var subpacket_length = util.readNumber(
- bytes.substr(0, 2));
+ function subpackets(bytes) {
+ // Two-octet scalar octet count for following subpacket data.
+ var subpacket_length = util.readNumber(
+ bytes.substr(0, 2));
- var i = 2;
+ var i = 2;
- // subpacket data set (zero or more subpackets)
- var subpacked_read = 0;
- while (i < 2 + subpacket_length) {
+ // subpacket data set (zero or more subpackets)
+ var subpacked_read = 0;
+ while (i < 2 + subpacket_length) {
- var len = packet.readSimpleLength(bytes.substr(i));
- i += len.offset;
+ var len = packet.readSimpleLength(bytes.substr(i));
+ i += len.offset;
- this.read_sub_packet(bytes.substr(i, len.len));
+ this.read_sub_packet(bytes.substr(i, len.len));
- i += len.len;
- }
-
- return i;
+ i += len.len;
}
- // hashed subpackets
- i += subpackets.call(this, bytes.substr(i), true);
-
- // A V4 signature hashes the packet body
- // starting from its first field, the version number, through the end
- // of the hashed subpacket data. Thus, the fields hashed are the
- // signature version, the signature type, the public-key algorithm, the
- // hash algorithm, the hashed subpacket length, and the hashed
- // subpacket body.
- this.signatureData = bytes.substr(0, i);
-
- // unhashed subpackets
- i += subpackets.call(this, bytes.substr(i), false);
-
- break;
- default:
- throw new Error('Version ' + version + ' of the signature is unsupported.');
- }
-
- // Two-octet field holding left 16 bits of signed hash value.
- this.signedHashValue = bytes.substr(i, 2);
- i += 2;
-
- this.signature = bytes.substr(i);
- };
-
- this.write = function () {
- return this.signatureData +
- util.writeNumber(0, 2) + // Number of unsigned subpackets.
- this.signedHashValue +
- this.signature;
- };
-
- /**
- * Signs provided data. This needs to be done prior to serialization.
- * @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) {
- var signatureType = enums.write(enums.signature, this.signatureType),
- publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm),
- hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm);
-
- var result = String.fromCharCode(4);
- result += String.fromCharCode(signatureType);
- result += String.fromCharCode(publicKeyAlgorithm);
- result += String.fromCharCode(hashAlgorithm);
-
- this.issuerKeyId = key.getKeyId();
-
- // Add hashed subpackets
- result += this.write_all_sub_packets();
-
- this.signatureData = result;
-
- var trailer = this.calculateTrailer();
-
- var toHash = this.toSign(signatureType, data) +
- this.signatureData + trailer;
-
- var hash = crypto.hash.digest(hashAlgorithm, toHash);
-
- this.signedHashValue = hash.substr(0, 2);
-
- this.signature = crypto.signature.sign(hashAlgorithm,
- publicKeyAlgorithm, key.mpi, toHash);
- };
-
- /**
- * Creates string of bytes with all subpacket data
- * @return {String} a string-representation of a all subpacket data
- */
- this.write_all_sub_packets = function () {
- var sub = enums.signatureSubpacket;
- var result = '';
- var bytes = '';
- if (this.created !== null) {
- result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
- }
- if (this.signatureExpirationTime !== null) {
- result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4));
- }
- if (this.exportable !== null) {
- result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
- }
- if (this.trustLevel !== null) {
- bytes = String.fromCharCode(this.trustLevel) + String.fromCharCode(this.trustAmount);
- result += write_sub_packet(sub.trust_signature, bytes);
- }
- if (this.regularExpression !== null) {
- result += write_sub_packet(sub.regular_expression, this.regularExpression);
- }
- if (this.revocable !== null) {
- result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
- }
- if (this.keyExpirationTime !== null) {
- result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4));
- }
- if (this.preferredSymmetricAlgorithms !== null) {
- bytes = util.bin2str(this.preferredSymmetricAlgorithms);
- result += write_sub_packet(sub.preferred_symmetric_algorithms, bytes);
- }
- if (this.revocationKeyClass !== null) {
- bytes = String.fromCharCode(this.revocationKeyClass);
- bytes += String.fromCharCode(this.revocationKeyAlgorithm);
- bytes += this.revocationKeyFingerprint;
- result += write_sub_packet(sub.revocation_key, bytes);
- }
- if (!this.issuerKeyId.isNull()) {
- result += write_sub_packet(sub.issuer, this.issuerKeyId.write());
- }
- if (this.notation !== null) {
- for (var name in this.notation) {
- if (this.notation.hasOwnProperty(name)) {
- var value = this.notation[name];
- bytes = String.fromCharCode(0x80);
- bytes += String.fromCharCode(0);
- bytes += String.fromCharCode(0);
- bytes += String.fromCharCode(0);
- // 2 octets of name length
- bytes += util.writeNumber(name.length, 2);
- // 2 octets of value length
- bytes += util.writeNumber(value.length, 2);
- bytes += name + value;
- result += write_sub_packet(sub.notation_data, bytes);
- }
+ return i;
}
- }
- if (this.preferredHashAlgorithms !== null) {
- bytes = util.bin2str(this.preferredHashAlgorithms);
- result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
- }
- if (this.preferredCompressionAlgorithms !== null) {
- bytes = util.bin2str(this.preferredCompressionAlgorithms);
- result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
- }
- if (this.keyServerPreferences !== null) {
- bytes = util.bin2str(this.keyServerPreferences);
- result += write_sub_packet(sub.key_server_preferences, bytes);
- }
- if (this.preferredKeyServer !== null) {
- result += write_sub_packet(sub.preferred_key_server, this.preferredKeyServer);
- }
- if (this.isPrimaryUserID !== null) {
- result += write_sub_packet(sub.primary_user_id, String.fromCharCode(this.isPrimaryUserID ? 1 : 0));
- }
- if (this.policyURI !== null) {
- result += write_sub_packet(sub.policy_uri, this.policyURI);
- }
- if (this.keyFlags !== null) {
- bytes = util.bin2str(this.keyFlags);
- result += write_sub_packet(sub.key_flags, bytes);
- }
- if (this.signersUserId !== null) {
- result += write_sub_packet(sub.signers_user_id, this.signersUserId);
- }
- if (this.reasonForRevocationFlag !== null) {
- bytes = String.fromCharCode(this.reasonForRevocationFlag);
- bytes += this.reasonForRevocationString;
- result += write_sub_packet(sub.reason_for_revocation, bytes);
- }
- if (this.features !== null) {
- bytes = util.bin2str(this.features);
- result += write_sub_packet(sub.features, bytes);
- }
- if (this.signatureTargetPublicKeyAlgorithm !== null) {
- bytes = String.fromCharCode(this.signatureTargetPublicKeyAlgorithm);
- bytes += String.fromCharCode(this.signatureTargetHashAlgorithm);
- bytes += this.signatureTargetHash;
- result += write_sub_packet(sub.signature_target, bytes);
- }
- if (this.embeddedSignature !== null) {
- result += write_sub_packet(sub.embedded_signature, this.embeddedSignature.write());
- }
- result = util.writeNumber(result.length, 2) + result;
- return result;
- };
- /**
- * creates a string representation of a sub signature packet (See RFC 4880 5.2.3.1)
- * @param {Integer} type subpacket signature type. Signature types as described
- * in RFC4880 Section 5.2.3.2
- * @param {String} data data to be included
- * @return {String} a string-representation of a sub signature packet (See RFC 4880 5.2.3.1)
- */
- function write_sub_packet(type, data) {
- var result = "";
- result += packet.writeSimpleLength(data.length + 1);
- result += String.fromCharCode(type);
- result += data;
- return result;
+ // hashed subpackets
+ i += subpackets.call(this, bytes.substr(i), true);
+
+ // A V4 signature hashes the packet body
+ // starting from its first field, the version number, through the end
+ // of the hashed subpacket data. Thus, the fields hashed are the
+ // signature version, the signature type, the public-key algorithm, the
+ // hash algorithm, the hashed subpacket length, and the hashed
+ // subpacket body.
+ this.signatureData = bytes.substr(0, i);
+
+ // unhashed subpackets
+ i += subpackets.call(this, bytes.substr(i), false);
+
+ break;
+ default:
+ throw new Error('Version ' + version + ' of the signature is unsupported.');
}
- // V4 signature sub packets
+ // Two-octet field holding left 16 bits of signed hash value.
+ this.signedHashValue = bytes.substr(i, 2);
+ i += 2;
- this.read_sub_packet = function (bytes) {
- var mypos = 0;
-
- function read_array(prop, bytes) {
- this[prop] = [];
-
- for (var i = 0; i < bytes.length; i++) {
- this[prop].push(bytes.charCodeAt(i));
- }
- }
-
- // The leftwost bit denotes a "critical" packet, but we ignore it.
- var type = bytes.charCodeAt(mypos++) & 0x7F;
- var seconds;
-
- // subpacket type
- switch (type) {
- case 2:
- // Signature Creation Time
- this.created = util.readDate(bytes.substr(mypos));
- break;
- case 3:
- // Signature Expiration Time in seconds
- seconds = util.readNumber(bytes.substr(mypos));
-
- this.signatureNeverExpires = seconds === 0;
- this.signatureExpirationTime = seconds;
-
- break;
- case 4:
- // Exportable Certification
- this.exportable = bytes.charCodeAt(mypos++) == 1;
- break;
- case 5:
- // Trust Signature
- this.trustLevel = bytes.charCodeAt(mypos++);
- this.trustAmount = bytes.charCodeAt(mypos++);
- break;
- case 6:
- // Regular Expression
- this.regularExpression = bytes.substr(mypos);
- break;
- case 7:
- // Revocable
- this.revocable = bytes.charCodeAt(mypos++) == 1;
- break;
- case 9:
- // Key Expiration Time in seconds
- seconds = util.readNumber(bytes.substr(mypos));
-
- this.keyExpirationTime = seconds;
- this.keyNeverExpires = seconds === 0;
-
- break;
- case 11:
- // Preferred Symmetric Algorithms
- this.preferredSymmetricAlgorithms = [];
-
- while (mypos != bytes.length) {
- this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
- }
-
- break;
- case 12:
- // Revocation Key
- // (1 octet of class, 1 octet of public-key algorithm ID, 20
- // octets of
- // fingerprint)
- this.revocationKeyClass = bytes.charCodeAt(mypos++);
- this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
- this.revocationKeyFingerprint = bytes.substr(mypos, 20);
- break;
-
- case 16:
- // Issuer
- this.issuerKeyId.read(bytes.substr(mypos));
- break;
-
- case 20:
- // Notation Data
- // We don't know how to handle anything but a text flagged data.
- if (bytes.charCodeAt(mypos) == 0x80) {
-
- // We extract key/value tuple from the byte stream.
- mypos += 4;
- var m = util.readNumber(bytes.substr(mypos, 2));
- mypos += 2;
- var n = util.readNumber(bytes.substr(mypos, 2));
- mypos += 2;
-
- var name = bytes.substr(mypos, m),
- value = bytes.substr(mypos + m, n);
-
- this.notation = this.notation || {};
- this.notation[name] = value;
- } else throw new Error("Unsupported notation flag.");
- break;
- case 21:
- // Preferred Hash Algorithms
- read_array.call(this, 'preferredHashAlgorithms', bytes.substr(mypos));
- break;
- case 22:
- // Preferred Compression Algorithms
- read_array.call(this, 'preferredCompressionAlgorithms ', bytes.substr(mypos));
- break;
- case 23:
- // Key Server Preferences
- read_array.call(this, 'keyServerPreferencess', bytes.substr(mypos));
- break;
- case 24:
- // Preferred Key Server
- this.preferredKeyServer = bytes.substr(mypos);
- break;
- case 25:
- // Primary User ID
- this.isPrimaryUserID = bytes[mypos++] !== 0;
- break;
- case 26:
- // Policy URI
- this.policyURI = bytes.substr(mypos);
- break;
- case 27:
- // Key Flags
- read_array.call(this, 'keyFlags', bytes.substr(mypos));
- break;
- case 28:
- // Signer's User ID
- this.signersUserId += bytes.substr(mypos);
- break;
- case 29:
- // Reason for Revocation
- this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
- this.reasonForRevocationString = bytes.substr(mypos);
- break;
- case 30:
- // Features
- read_array.call(this, 'features', bytes.substr(mypos));
- break;
- case 31:
- // Signature Target
- // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
- this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
- this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
-
- var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
-
- this.signatureTargetHash = bytes.substr(mypos, len);
- break;
- case 32:
- // Embedded Signature
- this.embeddedSignature = new signature();
- this.embeddedSignature.read(bytes.substr(mypos));
- break;
- default:
- throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
- }
- };
-
- // Produces data to produce signature on
- this.toSign = function (type, data) {
- var t = enums.signature;
-
- switch (type) {
- case t.binary:
- case t.text:
- return data.getBytes();
-
- case t.standalone:
- return '';
-
- case t.cert_generic:
- case t.cert_persona:
- case t.cert_casual:
- case t.cert_positive:
- case t.cert_revocation:
- var packet, tag;
-
- if (data.userid !== undefined) {
- tag = 0xB4;
- packet = data.userid;
- } else if (data.userattribute !== undefined) {
- tag = 0xD1;
- packet = data.userattribute;
- } else throw new Error('Either a userid or userattribute packet needs to be ' +
- 'supplied for certification.');
-
- var bytes = packet.write();
-
- if (this.version == 4) {
- return this.toSign(t.key, data) +
- String.fromCharCode(tag) +
- util.writeNumber(bytes.length, 4) +
- bytes;
- } else if (this.version == 3) {
- return this.toSign(t.key, data) +
- bytes;
- }
- break;
-
- case t.subkey_binding:
- case t.key_binding:
- return this.toSign(t.key, data) + this.toSign(t.key, {
- key: data.bind
- });
-
- case t.key:
- if (data.key === undefined)
- throw new Error('Key packet is required for this sigtature.');
-
- return data.key.writeOld();
-
- case t.key_revocation:
- case t.subkey_revocation:
- return this.toSign(t.key, data);
- case t.timestamp:
- return '';
- case t.third_party:
- throw new Error('Not implemented');
- default:
- throw new Error('Unknown signature type.');
- }
- };
-
-
- this.calculateTrailer = function () {
- // calculating the trailer
- var trailer = '';
- // V3 signatures don't have a trailer
- if (this.version == 3) return trailer;
- trailer += String.fromCharCode(4); // Version
- trailer += String.fromCharCode(0xFF);
- trailer += util.writeNumber(this.signatureData.length, 4);
- return trailer;
- };
-
-
- /**
- * verifys the signature packet. Note: not signature types are implemented
- * @param {String|Object} data data which on the signature applies
- * @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) {
- var signatureType = enums.write(enums.signature, this.signatureType),
- publicKeyAlgorithm = enums.write(enums.publicKey, this.publicKeyAlgorithm),
- hashAlgorithm = enums.write(enums.hash, this.hashAlgorithm);
-
- var bytes = this.toSign(signatureType, data),
- trailer = this.calculateTrailer();
-
-
- var mpicount = 0;
- // Algorithm-Specific Fields for RSA signatures:
- // - multiprecision number (MPI) of RSA signature value m**d mod n.
- if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
- mpicount = 1;
- // Algorithm-Specific Fields for DSA signatures:
- // - MPI of DSA value r.
- // - MPI of DSA value s.
- else if (publicKeyAlgorithm == 17)
- mpicount = 2;
-
- var mpi = [],
- i = 0;
- for (var j = 0; j < mpicount; j++) {
- mpi[j] = new type_mpi();
- i += mpi[j].read(this.signature.substr(i));
- }
-
- this.verified = crypto.signature.verify(publicKeyAlgorithm,
- hashAlgorithm, mpi, key.mpi,
- bytes + this.signatureData + trailer);
-
- return this.verified;
- };
-
- /**
- * Verifies signature expiration date
- * @return {Boolean} true if expired
- */
- this.isExpired = function () {
- if (!this.signatureNeverExpires) {
- return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
- }
- return false;
- };
+ this.signature = bytes.substr(i);
};
+Signature.prototype.write = function () {
+ return this.signatureData +
+ util.writeNumber(0, 2) + // Number of unsigned subpackets.
+ this.signedHashValue +
+ this.signature;
+};
+
+/**
+ * Signs provided data. This needs to be done prior to serialization.
+ * @param {module:packet/secret_key} key private key used to sign the message.
+ * @param {Object} data Contains packets to be signed.
+ */
+Signature.prototype.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);
+
+ var result = String.fromCharCode(4);
+ result += String.fromCharCode(signatureType);
+ result += String.fromCharCode(publicKeyAlgorithm);
+ result += String.fromCharCode(hashAlgorithm);
+
+ this.issuerKeyId = key.getKeyId();
+
+ // Add hashed subpackets
+ result += this.write_all_sub_packets();
+
+ this.signatureData = result;
+
+ var trailer = this.calculateTrailer();
+
+ var toHash = this.toSign(signatureType, data) +
+ this.signatureData + trailer;
+
+ var hash = crypto.hash.digest(hashAlgorithm, toHash);
+
+ this.signedHashValue = hash.substr(0, 2);
+
+ this.signature = crypto.signature.sign(hashAlgorithm,
+ publicKeyAlgorithm, key.mpi, toHash);
+};
+
+/**
+ * Creates string of bytes with all subpacket data
+ * @return {String} a string-representation of a all subpacket data
+ */
+Signature.prototype.write_all_sub_packets = function () {
+ var sub = enums.signatureSubpacket;
+ var result = '';
+ var bytes = '';
+ if (this.created !== null) {
+ result += write_sub_packet(sub.signature_creation_time, util.writeDate(this.created));
+ }
+ if (this.signatureExpirationTime !== null) {
+ result += write_sub_packet(sub.signature_expiration_time, util.writeNumber(this.signatureExpirationTime, 4));
+ }
+ if (this.exportable !== null) {
+ result += write_sub_packet(sub.exportable_certification, String.fromCharCode(this.exportable ? 1 : 0));
+ }
+ if (this.trustLevel !== null) {
+ bytes = String.fromCharCode(this.trustLevel) + String.fromCharCode(this.trustAmount);
+ result += write_sub_packet(sub.trust_signature, bytes);
+ }
+ if (this.regularExpression !== null) {
+ result += write_sub_packet(sub.regular_expression, this.regularExpression);
+ }
+ if (this.revocable !== null) {
+ result += write_sub_packet(sub.revocable, String.fromCharCode(this.revocable ? 1 : 0));
+ }
+ if (this.keyExpirationTime !== null) {
+ result += write_sub_packet(sub.key_expiration_time, util.writeNumber(this.keyExpirationTime, 4));
+ }
+ if (this.preferredSymmetricAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredSymmetricAlgorithms);
+ result += write_sub_packet(sub.preferred_symmetric_algorithms, bytes);
+ }
+ if (this.revocationKeyClass !== null) {
+ bytes = String.fromCharCode(this.revocationKeyClass);
+ bytes += String.fromCharCode(this.revocationKeyAlgorithm);
+ bytes += this.revocationKeyFingerprint;
+ result += write_sub_packet(sub.revocation_key, bytes);
+ }
+ if (!this.issuerKeyId.isNull()) {
+ result += write_sub_packet(sub.issuer, this.issuerKeyId.write());
+ }
+ if (this.notation !== null) {
+ for (var name in this.notation) {
+ if (this.notation.hasOwnProperty(name)) {
+ var value = this.notation[name];
+ bytes = String.fromCharCode(0x80);
+ bytes += String.fromCharCode(0);
+ bytes += String.fromCharCode(0);
+ bytes += String.fromCharCode(0);
+ // 2 octets of name length
+ bytes += util.writeNumber(name.length, 2);
+ // 2 octets of value length
+ bytes += util.writeNumber(value.length, 2);
+ bytes += name + value;
+ result += write_sub_packet(sub.notation_data, bytes);
+ }
+ }
+ }
+ if (this.preferredHashAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredHashAlgorithms);
+ result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
+ }
+ if (this.preferredCompressionAlgorithms !== null) {
+ bytes = util.bin2str(this.preferredCompressionAlgorithms);
+ result += write_sub_packet(sub.preferred_hash_algorithms, bytes);
+ }
+ if (this.keyServerPreferences !== null) {
+ bytes = util.bin2str(this.keyServerPreferences);
+ result += write_sub_packet(sub.key_server_preferences, bytes);
+ }
+ if (this.preferredKeyServer !== null) {
+ result += write_sub_packet(sub.preferred_key_server, this.preferredKeyServer);
+ }
+ if (this.isPrimaryUserID !== null) {
+ result += write_sub_packet(sub.primary_user_id, String.fromCharCode(this.isPrimaryUserID ? 1 : 0));
+ }
+ if (this.policyURI !== null) {
+ result += write_sub_packet(sub.policy_uri, this.policyURI);
+ }
+ if (this.keyFlags !== null) {
+ bytes = util.bin2str(this.keyFlags);
+ result += write_sub_packet(sub.key_flags, bytes);
+ }
+ if (this.signersUserId !== null) {
+ result += write_sub_packet(sub.signers_user_id, this.signersUserId);
+ }
+ if (this.reasonForRevocationFlag !== null) {
+ bytes = String.fromCharCode(this.reasonForRevocationFlag);
+ bytes += this.reasonForRevocationString;
+ result += write_sub_packet(sub.reason_for_revocation, bytes);
+ }
+ if (this.features !== null) {
+ bytes = util.bin2str(this.features);
+ result += write_sub_packet(sub.features, bytes);
+ }
+ if (this.signatureTargetPublicKeyAlgorithm !== null) {
+ bytes = String.fromCharCode(this.signatureTargetPublicKeyAlgorithm);
+ bytes += String.fromCharCode(this.signatureTargetHashAlgorithm);
+ bytes += this.signatureTargetHash;
+ result += write_sub_packet(sub.signature_target, bytes);
+ }
+ if (this.embeddedSignature !== null) {
+ result += write_sub_packet(sub.embedded_signature, this.embeddedSignature.write());
+ }
+ result = util.writeNumber(result.length, 2) + result;
+ return result;
+};
+
+/**
+ * creates a string representation of a sub signature packet (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.1|RFC 4880 5.2.3.1})
+ * @param {Integer} type subpacket signature type. Signature types as described
+ * in {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.2|RFC4880 Section 5.2.3.2}
+ * @param {String} data data to be included
+ * @return {String} a string-representation of a sub signature packet (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.3.1|RFC 4880 5.2.3.1})
+ */
+function write_sub_packet(type, data) {
+ var result = "";
+ result += packet.writeSimpleLength(data.length + 1);
+ result += String.fromCharCode(type);
+ result += data;
+ return result;
+}
+
+// V4 signature sub packets
+
+Signature.prototype.read_sub_packet = function (bytes) {
+ var mypos = 0;
+
+ function read_array(prop, bytes) {
+ this[prop] = [];
+
+ for (var i = 0; i < bytes.length; i++) {
+ this[prop].push(bytes.charCodeAt(i));
+ }
+ }
+
+ // The leftwost bit denotes a "critical" packet, but we ignore it.
+ var type = bytes.charCodeAt(mypos++) & 0x7F;
+ var seconds;
+
+ // subpacket type
+ switch (type) {
+ case 2:
+ // Signature Creation Time
+ this.created = util.readDate(bytes.substr(mypos));
+ break;
+ case 3:
+ // Signature Expiration Time in seconds
+ seconds = util.readNumber(bytes.substr(mypos));
+
+ this.signatureNeverExpires = seconds === 0;
+ this.signatureExpirationTime = seconds;
+
+ break;
+ case 4:
+ // Exportable Certification
+ this.exportable = bytes.charCodeAt(mypos++) == 1;
+ break;
+ case 5:
+ // Trust Signature
+ this.trustLevel = bytes.charCodeAt(mypos++);
+ this.trustAmount = bytes.charCodeAt(mypos++);
+ break;
+ case 6:
+ // Regular Expression
+ this.regularExpression = bytes.substr(mypos);
+ break;
+ case 7:
+ // Revocable
+ this.revocable = bytes.charCodeAt(mypos++) == 1;
+ break;
+ case 9:
+ // Key Expiration Time in seconds
+ seconds = util.readNumber(bytes.substr(mypos));
+
+ this.keyExpirationTime = seconds;
+ this.keyNeverExpires = seconds === 0;
+
+ break;
+ case 11:
+ // Preferred Symmetric Algorithms
+ this.preferredSymmetricAlgorithms = [];
+
+ while (mypos != bytes.length) {
+ this.preferredSymmetricAlgorithms.push(bytes.charCodeAt(mypos++));
+ }
+
+ break;
+ case 12:
+ // Revocation Key
+ // (1 octet of class, 1 octet of public-key algorithm ID, 20
+ // octets of
+ // fingerprint)
+ this.revocationKeyClass = bytes.charCodeAt(mypos++);
+ this.revocationKeyAlgorithm = bytes.charCodeAt(mypos++);
+ this.revocationKeyFingerprint = bytes.substr(mypos, 20);
+ break;
+
+ case 16:
+ // Issuer
+ this.issuerKeyId.read(bytes.substr(mypos));
+ break;
+
+ case 20:
+ // Notation Data
+ // We don't know how to handle anything but a text flagged data.
+ if (bytes.charCodeAt(mypos) == 0x80) {
+
+ // We extract key/value tuple from the byte stream.
+ mypos += 4;
+ var m = util.readNumber(bytes.substr(mypos, 2));
+ mypos += 2;
+ var n = util.readNumber(bytes.substr(mypos, 2));
+ mypos += 2;
+
+ var name = bytes.substr(mypos, m),
+ value = bytes.substr(mypos + m, n);
+
+ this.notation = this.notation || {};
+ this.notation[name] = value;
+ } else throw new Error("Unsupported notation flag.");
+ break;
+ case 21:
+ // Preferred Hash Algorithms
+ read_array.call(this, 'preferredHashAlgorithms', bytes.substr(mypos));
+ break;
+ case 22:
+ // Preferred Compression Algorithms
+ read_array.call(this, 'preferredCompressionAlgorithms ', bytes.substr(mypos));
+ break;
+ case 23:
+ // Key Server Preferences
+ read_array.call(this, 'keyServerPreferencess', bytes.substr(mypos));
+ break;
+ case 24:
+ // Preferred Key Server
+ this.preferredKeyServer = bytes.substr(mypos);
+ break;
+ case 25:
+ // Primary User ID
+ this.isPrimaryUserID = bytes[mypos++] !== 0;
+ break;
+ case 26:
+ // Policy URI
+ this.policyURI = bytes.substr(mypos);
+ break;
+ case 27:
+ // Key Flags
+ read_array.call(this, 'keyFlags', bytes.substr(mypos));
+ break;
+ case 28:
+ // Signer's User ID
+ this.signersUserId += bytes.substr(mypos);
+ break;
+ case 29:
+ // Reason for Revocation
+ this.reasonForRevocationFlag = bytes.charCodeAt(mypos++);
+ this.reasonForRevocationString = bytes.substr(mypos);
+ break;
+ case 30:
+ // Features
+ read_array.call(this, 'features', bytes.substr(mypos));
+ break;
+ case 31:
+ // Signature Target
+ // (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
+ this.signatureTargetPublicKeyAlgorithm = bytes.charCodeAt(mypos++);
+ this.signatureTargetHashAlgorithm = bytes.charCodeAt(mypos++);
+
+ var len = crypto.getHashByteLength(this.signatureTargetHashAlgorithm);
+
+ this.signatureTargetHash = bytes.substr(mypos, len);
+ break;
+ case 32:
+ // Embedded Signature
+ this.embeddedSignature = new Signature();
+ this.embeddedSignature.read(bytes.substr(mypos));
+ break;
+ default:
+ throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
+ }
+};
+
+// Produces data to produce signature on
+Signature.prototype.toSign = function (type, data) {
+ var t = enums.signature;
+
+ switch (type) {
+ case t.binary:
+ case t.text:
+ return data.getBytes();
+
+ case t.standalone:
+ return '';
+
+ case t.cert_generic:
+ case t.cert_persona:
+ case t.cert_casual:
+ case t.cert_positive:
+ case t.cert_revocation:
+ var packet, tag;
+
+ if (data.userid !== undefined) {
+ tag = 0xB4;
+ packet = data.userid;
+ } else if (data.userattribute !== undefined) {
+ tag = 0xD1;
+ packet = data.userattribute;
+ } else throw new Error('Either a userid or userattribute packet needs to be ' +
+ 'supplied for certification.');
+
+ var bytes = packet.write();
+
+ if (this.version == 4) {
+ return this.toSign(t.key, data) +
+ String.fromCharCode(tag) +
+ util.writeNumber(bytes.length, 4) +
+ bytes;
+ } else if (this.version == 3) {
+ return this.toSign(t.key, data) +
+ bytes;
+ }
+ break;
+
+ case t.subkey_binding:
+ case t.key_binding:
+ return this.toSign(t.key, data) + this.toSign(t.key, {
+ key: data.bind
+ });
+
+ case t.key:
+ if (data.key === undefined)
+ throw new Error('Key packet is required for this sigtature.');
+
+ return data.key.writeOld();
+
+ case t.key_revocation:
+ case t.subkey_revocation:
+ return this.toSign(t.key, data);
+ case t.timestamp:
+ return '';
+ case t.third_party:
+ throw new Error('Not implemented');
+ default:
+ throw new Error('Unknown signature type.');
+ }
+};
+
+
+Signature.prototype.calculateTrailer = function () {
+ // calculating the trailer
+ var trailer = '';
+ // V3 signatures don't have a trailer
+ if (this.version == 3) return trailer;
+ trailer += String.fromCharCode(4); // Version
+ trailer += String.fromCharCode(0xFF);
+ trailer += util.writeNumber(this.signatureData.length, 4);
+ return trailer;
+};
+
+
+/**
+ * verifys the signature packet. Note: not signature types are implemented
+ * @param {String|Object} data data which on the signature applies
+ * @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.
+ */
+Signature.prototype.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);
+
+ var bytes = this.toSign(signatureType, data),
+ trailer = this.calculateTrailer();
+
+
+ var mpicount = 0;
+ // Algorithm-Specific Fields for RSA signatures:
+ // - multiprecision number (MPI) of RSA signature value m**d mod n.
+ if (publicKeyAlgorithm > 0 && publicKeyAlgorithm < 4)
+ mpicount = 1;
+ // Algorithm-Specific Fields for DSA signatures:
+ // - MPI of DSA value r.
+ // - MPI of DSA value s.
+ else if (publicKeyAlgorithm == 17)
+ mpicount = 2;
+
+ var mpi = [],
+ i = 0;
+ for (var j = 0; j < mpicount; j++) {
+ mpi[j] = new type_mpi();
+ i += mpi[j].read(this.signature.substr(i));
+ }
+
+ this.verified = crypto.signature.verify(publicKeyAlgorithm,
+ hashAlgorithm, mpi, key.mpi,
+ bytes + this.signatureData + trailer);
+
+ return this.verified;
+};
+
+/**
+ * Verifies signature expiration date
+ * @return {Boolean} true if expired
+ */
+Signature.prototype.isExpired = function () {
+ if (!this.signatureNeverExpires) {
+ return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
+ }
+ return false;
+};
diff --git a/src/packet/sym_encrypted_integrity_protected.js b/src/packet/sym_encrypted_integrity_protected.js
index dec28bb5..6a6d8c1e 100644
--- a/src/packet/sym_encrypted_integrity_protected.js
+++ b/src/packet/sym_encrypted_integrity_protected.js
@@ -19,7 +19,8 @@
* Implementation of the Sym. Encrypted Integrity Protected Data
* Packet (Tag 18)
*
- * RFC4880 5.13: The Symmetrically Encrypted Integrity Protected Data packet is
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.13|RFC4880 5.13}:
+ * The Symmetrically Encrypted Integrity Protected Data packet is
* a variant of the Symmetrically Encrypted Data packet. It is a new feature
* created for OpenPGP that addresses the problem of detecting a modification to
* encrypted data. It is used in combination with a Modification Detection Code
@@ -29,13 +30,15 @@
* @module packet/sym_encrypted_integrity_protected
*/
+module.exports = SymEncryptedIntegrityProtected;
+
var util = require('../util'),
crypto = require('../crypto');
/**
* @constructor
*/
-module.exports = function sym_encrypted_integrity_protected() {
+function SymEncryptedIntegrityProtected() {
/** The encrypted payload. */
this.encrypted = null; // string
/**
@@ -46,76 +49,75 @@ module.exports = function sym_encrypted_integrity_protected() {
*/
this.modification = false;
this.packets = null;
+}
+SymEncryptedIntegrityProtected.prototype.read = function (bytes) {
+ // - A one-octet version number. The only currently defined value is 1.
+ var version = bytes.charCodeAt(0);
- this.read = function (bytes) {
- // - A one-octet version number. The only currently defined value is 1.
- var version = bytes.charCodeAt(0);
+ if (version != 1) {
+ throw new Error('Invalid packet version.');
+ }
- if (version != 1) {
- throw new Error('Invalid packet version.');
- }
-
- // - Encrypted data, the output of the selected symmetric-key cipher
- // operating in Cipher Feedback mode with shift amount equal to the
- // block size of the cipher (CFB-n where n is the block size).
- this.encrypted = bytes.substr(1);
- };
-
- this.write = function () {
-
- // 1 = Version
- return String.fromCharCode(1) + this.encrypted;
- };
-
- this.encrypt = function (sessionKeyAlgorithm, key) {
- var bytes = this.packets.write();
-
- var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
- var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
- 1);
-
- var tohash = bytes;
-
-
- // Modification detection code packet.
- tohash += String.fromCharCode(0xD3);
- tohash += String.fromCharCode(0x14);
-
-
- tohash += crypto.hash.sha1(prefix + tohash);
-
-
- this.encrypted = crypto.cfb.encrypt(prefixrandom,
- sessionKeyAlgorithm, tohash, key, false).substring(0,
- prefix.length + tohash.length);
- };
-
- /**
- * Decrypts the encrypted data contained in this object read_packet must
- * have been called before
- *
- * @param {Integer} sessionKeyAlgorithm
- * The selected symmetric encryption algorithm to be used
- * @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) {
- var decrypted = crypto.cfb.decrypt(
- sessionKeyAlgorithm, key, this.encrypted, false);
-
-
- // there must be a modification detection code packet as the
- // last packet and everything gets hashed except the hash itself
- this.hash = crypto.hash.sha1(
- crypto.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted) + decrypted.substring(0, decrypted.length - 20));
-
-
- var mdc = decrypted.substr(decrypted.length - 20, 20);
-
- if (this.hash != mdc) {
- throw new Error('Modification detected.');
- } else
- this.packets.read(decrypted.substr(0, decrypted.length - 22));
- };
+ // - Encrypted data, the output of the selected symmetric-key cipher
+ // operating in Cipher Feedback mode with shift amount equal to the
+ // block size of the cipher (CFB-n where n is the block size).
+ this.encrypted = bytes.substr(1);
+};
+
+SymEncryptedIntegrityProtected.prototype.write = function () {
+
+ // 1 = Version
+ return String.fromCharCode(1) + this.encrypted;
+};
+
+SymEncryptedIntegrityProtected.prototype.encrypt = function (sessionKeyAlgorithm, key) {
+ var bytes = this.packets.write();
+
+ var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
+ var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
+ 1);
+
+ var tohash = bytes;
+
+
+ // Modification detection code packet.
+ tohash += String.fromCharCode(0xD3);
+ tohash += String.fromCharCode(0x14);
+
+
+ tohash += crypto.hash.sha1(prefix + tohash);
+
+
+ this.encrypted = crypto.cfb.encrypt(prefixrandom,
+ sessionKeyAlgorithm, tohash, key, false).substring(0,
+ prefix.length + tohash.length);
+};
+
+/**
+ * Decrypts the encrypted data contained in this object read_packet must
+ * have been called before
+ *
+ * @param {module:enums.symmetric} sessionKeyAlgorithm
+ * The selected symmetric encryption algorithm to be used
+ * @param {String} key The key of cipher blocksize length to be used
+ * @return {String} The decrypted data of this packet
+ */
+SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm, key) {
+ var decrypted = crypto.cfb.decrypt(
+ sessionKeyAlgorithm, key, this.encrypted, false);
+
+
+ // there must be a modification detection code packet as the
+ // last packet and everything gets hashed except the hash itself
+ this.hash = crypto.hash.sha1(
+ crypto.cfb.mdc(sessionKeyAlgorithm, key, this.encrypted) + decrypted.substring(0, decrypted.length - 20));
+
+
+ var mdc = decrypted.substr(decrypted.length - 20, 20);
+
+ if (this.hash != mdc) {
+ throw new Error('Modification detected.');
+ } else
+ this.packets.read(decrypted.substr(0, decrypted.length - 22));
};
diff --git a/src/packet/sym_encrypted_session_key.js b/src/packet/sym_encrypted_session_key.js
index 68d7936e..d4ffe624 100644
--- a/src/packet/sym_encrypted_session_key.js
+++ b/src/packet/sym_encrypted_session_key.js
@@ -18,7 +18,7 @@
/**
* Public-Key Encrypted Session Key Packets (Tag 1)
*
- * RFC4880 5.1: A Public-Key Encrypted Session Key packet holds the session key
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}: A Public-Key Encrypted Session Key packet holds the session key
* used to encrypt a message. Zero or more Public-Key Encrypted Session Key
* packets and/or Symmetric-Key Encrypted Session Key packets may precede a
* Symmetrically Encrypted Data Packet, which holds an encrypted message. The
@@ -39,102 +39,104 @@ var type_s2k = require('../type/s2k.js'),
enums = require('../enums.js'),
crypto = require('../crypto');
+module.exports = SymEncryptedSessionKey;
+
/**
* @constructor
*/
-module.exports = function sym_encrypted_session_key() {
+function SymEncryptedSessionKey() {
this.tag = 3;
this.sessionKeyEncryptionAlgorithm = null;
this.sessionKeyAlgorithm = 'aes256';
this.encrypted = null;
this.s2k = new type_s2k();
+}
- /**
- * Parsing function for a symmetric encrypted session key packet (tag 3).
- *
- * @param {String} input Payload of a tag 1 packet
- * @param {Integer} position Position to start reading from the input string
- * @param {Integer} len
- * Length of the packet or the remaining length of
- * input at position
- * @return {module:packet/sym_encrypted_session_key} Object representation
- */
- this.read = function(bytes) {
- // A one-octet version number. The only currently defined version is 4.
- this.version = bytes.charCodeAt(0);
+/**
+ * Parsing function for a symmetric encrypted session key packet (tag 3).
+ *
+ * @param {String} input Payload of a tag 1 packet
+ * @param {Integer} position Position to start reading from the input string
+ * @param {Integer} len
+ * Length of the packet or the remaining length of
+ * input at position
+ * @return {module:packet/sym_encrypted_session_key} Object representation
+ */
+SymEncryptedSessionKey.prototype.read = function(bytes) {
+ // A one-octet version number. The only currently defined version is 4.
+ this.version = bytes.charCodeAt(0);
- // A one-octet number describing the symmetric algorithm used.
- var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
+ // A one-octet number describing the symmetric algorithm used.
+ var algo = enums.read(enums.symmetric, bytes.charCodeAt(1));
- // A string-to-key (S2K) specifier, length as defined above.
- var s2klength = this.s2k.read(bytes.substr(2));
+ // A string-to-key (S2K) specifier, length as defined above.
+ var s2klength = this.s2k.read(bytes.substr(2));
- // Optionally, the encrypted session key itself, which is decrypted
- // with the string-to-key object.
- var done = s2klength + 2;
+ // Optionally, the encrypted session key itself, which is decrypted
+ // with the string-to-key object.
+ var done = s2klength + 2;
- if (done < bytes.length) {
- this.encrypted = bytes.substr(done);
- this.sessionKeyEncryptionAlgorithm = algo;
- } else
- this.sessionKeyAlgorithm = algo;
- };
-
- this.write = function() {
- var algo = this.encrypted === null ?
- this.sessionKeyAlgorithm :
- this.sessionKeyEncryptionAlgorithm;
-
- var bytes = String.fromCharCode(this.version) +
- String.fromCharCode(enums.write(enums.symmetric, algo)) +
- this.s2k.write();
-
- if (this.encrypted !== null)
- bytes += this.encrypted;
- return bytes;
- };
-
- /**
- * Decrypts the session key (only for public key encrypted session key
- * packets (tag 1)
- *
- * @return {String} The unencrypted session key
- */
- this.decrypt = function(passphrase) {
- var algo = this.sessionKeyEncryptionAlgorithm !== null ?
- this.sessionKeyEncryptionAlgorithm :
- this.sessionKeyAlgorithm;
-
-
- var length = crypto.cipher[algo].keySize;
- var key = this.s2k.produce_key(passphrase, length);
-
- if (this.encrypted === null) {
- this.sessionKey = key;
-
- } else {
- var decrypted = crypto.cfb.decrypt(
- this.sessionKeyEncryptionAlgorithm, key, this.encrypted, true);
-
- this.sessionKeyAlgorithm = enums.read(enums.symmetric,
- decrypted[0].keyCodeAt());
-
- this.sessionKey = decrypted.substr(1);
- }
- };
-
- this.encrypt = function(passphrase) {
- var length = crypto.getKeyLength(this.sessionKeyEncryptionAlgorithm);
- var key = this.s2k.produce_key(passphrase, length);
-
- var private_key = String.fromCharCode(
- enums.write(enums.symmetric, this.sessionKeyAlgorithm)) +
-
- crypto.getRandomBytes(
- crypto.getKeyLength(this.sessionKeyAlgorithm));
-
- this.encrypted = crypto.cfb.encrypt(
- crypto.getPrefixRandom(this.sessionKeyEncryptionAlgorithm),
- this.sessionKeyEncryptionAlgorithm, key, private_key, true);
- };
+ if (done < bytes.length) {
+ this.encrypted = bytes.substr(done);
+ this.sessionKeyEncryptionAlgorithm = algo;
+ } else
+ this.sessionKeyAlgorithm = algo;
+};
+
+SymEncryptedSessionKey.prototype.write = function() {
+ var algo = this.encrypted === null ?
+ this.sessionKeyAlgorithm :
+ this.sessionKeyEncryptionAlgorithm;
+
+ var bytes = String.fromCharCode(this.version) +
+ String.fromCharCode(enums.write(enums.symmetric, algo)) +
+ this.s2k.write();
+
+ if (this.encrypted !== null)
+ bytes += this.encrypted;
+ return bytes;
+};
+
+/**
+ * Decrypts the session key (only for public key encrypted session key
+ * packets (tag 1)
+ *
+ * @return {String} The unencrypted session key
+ */
+SymEncryptedSessionKey.prototype.decrypt = function(passphrase) {
+ var algo = this.sessionKeyEncryptionAlgorithm !== null ?
+ this.sessionKeyEncryptionAlgorithm :
+ this.sessionKeyAlgorithm;
+
+
+ var length = crypto.cipher[algo].keySize;
+ var key = this.s2k.produce_key(passphrase, length);
+
+ if (this.encrypted === null) {
+ this.sessionKey = key;
+
+ } else {
+ var decrypted = crypto.cfb.decrypt(
+ this.sessionKeyEncryptionAlgorithm, key, this.encrypted, true);
+
+ this.sessionKeyAlgorithm = enums.read(enums.symmetric,
+ decrypted[0].keyCodeAt());
+
+ this.sessionKey = decrypted.substr(1);
+ }
+};
+
+SymEncryptedSessionKey.prototype.encrypt = function(passphrase) {
+ var length = crypto.getKeyLength(this.sessionKeyEncryptionAlgorithm);
+ var key = this.s2k.produce_key(passphrase, length);
+
+ var private_key = String.fromCharCode(
+ enums.write(enums.symmetric, this.sessionKeyAlgorithm)) +
+
+ crypto.getRandomBytes(
+ crypto.getKeyLength(this.sessionKeyAlgorithm));
+
+ this.encrypted = crypto.cfb.encrypt(
+ crypto.getPrefixRandom(this.sessionKeyEncryptionAlgorithm),
+ this.sessionKeyEncryptionAlgorithm, key, private_key, true);
};
diff --git a/src/packet/symmetrically_encrypted.js b/src/packet/symmetrically_encrypted.js
index cc949d93..3c3020fe 100644
--- a/src/packet/symmetrically_encrypted.js
+++ b/src/packet/symmetrically_encrypted.js
@@ -18,7 +18,7 @@
/**
* Implementation of the Symmetrically Encrypted Data Packet (Tag 9)
*
- * RFC4880 5.7: The Symmetrically Encrypted Data packet contains data encrypted
+ * {@link http://tools.ietf.org/html/rfc4880#section-5.7|RFC4880 5.7}: The Symmetrically Encrypted Data packet contains data encrypted
* with a symmetric-key algorithm. When it has been decrypted, it contains other
* packets (usually a literal data packet or compressed data packet, but in
* theory other Symmetrically Encrypted Data packets or sequences of packets
@@ -27,45 +27,47 @@
* @module packet/symmetrically_encrypted
*/
+module.exports = SymmetricallyEncrypted;
+
var crypto = require('../crypto');
/**
* @constructor
*/
-module.exports = function symmetrically_encrypted() {
+function SymmetricallyEncrypted() {
this.encrypted = null;
/** Decrypted packets contained within.
* @type {module:packet/packetlist} */
this.packets = null;
+}
- this.read = function(bytes) {
- this.encrypted = bytes;
- };
-
- this.write = function() {
- return this.encrypted;
- };
-
- /**
- * Symmetrically decrypt the packet data
- *
- * @param {Integer} sessionKeyAlgorithm
- * Symmetric key algorithm to use // See RFC4880 9.2
- * @param {String} key
- * Key as string with the corresponding length to the
- * algorithm
- */
- this.decrypt = function(sessionKeyAlgorithm, key) {
- var decrypted = crypto.cfb.decrypt(
- sessionKeyAlgorithm, key, this.encrypted, true);
-
- this.packets.read(decrypted);
- };
-
- this.encrypt = function(algo, key) {
- var data = this.packets.write();
-
- this.encrypted = crypto.cfb.encrypt(
- crypto.getPrefixRandom(algo), algo, data, key, true);
- };
+SymmetricallyEncrypted.prototype.read = function (bytes) {
+ this.encrypted = bytes;
+};
+
+SymmetricallyEncrypted.prototype.write = function () {
+ return this.encrypted;
+};
+
+/**
+ * Symmetrically decrypt the packet data
+ *
+ * @param {module:enums.symmetric} sessionKeyAlgorithm
+ * Symmetric key algorithm to use // See {@link http://tools.ietf.org/html/rfc4880#section-9.2|RFC4880 9.2}
+ * @param {String} key
+ * Key as string with the corresponding length to the
+ * algorithm
+ */
+SymmetricallyEncrypted.prototype.decrypt = function (sessionKeyAlgorithm, key) {
+ var decrypted = crypto.cfb.decrypt(
+ sessionKeyAlgorithm, key, this.encrypted, true);
+
+ this.packets.read(decrypted);
+};
+
+SymmetricallyEncrypted.prototype.encrypt = function (algo, key) {
+ var data = this.packets.write();
+
+ this.encrypted = crypto.cfb.encrypt(
+ crypto.getPrefixRandom(algo), algo, data, key, true);
};
diff --git a/src/packet/trust.js b/src/packet/trust.js
index f35ce337..e96b3c33 100644
--- a/src/packet/trust.js
+++ b/src/packet/trust.js
@@ -2,9 +2,10 @@
* @module packet/trust
*/
+module.exports = Trust;
+
/**
* @constructor
*/
-module.exports = function trust() {
-
+function Trust() {
};
diff --git a/src/packet/user_attribute.js b/src/packet/user_attribute.js
index fc344d21..787739dd 100644
--- a/src/packet/user_attribute.js
+++ b/src/packet/user_attribute.js
@@ -38,25 +38,26 @@
var util = require('../util'),
packet = require('./packet.js');
+module.exports = UserAttribute;
+
/**
* @constructor
*/
-module.exports = function user_attribute() {
- this.tag = 17;
+function UserAttribute() {
this.attributes = [];
+}
- /**
- * parsing function for a user attribute packet (tag 17).
- * @param {String} input payload of a tag 17 packet
- */
- this.read = function(bytes) {
- var i = 0;
- while (i < bytes.length) {
- var len = packet.readSimpleLength(bytes.substr(i));
- i += len.offset;
+/**
+ * parsing function for a user attribute packet (tag 17).
+ * @param {String} input payload of a tag 17 packet
+ */
+UserAttribute.prototype.read = function(bytes) {
+ var i = 0;
+ while (i < bytes.length) {
+ var len = packet.readSimpleLength(bytes.substr(i));
+ i += len.offset;
- this.attributes.push(bytes.substr(i, len.len));
- i += len.len;
- }
- };
+ this.attributes.push(bytes.substr(i, len.len));
+ i += len.len;
+ }
};
diff --git a/src/packet/userid.js b/src/packet/userid.js
index fb983daa..bc0ad6a8 100644
--- a/src/packet/userid.js
+++ b/src/packet/userid.js
@@ -27,32 +27,33 @@
* @module packet/userid
*/
+module.exports = Userid;
+
var util = require('../util');
/**
* @constructor
*/
-module.exports = function userid() {
+function Userid() {
/** A string containing the user id. Usually in the form
* John Doe
* @type {String}
*/
this.userid = '';
+}
-
- /**
- * Parsing function for a user id packet (tag 13).
- * @param {String} input payload of a tag 13 packet
- */
- this.read = function (bytes) {
- this.userid = util.decode_utf8(bytes);
- };
-
- /**
- * Creates a string representation of the user id packet
- * @return {String} string representation
- */
- this.write = function () {
- return util.encode_utf8(this.userid);
- };
+/**
+ * Parsing function for a user id packet (tag 13).
+ * @param {String} input payload of a tag 13 packet
+ */
+Userid.prototype.read = function (bytes) {
+ this.userid = util.decode_utf8(bytes);
+};
+
+/**
+ * Creates a string representation of the user id packet
+ * @return {String} string representation
+ */
+Userid.prototype.write = function () {
+ return util.encode_utf8(this.userid);
};
diff --git a/src/type/keyid.js b/src/type/keyid.js
index 5a632f3d..84b3bcdc 100644
--- a/src/type/keyid.js
+++ b/src/type/keyid.js
@@ -16,7 +16,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
- * Implementation of type key id (RFC4880 3.3)
+ * Implementation of type key id ({@link http://tools.ietf.org/html/rfc4880#section-3.3|RFC4880 3.3})
*
* A Key ID is an eight-octet scalar that identifies a key.
* Implementations SHOULD NOT assume that Key IDs are unique. The
@@ -26,41 +26,42 @@
* @module type/keyid
*/
+module.exports = Keyid;
+
var util = require('../util');
/**
* @constructor
*/
-module.exports = function keyid() {
+function Keyid() {
this.bytes = '';
+}
-
- /**
- * Parsing method for a key id
- * @param {String} input Input to read the key id from
- */
- this.read = function(bytes) {
- this.bytes = bytes.substr(0, 8);
- };
-
- this.write = function() {
- return this.bytes;
- };
-
- this.toHex = function() {
- return util.hexstrdump(this.bytes);
- };
-
- this.equals = function(keyid) {
- return this.bytes == keyid.bytes;
- };
-
- this.isNull = function() {
- return this.bytes === '';
- };
+/**
+ * Parsing method for a key id
+ * @param {String} input Input to read the key id from
+ */
+Keyid.prototype.read = function(bytes) {
+ this.bytes = bytes.substr(0, 8);
};
-module.exports.mapToHex = function(keyId) {
+Keyid.prototype.write = function() {
+ return this.bytes;
+};
+
+Keyid.prototype.toHex = function() {
+ return util.hexstrdump(this.bytes);
+};
+
+Keyid.prototype.equals = function(keyid) {
+ return this.bytes == keyid.bytes;
+};
+
+Keyid.prototype.isNull = function() {
+ return this.bytes === '';
+};
+
+module.exports.mapToHex = function (keyId) {
return keyId.toHex();
};
diff --git a/src/type/mpi.js b/src/type/mpi.js
index a094cee1..22afa903 100644
--- a/src/type/mpi.js
+++ b/src/type/mpi.js
@@ -21,7 +21,7 @@
// - MPI = c | d << 8 | e << ((MPI.length -2)*8) | f ((MPI.length -2)*8)
/**
- * Implementation of type MPI (RFC4880 3.2)
+ * Implementation of type MPI ({@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2})
*
* Multiprecision integers (also called MPIs) are unsigned integers used
* to hold large integers such as the ones used in cryptographic
@@ -34,67 +34,69 @@
* @module type/mpi
*/
+module.exports = MPI;
+
var BigInteger = require('../crypto/public_key/jsbn.js'),
util = require('../util');
/**
* @constructor
*/
-module.exports = function mpi() {
+function MPI() {
/** An implementation dependent integer */
this.data = null;
+}
- /**
- * Parsing function for a mpi (RFC 4880 3.2).
- * @param {String} input Payload of mpi data
- * @return {Integer} Length of data read
- */
- this.read = function (bytes) {
- var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
+/**
+ * Parsing function for a mpi ({@link http://tools.ietf.org/html/rfc4880#section3.2|RFC 4880 3.2}).
+ * @param {String} input Payload of mpi data
+ * @return {Integer} Length of data read
+ */
+MPI.prototype.read = function (bytes) {
+ var bits = (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
- // Additional rules:
- //
- // The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
- //
- // The length field of an MPI describes the length starting from its
- // most significant non-zero bit. Thus, the MPI [00 02 01] is not
- // formed correctly. It should be [00 01 01].
+ // Additional rules:
+ //
+ // The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
+ //
+ // The length field of an MPI describes the length starting from its
+ // most significant non-zero bit. Thus, the MPI [00 02 01] is not
+ // formed correctly. It should be [00 01 01].
- // TODO: Verification of this size method! This size calculation as
- // specified above is not applicable in JavaScript
- var bytelen = Math.ceil(bits / 8);
+ // TODO: Verification of this size method! This size calculation as
+ // specified above is not applicable in JavaScript
+ var bytelen = Math.ceil(bits / 8);
- var raw = bytes.substr(2, bytelen);
- this.fromBytes(raw);
+ var raw = bytes.substr(2, bytelen);
+ this.fromBytes(raw);
- return 2 + bytelen;
- };
-
- this.fromBytes = function (bytes) {
- this.data = new BigInteger(util.hexstrdump(bytes), 16);
- };
-
- this.toBytes = function () {
- return this.write().substr(2);
- };
-
- this.byteLength = function () {
- return this.toBytes().length;
- };
-
- /**
- * Converts the mpi object to a string as specified in RFC4880 3.2
- * @return {String} mpi Byte representation
- */
- this.write = function () {
- return this.data.toMPI();
- };
-
- this.toBigInteger = function () {
- return this.data.clone();
- };
-
- this.fromBigInteger = function (bn) {
- this.data = bn.clone();
- };
+ return 2 + bytelen;
+};
+
+MPI.prototype.fromBytes = function (bytes) {
+ this.data = new BigInteger(util.hexstrdump(bytes), 16);
+};
+
+MPI.prototype.toBytes = function () {
+ return this.write().substr(2);
+};
+
+MPI.prototype.byteLength = function () {
+ return this.toBytes().length;
+};
+
+/**
+ * Converts the mpi object to a string as specified in {@link http://tools.ietf.org/html/rfc4880#section-3.2|RFC4880 3.2}
+ * @return {String} mpi Byte representation
+ */
+MPI.prototype.write = function () {
+ return this.data.toMPI();
+};
+
+MPI.prototype.toBigInteger = function () {
+ return this.data.clone();
+};
+
+MPI.prototype.fromBigInteger = function (bn) {
+ this.data = bn.clone();
};
diff --git a/src/type/s2k.js b/src/type/s2k.js
index 48e680de..3de47042 100644
--- a/src/type/s2k.js
+++ b/src/type/s2k.js
@@ -16,7 +16,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
- * Implementation of the String-to-key specifier (RFC4880 3.7)
+ * Implementation of the String-to-key specifier ({@link http://tools.ietf.org/html/rfc4880#section-3.7|RFC4880 3.7})
*
* String-to-key (S2K) specifiers are used to convert passphrase strings
* into symmetric-key encryption/decryption keys. They are used in two
@@ -29,6 +29,8 @@
* @module type/s2k
*/
+module.exports = S2K;
+
var enums = require('../enums.js'),
util = require('../util'),
crypto = require('../crypto');
@@ -36,7 +38,7 @@ var enums = require('../enums.js'),
/**
* @constructor
*/
-module.exports = function s2k() {
+function S2K() {
/** @type {module:enums.hash} */
this.algorithm = 'sha256';
/** @type {module:enums.s2k} */
@@ -46,134 +48,133 @@ module.exports = function s2k() {
* @type {String}
*/
this.salt = crypto.random.getRandomBytes(8);
+}
-
+S2K.prototype.get_count = function () {
// Exponent bias, defined in RFC4880
var expbias = 6;
- this.get_count = function () {
- return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
- };
-
- /**
- * Parsing function for a string-to-key specifier (RFC 4880 3.7).
- * @param {String} input Payload of string-to-key specifier
- * @return {Integer} Actual length of the object
- */
- 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++));
-
- switch (this.type) {
- case 'simple':
- break;
-
- case 'salted':
- this.salt = bytes.substr(i, 8);
- i += 8;
- break;
-
- case 'iterated':
- this.salt = bytes.substr(i, 8);
- i += 8;
-
- // Octet 10: count, a one-octet, coded value
- this.c = bytes.charCodeAt(i++);
- break;
-
- case 'gnu':
- if (bytes.substr(i, 3) == "GNU") {
- i += 3; // GNU
- var gnuExtType = 1000 + bytes.charCodeAt(i++);
- if (gnuExtType == 1001) {
- this.type = gnuExtType;
- // GnuPG extension mode 1001 -- don't write secret key at all
- } else {
- throw new Error("Unknown s2k gnu protection mode.");
- }
- } else {
- throw new Error("Unknown s2k type.");
- }
- break;
-
- default:
- throw new Error("Unknown s2k type.");
- }
-
- return i;
- };
-
-
- /**
- * writes an s2k hash based on the inputs.
- * @return {String} Produced key of hashAlgorithm hash length
- */
- this.write = function () {
- var bytes = String.fromCharCode(enums.write(enums.s2k, this.type));
- bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm));
-
- switch (this.type) {
- case 'simple':
- break;
- case 'salted':
- bytes += this.salt;
- break;
- case 'iterated':
- bytes += this.salt;
- bytes += String.fromCharCode(this.c);
- break;
- }
-
- return bytes;
- };
-
- /**
- * Produces a key using the specified passphrase and the defined
- * hashAlgorithm
- * @param {String} passphrase Passphrase containing user input
- * @return {String} Produced key with a length corresponding to
- * hashAlgorithm hash length
- */
- this.produce_key = function (passphrase, numBytes) {
- passphrase = util.encode_utf8(passphrase);
-
- function round(prefix, s2k) {
- var algorithm = enums.write(enums.hash, s2k.algorithm);
-
- switch (s2k.type) {
- case 'simple':
- return crypto.hash.digest(algorithm, prefix + passphrase);
-
- case 'salted':
- return crypto.hash.digest(algorithm,
- prefix + s2k.salt + passphrase);
-
- case 'iterated':
- var isp = [],
- count = s2k.get_count();
- data = s2k.salt + passphrase;
-
- while (isp.length * data.length < count)
- isp.push(data);
-
- isp = isp.join('');
-
- if (isp.length > count)
- isp = isp.substr(0, count);
-
- return crypto.hash.digest(algorithm, prefix + isp);
- }
- }
-
- var result = '',
- prefix = '';
-
- while (result.length <= numBytes) {
- result += round(prefix, this);
- prefix += String.fromCharCode(0);
- }
-
- return result.substr(0, numBytes);
- };
+ return (16 + (this.c & 15)) << ((this.c >> 4) + expbias);
+};
+
+/**
+ * Parsing function for a string-to-key specifier ({@link http://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
+ * @param {String} input Payload of string-to-key specifier
+ * @return {Integer} Actual length of the object
+ */
+S2K.prototype.read = function (bytes) {
+ var i = 0;
+ this.type = enums.read(enums.s2k, bytes.charCodeAt(i++));
+ this.algorithm = enums.read(enums.hash, bytes.charCodeAt(i++));
+
+ switch (this.type) {
+ case 'simple':
+ break;
+
+ case 'salted':
+ this.salt = bytes.substr(i, 8);
+ i += 8;
+ break;
+
+ case 'iterated':
+ this.salt = bytes.substr(i, 8);
+ i += 8;
+
+ // Octet 10: count, a one-octet, coded value
+ this.c = bytes.charCodeAt(i++);
+ break;
+
+ case 'gnu':
+ if (bytes.substr(i, 3) == "GNU") {
+ i += 3; // GNU
+ var gnuExtType = 1000 + bytes.charCodeAt(i++);
+ if (gnuExtType == 1001) {
+ this.type = gnuExtType;
+ // GnuPG extension mode 1001 -- don't write secret key at all
+ } else {
+ throw new Error("Unknown s2k gnu protection mode.");
+ }
+ } else {
+ throw new Error("Unknown s2k type.");
+ }
+ break;
+
+ default:
+ throw new Error("Unknown s2k type.");
+ }
+
+ return i;
+};
+
+
+/**
+ * writes an s2k hash based on the inputs.
+ * @return {String} Produced key of hashAlgorithm hash length
+ */
+S2K.prototype.write = function () {
+ var bytes = String.fromCharCode(enums.write(enums.s2k, this.type));
+ bytes += String.fromCharCode(enums.write(enums.hash, this.algorithm));
+
+ switch (this.type) {
+ case 'simple':
+ break;
+ case 'salted':
+ bytes += this.salt;
+ break;
+ case 'iterated':
+ bytes += this.salt;
+ bytes += String.fromCharCode(this.c);
+ break;
+ }
+
+ return bytes;
+};
+
+/**
+ * Produces a key using the specified passphrase and the defined
+ * hashAlgorithm
+ * @param {String} passphrase Passphrase containing user input
+ * @return {String} Produced key with a length corresponding to
+ * hashAlgorithm hash length
+ */
+S2K.prototype.produce_key = function (passphrase, numBytes) {
+ passphrase = util.encode_utf8(passphrase);
+
+ function round(prefix, s2k) {
+ var algorithm = enums.write(enums.hash, s2k.algorithm);
+
+ switch (s2k.type) {
+ case 'simple':
+ return crypto.hash.digest(algorithm, prefix + passphrase);
+
+ case 'salted':
+ return crypto.hash.digest(algorithm,
+ prefix + s2k.salt + passphrase);
+
+ case 'iterated':
+ var isp = [],
+ count = s2k.get_count();
+ data = s2k.salt + passphrase;
+
+ while (isp.length * data.length < count)
+ isp.push(data);
+
+ isp = isp.join('');
+
+ if (isp.length > count)
+ isp = isp.substr(0, count);
+
+ return crypto.hash.digest(algorithm, prefix + isp);
+ }
+ }
+
+ var result = '',
+ prefix = '';
+
+ while (result.length <= numBytes) {
+ result += round(prefix, this);
+ prefix += String.fromCharCode(0);
+ }
+
+ return result.substr(0, numBytes);
};
diff --git a/test/general/key.js b/test/general/key.js
index 1cf127c1..ce7e8d36 100644
--- a/test/general/key.js
+++ b/test/general/key.js
@@ -265,7 +265,7 @@ describe('Key', function() {
var pubKey = pubKeys.keys[0];
expect(pubKey).to.exist;
- var packetlist = new openpgp.packet.list();
+ var packetlist = new openpgp.packet.List();
packetlist.read(openpgp.armor.decode(pub_sig_test).data);
diff --git a/test/general/keyring.js b/test/general/keyring.js
index dd37d8d6..271c0df8 100644
--- a/test/general/keyring.js
+++ b/test/general/keyring.js
@@ -1,7 +1,7 @@
'use strict';
var openpgp = require('openpgp'),
- keyring = new (new require('keyring'))(),
+ keyring = new (require('keyring'))(),
expect = chai.expect;
describe("Keyring", function() {
diff --git a/test/general/packet.js b/test/general/packet.js
index 8b2dba28..ab84d779 100644
--- a/test/general/packet.js
+++ b/test/general/packet.js
@@ -43,12 +43,12 @@ describe("Packet", function() {
'-----END PGP PRIVATE KEY BLOCK-----';
it('Symmetrically encrypted packet', function(done) {
- var message = new openpgp.packet.list();
+ var message = new openpgp.packet.List();
- var literal = new openpgp.packet.literal();
+ var literal = new openpgp.packet.Literal();
literal.setText('Hello world');
- var enc = new openpgp.packet.symmetrically_encrypted();
+ var enc = new openpgp.packet.SymmetricallyEncrypted();
message.push(enc);
enc.packets.push(literal);
@@ -57,7 +57,7 @@ describe("Packet", function() {
enc.encrypt(algo, key);
- var msg2 = new openpgp.packet.list();
+ var msg2 = new openpgp.packet.List();
msg2.read(message.write());
msg2[0].decrypt(algo, key);
@@ -70,16 +70,16 @@ describe("Packet", function() {
var key = '12345678901234567890123456789012',
algo = 'aes256';
- var literal = new openpgp.packet.literal(),
- enc = new openpgp.packet.sym_encrypted_integrity_protected(),
- msg = new openpgp.packet.list();
+ var literal = new openpgp.packet.Literal(),
+ enc = new openpgp.packet.SymEncryptedIntegrityProtected(),
+ msg = new openpgp.packet.List();
msg.push(enc);
literal.setText('Hello world!');
enc.packets.push(literal);
enc.encrypt(algo, key);
- var msg2 = new openpgp.packet.list();
+ var msg2 = new openpgp.packet.List();
msg2.read(msg.write());
msg2[0].decrypt(algo, key);
@@ -100,7 +100,7 @@ describe("Packet", function() {
var msgbytes = openpgp.armor.decode(msg).data;
- var parsed = new openpgp.packet.list();
+ var parsed = new openpgp.packet.List();
parsed.read(msgbytes);
parsed[0].decrypt('test');
@@ -127,9 +127,9 @@ describe("Packet", function() {
return mpi;
});
- var enc = new openpgp.packet.public_key_encrypted_session_key(),
- msg = new openpgp.packet.list(),
- msg2 = new openpgp.packet.list();
+ var enc = new openpgp.packet.PublicKeyEncryptedSessionKey(),
+ msg = new openpgp.packet.List(),
+ msg2 = new openpgp.packet.List();
enc.sessionKey = '12345678901234567890123456789012';
enc.publicKeyAlgorithm = 'rsa_encrypt';
@@ -171,11 +171,11 @@ describe("Packet", function() {
'=lKiS\n' +
'-----END PGP PRIVATE KEY BLOCK-----';
- var key = new openpgp.packet.list();
+ var key = new openpgp.packet.List();
key.read(openpgp.armor.decode(armored_key).data);
key = key[0];
- var enc = new openpgp.packet.public_key_encrypted_session_key(),
+ var enc = new openpgp.packet.PublicKeyEncryptedSessionKey(),
secret = '12345678901234567890123456789012';
enc.sessionKey = secret;
@@ -240,11 +240,11 @@ describe("Packet", function() {
'-----END PGP MESSAGE-----';
- var key = new openpgp.packet.list();
+ var key = new openpgp.packet.List();
key.read(openpgp.armor.decode(armored_key).data);
key = key[3];
- var msg = new openpgp.packet.list();
+ var msg = new openpgp.packet.List();
msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key);
@@ -260,10 +260,10 @@ describe("Packet", function() {
var passphrase = 'hello',
algo = 'aes256';
- var literal = new openpgp.packet.literal(),
- key_enc = new openpgp.packet.sym_encrypted_session_key(),
- enc = new openpgp.packet.sym_encrypted_integrity_protected(),
- msg = new openpgp.packet.list();
+ var literal = new openpgp.packet.Literal(),
+ key_enc = new openpgp.packet.SymEncryptedSessionKey(),
+ enc = new openpgp.packet.SymEncryptedIntegrityProtected(),
+ msg = new openpgp.packet.List();
msg.push(key_enc);
msg.push(enc);
@@ -278,7 +278,7 @@ describe("Packet", function() {
enc.encrypt(algo, key);
- var msg2 = new openpgp.packet.list();
+ var msg2 = new openpgp.packet.List();
msg2.read(msg.write());
msg2[0].decrypt(passphrase);
@@ -302,12 +302,12 @@ describe("Packet", function() {
'=pR+C\n' +
'-----END PGP MESSAGE-----';
- var key = new openpgp.packet.list();
+ var key = new openpgp.packet.List();
key.read(openpgp.armor.decode(armored_key).data);
key = key[3];
key.decrypt('test');
- var msg = new openpgp.packet.list();
+ var msg = new openpgp.packet.List();
msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key);
@@ -320,7 +320,7 @@ describe("Packet", function() {
});
it('Secret key reading with signature verification.', function(done) {
- var key = new openpgp.packet.list();
+ var key = new openpgp.packet.List();
key.read(openpgp.armor.decode(armored_key).data);
@@ -357,11 +357,11 @@ describe("Packet", function() {
'=htrB\n' +
'-----END PGP MESSAGE-----'
- var key = new openpgp.packet.list();
+ var key = new openpgp.packet.List();
key.read(openpgp.armor.decode(armored_key).data);
key[3].decrypt('test')
- var msg = new openpgp.packet.list();
+ var msg = new openpgp.packet.List();
msg.read(openpgp.armor.decode(armored_msg).data);
msg[0].decrypt(key[3]);
@@ -376,8 +376,8 @@ describe("Packet", function() {
});
it('Writing and encryption of a secret key packet.', function(done) {
- var key = new openpgp.packet.list();
- key.push(new openpgp.packet.secret_key);
+ var key = new openpgp.packet.List();
+ key.push(new openpgp.packet.SecretKey);
var rsa = new openpgp.crypto.publicKey.rsa(),
mpi = rsa.generate(512, "10001")
@@ -397,7 +397,7 @@ describe("Packet", function() {
var raw = key.write();
- var key2 = new openpgp.packet.list();
+ var key2 = new openpgp.packet.List();
key2.read(raw);
key2[0].decrypt('hello');
@@ -406,7 +406,7 @@ describe("Packet", function() {
});
it('Writing and verification of a signature packet.', function(done) {
- var key = new openpgp.packet.secret_key();
+ var key = new openpgp.packet.SecretKey();
var rsa = new openpgp.crypto.publicKey.rsa,
mpi = rsa.generate(512, "10001")
@@ -421,9 +421,9 @@ describe("Packet", function() {
key.mpi = mpi;
- var signed = new openpgp.packet.list(),
- literal = new openpgp.packet.literal(),
- signature = new openpgp.packet.signature();
+ var signed = new openpgp.packet.List(),
+ literal = new openpgp.packet.Literal(),
+ signature = new openpgp.packet.Signature();
literal.setText('Hello world');
@@ -438,7 +438,7 @@ describe("Packet", function() {
var raw = signed.write();
- var signed2 = new openpgp.packet.list();
+ var signed2 = new openpgp.packet.List();
signed2.read(raw);
var verified = signed2[1].verify(key, signed2[0]);