-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmor.ts
More file actions
24 lines (24 loc) · 751 Bytes
/
armor.ts
File metadata and controls
24 lines (24 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Removes armoring from text SSH signatures and decodes it to raw bytes.
*
* @param {string} text SSH signature in armored format.
* @returns {Uint8Array} Raw bytes of the signature.
*/
export function dearmor(text: string) {
const lines = text.trim().split("\n");
const first = lines.shift();
if (first !== "-----BEGIN SSH SIGNATURE-----") {
throw new Error(
"Bad header line, expected -----BEGIN SSH SIGNATURE----- got: " + first,
);
}
const last = lines.pop();
if (last !== "-----END SSH SIGNATURE-----") {
throw new Error(
"Bad trailer line, expected -----END SSH SIGNATURE----- got: " + last,
);
}
return Uint8Array.from(
atob(lines.join("")).split("").map((x) => x.charCodeAt(0)),
);
}