smartssh/dist/smartssh.classes.sshkey.js
2016-06-01 04:18:31 +02:00

99 lines
9.1 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);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SshKey.prototype, "publicKey", {
get: function () {
return this.pubKey;
},
// setters
set: function (publicKeyArg) {
this.pubKey = publicKeyArg;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SshKey.prototype, "publicKeyBase64", {
get: function () {
return plugins.base64.encode(this.pubKey);
},
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3Noa2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUc5QztJQUlJLGdCQUFZLFVBQTJEO1FBQTNELDBCQUEyRCxHQUEzRCxlQUEyRDtRQUNuRSxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUM7UUFDbEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxVQUFVLENBQUMsTUFBTSxDQUFDO1FBQ2hDLElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztJQUNuQyxDQUFDOztJQUdELHNCQUFJLHdCQUFJO1FBRFIsVUFBVTthQUNWO1lBQ0ksTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7UUFDeEIsQ0FBQztRQXVCRCxVQUFVO2FBQ1YsVUFBUyxPQUFjO1lBQ25CLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO1FBQzNCLENBQUM7OztPQTFCQTs7SUFDRCxzQkFBSSw4QkFBVTthQUFkO1lBQ0ksTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7UUFDeEIsQ0FBQzthQXdCRCxVQUFlLGFBQW9CO1lBQy9CLElBQUksQ0FBQyxPQUFPLEdBQUcsYUFBYSxDQUFDO1FBQ2pDLENBQUM7OztPQTFCQTs7SUFDRCxzQkFBSSxvQ0FBZ0I7YUFBcEI7WUFDSSxNQUFNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ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