Write unhashed subpackets. Fix #178.

This commit is contained in:
Thomas Oberndörfer 2014-02-23 20:51:02 +01:00
parent 5d4d3f5ba1
commit 151694ff07
2 changed files with 14 additions and 2 deletions

View File

@ -51,6 +51,7 @@ function Signature() {
this.publicKeyAlgorithm = null;
this.signatureData = null;
this.unhashedSubpackets = null;
this.signedHashValue = null;
this.created = new Date();
@ -166,9 +167,11 @@ Signature.prototype.read = function (bytes) {
// hash algorithm, the hashed subpacket length, and the hashed
// subpacket body.
this.signatureData = bytes.substr(0, i);
var sigDataLength = i;
// unhashed subpackets
i += subpackets.call(this, bytes.substr(i), false);
this.unhashedSubpackets = bytes.substr(sigDataLength, i - sigDataLength);
break;
default:
@ -184,7 +187,8 @@ Signature.prototype.read = function (bytes) {
Signature.prototype.write = function () {
return this.signatureData +
util.writeNumber(0, 2) + // Number of unsigned subpackets.
// unhashed subpackets or two octets for zero
(this.unhashedSubpackets ? this.unhashedSubpackets : util.writeNumber(0, 2)) +
this.signedHashValue +
this.signature;
};
@ -559,7 +563,7 @@ Signature.prototype.toSign = function (type, data) {
case t.key:
if (data.key === undefined)
throw new Error('Key packet is required for this sigtature.');
throw new Error('Key packet is required for this signature.');
return data.key.writeOld();

View File

@ -571,4 +571,12 @@ describe("Signature", function() {
expect(verified).to.be.true;
done();
});
it('Write unhashed subpackets', function() {
var pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
expect(pubKey.users[0].selfCertifications).to.exist;
pubKey = openpgp.key.readArmored(pubKey.armor()).keys[0]
expect(pubKey.users[0].selfCertifications).to.exist;
});
});