cli: signed-integrity error checking in action handlers (ref. #66)

merge-requests/23/head
Michał 'rysiek' Woźniak 2022-12-11 15:00:14 +00:00
rodzic b226bf3012
commit 10b42c5273
1 zmienionych plików z 36 dodań i 3 usunięć

Wyświetl plik

@ -56,8 +56,20 @@ let getPubkey = async (keyfile) => {
if (Array.isArray(keyfile)) {
keyfile = keyfile[0]
}
// get the key data from the key file
var keydata = JSON.parse(Deno.readTextFileSync(keyfile));
// we need non-empty arguments
if ((typeof keyfile !== "string") || (keyfile == "")) {
throw new Error("No keyfile provided.")
}
// load the key
try {
var keydata = JSON.parse(Deno.readTextFileSync(keyfile));
} catch(e) {
throw new Error(`Failed to load private key from '${keyfile}': ${e.message}`, {cause: e})
}
// the key can be either in a CryptoKeyPair structure, or directly in CryptoKey structure
// standardize!
if ("privateKey" in keydata) {
@ -177,8 +189,29 @@ let genSignedIntegrity = async (
output='json',
extension='.integrity') => {
// we need non-empty arguments
if (!Array.isArray(paths) || (paths.length == 0)) {
throw new Error("Expected non-empty list of paths to process.")
}
if ((typeof keyfile !== "string") || (keyfile == "")) {
throw new Error("No keyfile provided.")
}
if (!Array.isArray(algos) || (algos.length == 0)) {
throw new Error("Expected non-empty list of algorithms to use.")
}
if (!['json', 'text', 'files'].includes(output)) {
throw new Error("Expected 'json', 'text', or 'files' as output type.")
}
if ( (output == 'files') && ( (typeof extension !== "string") || (extension == "") ) ) {
throw new Error("No extension provided.")
}
// load the key
var keydata = JSON.parse(Deno.readTextFileSync(keyfile));
try {
var keydata = JSON.parse(Deno.readTextFileSync(keyfile));
} catch(e) {
throw new Error(`Failed to load private key from '${keyfile}': ${e.message}`, {cause: e})
}
// the key can be either in a CryptoKeyPair structure, or directly in CryptoKey structure
// standardize!