Add support to write V3 signatures

This commit is contained in:
Thomas Oberndörfer 2014-04-03 21:21:56 +02:00
parent c107ef8d2f
commit 86537fb48c
2 changed files with 32 additions and 6 deletions

View File

@ -175,7 +175,7 @@ Signature.prototype.read = function (bytes) {
break; break;
default: default:
throw new Error('Version ' + version + ' of the signature is unsupported.'); throw new Error('Version ' + this.version + ' of the signature is unsupported.');
} }
// Two-octet field holding left 16 bits of signed hash value. // Two-octet field holding left 16 bits of signed hash value.
@ -186,11 +186,23 @@ Signature.prototype.read = function (bytes) {
}; };
Signature.prototype.write = function () { Signature.prototype.write = function () {
return this.signatureData + var result = '';
// unhashed subpackets or two octets for zero switch (this.version) {
(this.unhashedSubpackets ? this.unhashedSubpackets : util.writeNumber(0, 2)) + case 3:
this.signedHashValue + result += String.fromCharCode(3); // version
this.signature; result += String.fromCharCode(5); // One-octet length of following hashed material. MUST be 5
result += this.signatureData;
result += this.issuerKeyId.write();
result += String.fromCharCode(this.publicKeyAlgorithm);
result += String.fromCharCode(this.hashAlgorithm);
break;
case 4:
result += this.signatureData;
result += this.unhashedSubpackets ? this.unhashedSubpackets : util.writeNumber(0, 2);
break;
}
result += this.signedHashValue + this.signature;
return result;
}; };
/** /**

View File

@ -576,4 +576,18 @@ describe("Signature", function() {
expect(pubKey.users[0].selfCertifications).to.exist; expect(pubKey.users[0].selfCertifications).to.exist;
}); });
it('Write V3 signatures', function() {
var pubKey = openpgp.key.readArmored(pub_v3).keys[0];
var pubKey2 = openpgp.key.readArmored(pubKey.armor()).keys[0];
expect(pubKey2).to.exist;
expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications);
});
it('Write V4 signatures', function() {
var pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
var pubKey2 = openpgp.key.readArmored(pubKey.armor()).keys[0];
expect(pubKey2).to.exist;
expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications);
});
}); });