@microsoft/dev-tunnels-ssh-keys
Version:
SSH key import/export library for Dev Tunnels
46 lines • 1.77 kB
JavaScript
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultKeyFormatter = void 0;
const importExport_1 = require("./importExport");
/**
* Auto-detects the format of a key when importing, by trying all the available formatters.
*/
class DefaultKeyFormatter {
export(keyPair, includePrivate) {
throw new Error('DefaultKeyFormatter should not be used for exporting.');
}
encrypt(keyData, passphrase) {
throw new Error('DefaultKeyFormatter should not be used for encrypting.');
}
async import(keyData) {
for (const [keyFormat, keyFormatter] of importExport_1.keyFormatters) {
if (keyFormat !== 0 /* KeyFormat.Default */ &&
keyFormat !== 1 /* KeyFormat.Ssh */ &&
keyFormat !== 7 /* KeyFormat.Jwk */) {
const keyPair = await keyFormatter.import(keyData);
if (keyPair) {
return keyPair;
}
}
}
return null;
}
async decrypt(keyData, passphrase) {
for (const [keyFormat, keyFormatter] of importExport_1.keyFormatters) {
if (keyFormat !== 0 /* KeyFormat.Default */ &&
keyFormat !== 1 /* KeyFormat.Ssh */ &&
keyFormat !== 7 /* KeyFormat.Jwk */) {
const decryptedKeyData = await keyFormatter.decrypt(keyData, passphrase);
if (decryptedKeyData) {
return decryptedKeyData;
}
}
}
return null;
}
}
exports.DefaultKeyFormatter = DefaultKeyFormatter;
//# sourceMappingURL=defaultKeyFormatter.js.map
;