Store unhashed subpackets in a more structured format (#1767)

To match the new `unknownSubpackets` property.
This commit is contained in:
Daniel Huigens 2024-06-17 16:52:28 +02:00 committed by GitHub
parent b1e27a1430
commit 9f5ff66c3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 9 deletions

9
openpgp.d.ts vendored
View File

@ -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;

View File

@ -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: