122 lines
10 KiB
JavaScript
122 lines
10 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;
|
|
this._authorized = optionsArg.authorized;
|
|
}
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "host", {
|
|
// this.host
|
|
get: function () {
|
|
return this._hostVar;
|
|
},
|
|
set: function (hostArg) {
|
|
this._hostVar = hostArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "privKey", {
|
|
// this.privKey
|
|
get: function () {
|
|
return this._privKey;
|
|
},
|
|
set: function (privateKeyArg) {
|
|
this._privKey = privateKeyArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "privKeyBase64", {
|
|
// this.privKeyBase64
|
|
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, "pubKey", {
|
|
// this.pubKey
|
|
get: function () {
|
|
return this._pubKey;
|
|
},
|
|
set: function (publicKeyArg) {
|
|
this._pubKey = publicKeyArg;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
Object.defineProperty(SshKey.prototype, "pubKeyBase64", {
|
|
// this.pubKeyBase64
|
|
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, "authorized", {
|
|
get: function () {
|
|
return this._authorized;
|
|
},
|
|
set: function (authorizedArg) {
|
|
this._authorized = authorizedArg;
|
|
},
|
|
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";
|
|
}
|
|
},
|
|
set: function (someVlueArg) {
|
|
console.log("the type of an SshKey connot be set. This value is autpcomputed.");
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
;
|
|
// methods
|
|
SshKey.prototype.read = function (filePathArg) {
|
|
};
|
|
SshKey.prototype.store = function (dirPathArg) {
|
|
plugins.fs.ensureDirSync(dirPathArg);
|
|
var fileNameBase = this.host;
|
|
if (this._privKey) {
|
|
plugins.smartfile.memory.toFsSync(this._privKey, plugins.path.join(dirPathArg, fileNameBase));
|
|
}
|
|
;
|
|
if (this._pubKey) {
|
|
plugins.smartfile.memory.toFsSync(this._pubKey, plugins.path.join(dirPathArg, fileNameBase + ".pub"));
|
|
}
|
|
};
|
|
return SshKey;
|
|
}());
|
|
exports.SshKey = SshKey;
|
|
var testKey = new SshKey();
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3Noa2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUc5QztJQUtJLGdCQUFZLFVBQStFO1FBQS9FLDBCQUErRSxHQUEvRSxlQUErRTtRQUN2RixJQUFJLENBQUMsUUFBUSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUM7UUFDbkMsSUFBSSxD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