-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
33 lines (32 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Sig } from "./sig.ts";
import { verify as rawVerify } from "./verifier.ts";
import { parse } from "./sig_parser.ts";
/**
* Verifies SSH signature against provided data.
*
* Returns `true` if the `signature` is a valid signature over `signed_data`, `false` otherwise.
*
* @param {Sig | string} signature SSH signature.
* @param {Uint8Array | string} signed_data Data that has been signed.
* @param {object} options Pass-in subtle crypto if required.
* @returns {Promise<boolean>} Resolves to true if the signature is valid, to false otherwise.
*/
export async function verify(
signature: Sig | string,
signed_data: Uint8Array | string,
options?: {
subtle?: SubtleCrypto;
},
): Promise<boolean> {
if (typeof options === "undefined") {
options = {};
}
const subtle = options.subtle || crypto.subtle;
if (typeof signature === "string") {
signature = parse(signature);
}
if (typeof signed_data === "string") {
signed_data = new TextEncoder().encode(signed_data);
}
return await rawVerify(subtle, signature, signed_data);
}