diff options
Diffstat (limited to 'deps/npm/node_modules/sigstore/dist/tuf/target.js')
-rw-r--r-- | deps/npm/node_modules/sigstore/dist/tuf/target.js | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/deps/npm/node_modules/sigstore/dist/tuf/target.js b/deps/npm/node_modules/sigstore/dist/tuf/target.js index ac708cdbcf..b79411c3dd 100644 --- a/deps/npm/node_modules/sigstore/dist/tuf/target.js +++ b/deps/npm/node_modules/sigstore/dist/tuf/target.js @@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getTarget = void 0; +exports.readTarget = void 0; /* Copyright 2023 The Sigstore Authors. @@ -21,29 +21,45 @@ limitations under the License. */ const fs_1 = __importDefault(require("fs")); const error_1 = require("../error"); +// Downloads and returns the specified target from the provided TUF Updater. +async function readTarget(tuf, targetPath) { + const path = await getTargetPath(tuf, targetPath); + return new Promise((resolve, reject) => { + fs_1.default.readFile(path, 'utf-8', (err, data) => { + if (err) { + reject(new error_1.InternalError({ + code: 'TUF_READ_TARGET_ERROR', + message: `error reading target ${path}`, + cause: err, + })); + } + else { + resolve(data); + } + }); + }); +} +exports.readTarget = readTarget; // Returns the local path to the specified target. If the target is not yet // cached locally, the provided TUF Updater will be used to download and // cache the target. -async function getTarget(tuf, targetPath) { - const path = await getTargetPath(tuf, targetPath); - try { - return fs_1.default.readFileSync(path, 'utf-8'); - } - catch (err) { - throw new error_1.InternalError(`error reading trusted root: ${err}`); - } -} -exports.getTarget = getTarget; async function getTargetPath(tuf, target) { let targetInfo; try { targetInfo = await tuf.refresh().then(() => tuf.getTargetInfo(target)); } catch (err) { - throw new error_1.InternalError(`error refreshing TUF metadata: ${err}`); + throw new error_1.InternalError({ + code: 'TUF_REFRESH_METADATA_ERROR', + message: 'error refreshing TUF metadata', + cause: err, + }); } if (!targetInfo) { - throw new error_1.InternalError(`target ${target} not found`); + throw new error_1.InternalError({ + code: 'TUF_FIND_TARGET_ERROR', + message: `target ${target} not found`, + }); } let path = await tuf.findCachedTarget(targetInfo); // An empty path here means the target has not been cached locally, or is @@ -53,7 +69,11 @@ async function getTargetPath(tuf, target) { path = await tuf.downloadTarget(targetInfo); } catch (err) { - throw new error_1.InternalError(`error downloading target: ${err}`); + throw new error_1.InternalError({ + code: 'TUF_DOWNLOAD_TARGET_ERROR', + message: `error downloading target ${path}`, + cause: err, + }); } } return path; |