104 lines
9.7 KiB
JavaScript
104 lines
9.7 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./smartssh.plugins");
|
|
var SshKey = (function () {
|
|
function SshKey(optionsArg) {
|
|
if (optionsArg === void 0) { optionsArg = {}; }
|
|
this.privKey = optionsArg.private;
|
|
this.pubKey = optionsArg.public;
|
|
this.hostVar = optionsArg.host;
|
|
}
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "host", {
|
|
// getters
|
|
get: function () {
|
|
return this.hostVar;
|
|
},
|
|
// setters
|
|
set: function (hostArg) {
|
|
this.hostVar = hostArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "privateKey", {
|
|
get: function () {
|
|
return this.privKey;
|
|
},
|
|
set: function (privateKeyArg) {
|
|
this.privKey = privateKeyArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "privateKeyBase64", {
|
|
get: function () {
|
|
return plugins.base64.encode(this.privKey);
|
|
},
|
|
set: function (privateKeyArg) {
|
|
this.privKey = plugins.base64.decode(privateKeyArg);
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(SshKey.prototype, "publicKey", {
|
|
get: function () {
|
|
return this.pubKey;
|
|
},
|
|
set: function (publicKeyArg) {
|
|
this.pubKey = publicKeyArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(SshKey.prototype, "publicKeyBase64", {
|
|
get: function () {
|
|
return plugins.base64.encode(this.pubKey);
|
|
},
|
|
set: function (publicKeyArg) {
|
|
this.pubKey = plugins.base64.decode(publicKeyArg);
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(SshKey.prototype, "type", {
|
|
get: function () {
|
|
if (this.privKey && this.pubKey) {
|
|
return "duplex";
|
|
}
|
|
else if (this.privKey) {
|
|
return "private";
|
|
}
|
|
else if (this.pubKey) {
|
|
return "public";
|
|
}
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
;
|
|
;
|
|
;
|
|
SshKey.prototype.store = function (filePathArg) {
|
|
var filePathObj = plugins.path.parse(filePathArg);
|
|
if (filePathObj.ext = ".priv") {
|
|
plugins.smartfile.memory.toFsSync(this.privKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
|
|
}
|
|
else if (filePathObj.ext = ".pub") {
|
|
plugins.smartfile.memory.toFsSync(this.pubKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
|
|
}
|
|
else {
|
|
plugins.fs.ensureDirSync(filePathObj.dir);
|
|
this.store(plugins.path.join(filePathObj.dir, "key.priv")); // call this function recursivly
|
|
this.store(plugins.path.join(filePathObj.dir, "key.priv")); // call this function recursivly
|
|
}
|
|
};
|
|
return SshKey;
|
|
}());
|
|
exports.SshKey = SshKey;
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3Noa2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUc5QztJQUlJLGdCQUFZLFVBQTJEO1FBQTNELDBCQUEyRCxHQUEzRCxlQUEyRDtRQUNuRSxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUM7UUFDbEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUMsTUFBTSxDQUFDO1FBQ2hDLElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztJQUNuQyxDQUFDOztJQUdELHNCQUFJLHdCQUFJO1FBRFIsVUFBVTthQUNWO1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