diff --git a/openpgp.d.ts b/openpgp.d.ts index 795f3869..405a99b3 100644 --- a/openpgp.d.ts +++ b/openpgp.d.ts @@ -497,7 +497,8 @@ export class SignaturePacket extends BasePacket { public hashAlgorithm: enums.hash | null; public publicKeyAlgorithm: enums.publicKey | null; public signatureData: null | Uint8Array; - public unhashedSubpackets: null | Uint8Array; + public unhashedSubpackets: RawSubpacket[]; + public unknownSubpackets: RawSubpacket[]; public signedHashValue: null | Uint8Array; public created: Date | null; public signatureExpirationTime: null | number; @@ -541,6 +542,12 @@ export class SignaturePacket extends BasePacket { public getExpirationTime(): Date | typeof Infinity; } +export interface RawSubpacket { + type: number; + critical: boolean; + body: Uint8Array; +} + export interface RawNotation { name: string; value: Uint8Array; diff --git a/src/packet/signature.js b/src/packet/signature.js index 78a7963b..a6bbc8d5 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -396,10 +396,8 @@ class SignaturePacket { * @returns {Uint8Array} Subpacket data. */ writeUnhashedSubPackets() { - const arr = []; - this.unhashedSubpackets.forEach(data => { - arr.push(writeSimpleLength(data.length)); - arr.push(data); + const arr = this.unhashedSubpackets.map(({ type, critical, body }) => { + return writeSubPacket(type, critical, body); }); const result = util.concat(arr); @@ -408,7 +406,7 @@ class SignaturePacket { return util.concat([length, result]); } - // V4 signature sub packets + // Signature subpackets readSubPacket(bytes, hashed = true) { let mypos = 0; @@ -416,15 +414,19 @@ class SignaturePacket { const critical = !!(bytes[mypos] & 0x80); const type = bytes[mypos] & 0x7F; + mypos++; + if (!hashed) { - this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length)); + this.unhashedSubpackets.push({ + type, + critical, + body: bytes.subarray(mypos, bytes.length) + }); if (!allowedUnhashedSubpackets.has(type)) { return; } } - mypos++; - // subpacket type switch (type) { case enums.signatureSubpacket.signatureCreationTime: