From 0af094770c4ebabc56ff761a8bd215bc397c0f7e Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Tue, 5 Aug 2025 18:50:37 +0100 Subject: refactor: reading page review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/lib/pgp/verify.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/lib/pgp/verify.ts') diff --git a/src/lib/pgp/verify.ts b/src/lib/pgp/verify.ts index 026b6df..1003147 100644 --- a/src/lib/pgp/verify.ts +++ b/src/lib/pgp/verify.ts @@ -24,6 +24,7 @@ import type { Commit } from "../git/types.ts"; import { findMapAsync, type MaybeIterable } from "../../utils/iterator.ts"; import { getUserIDsFromKey } from "./user.ts"; import { env } from "../environment.ts"; +import { toPK } from "./index.ts"; type DataURL = [URL, URL?]; type Corrupted = [false] | [true, Error]; @@ -195,18 +196,21 @@ export class SignatureVerifier { } } - addKey(key: MaybeIterable): void { + addKey(key: MaybeIterable): Iterable { if (key instanceof PublicKey) { this.keys.push(key); + return [key]; } else { this.keys.push(...key); + return key; } } async addKeysFromDir( key: string | URL, rules: KeyDiscoveryRules = DEFAULT_KEY_DISCOVERY_RULES, - ): Promise { + ): Promise> { + const keys: PublicKey[] = []; for await ( const i of createKeysFromDir(key, rules, { encoder: this.#encoder, @@ -214,39 +218,43 @@ export class SignatureVerifier { }) ) { this.keys.push(i); + keys.push(i); } + return keys; } async addKeyFromFile( key: string | URL, type: KeyFileFormat, - ): Promise { + ): Promise { switch (type) { case armored: { - this.keys.push(await createKeyFromFile(key, type, this.#decoder)); - break; + const k = await createKeyFromFile(key, type, this.#decoder); + this.keys.push(k); + return k; } case binary: { - this.keys.push(await createKeyFromFile(key, type, this.#encoder)); - break; + const k = await createKeyFromFile(key, type, this.#encoder); + this.keys.push(k); + return k; } } } async addKeyFromArmor( key: string | Uint8Array, - ): Promise { - this.keys.push( - await createKeyFromArmor(key, this.#decoder).then((x) => x.toPublic()), - ); + ): Promise { + const k = await createKeyFromArmor(key, this.#decoder).then(toPK); + this.keys.push(k); + return k; } async addKeyFromBinary( key: string | Uint8Array, - ): Promise { - this.keys.push( - await createKeyFromBinary(key, this.#encoder).then((x) => x.toPublic()), - ); + ): Promise { + const k = await createKeyFromBinary(key, this.#encoder).then(toPK); + this.keys.push(k); + return k; } public static async instance(): Promise { -- cgit v1.2.3