UNPKG

@microsoft/dev-tunnels-ssh-keys

Version:

SSH key import/export library for Dev Tunnels

38 lines 1.77 kB
"use strict"; // // Copyright (c) Microsoft Corporation. All rights reserved. // Object.defineProperty(exports, "__esModule", { value: true }); exports.useWebCrypto = exports.getKeyEncryptionAlgorithm = void 0; const dev_tunnels_ssh_1 = require("@microsoft/dev-tunnels-ssh"); function getKeyEncryptionAlgorithm(algorithm) { // Different formats may use different casing and hyphens. Normalize before comparing. algorithm = algorithm.toUpperCase().replace(/-/g, ''); // Note algorithms other than AES256 are used only for decrypting (importing) keys. switch (algorithm) { case 'AES128CBC': return new dev_tunnels_ssh_1.Encryption('aes128-cbc', 'AES', 'CBC', 128); case 'AES128CTR': return new dev_tunnels_ssh_1.Encryption('aes128-ctr', 'AES', 'CTR', 128); case 'AES192CBC': return new dev_tunnels_ssh_1.Encryption('aes192-cbc', 'AES', 'CBC', 192); case 'AES192CTR': return new dev_tunnels_ssh_1.Encryption('aes192-ctr', 'AES', 'CTR', 192); case 'AES256CBC': return new dev_tunnels_ssh_1.Encryption('aes256-cbc', 'AES', 'CBC', 256); case 'AES256CTR': return new dev_tunnels_ssh_1.Encryption('aes256-ctr', 'AES', 'CTR', 256); default: throw new Error(`Key cipher not supported: ${algorithm}`); } } exports.getKeyEncryptionAlgorithm = getKeyEncryptionAlgorithm; /** * Use web crypto when in a browser and the crypto.subtle API is available. * Otherwise use Node.js crypto. */ function useWebCrypto() { return typeof self === 'object' && !!(typeof crypto === 'object' && crypto.subtle); } exports.useWebCrypto = useWebCrypto; //# sourceMappingURL=keyFormatter.js.map