Files
smartssh/ts/smartssh.classes.sshkey.ts

96 lines
2.6 KiB
TypeScript
Raw Normal View History

2016-05-31 19:00:52 +02:00
import "typings-global";
import * as plugins from "./smartssh.plugins";
import * as helpers from "./smartssh.classes.helpers";
2016-04-25 04:06:20 +02:00
export class SshKey {
2016-06-25 02:29:34 +02:00
private _privKey:string;
private _pubKey:string;
private _hostVar:string;
private _authorized:boolean;
2016-06-25 02:10:53 +02:00
constructor(optionsArg:{private?:string,public?:string,host?:string,authorized?:boolean}={}){
2016-06-25 02:29:34 +02:00
this._privKey = optionsArg.private;
this._pubKey = optionsArg.public;
this._hostVar = optionsArg.host;
this._authorized = optionsArg.authorized;
2016-04-25 04:06:20 +02:00
};
2016-06-25 02:29:34 +02:00
// this.host
2016-04-26 04:44:50 +02:00
get host(){
2016-06-25 02:29:34 +02:00
return this._hostVar;
2016-04-26 04:44:50 +02:00
};
2016-06-25 02:29:34 +02:00
set host(hostArg:string){
this._hostVar = hostArg;
};
// this.privKey
get privKey(){
return this._privKey;
2016-04-25 04:06:20 +02:00
};
2016-06-25 02:29:34 +02:00
set privKey(privateKeyArg:string){
this._privKey = privateKeyArg;
};
// this.privKeyBase64
get privKeyBase64(){
return plugins.base64.encode(this._privKey);
2016-04-25 04:06:20 +02:00
}
2016-06-25 02:29:34 +02:00
set privKeyBase64(privateKeyArg:string) {
this._privKey = plugins.base64.decode(privateKeyArg);
2016-04-25 04:06:20 +02:00
}
2016-06-25 02:29:34 +02:00
// this.pubKey
get pubKey(){
return this._pubKey;
2016-04-25 04:06:20 +02:00
}
2016-06-25 02:29:34 +02:00
set pubKey(publicKeyArg:string){
this._pubKey = publicKeyArg;
};
// this.pubKeyBase64
get pubKeyBase64(){
return plugins.base64.encode(this._pubKey);
}
set pubKeyBase64(publicKeyArg:string) {
this._pubKey = plugins.base64.decode(publicKeyArg);
}
2016-06-25 15:30:57 +02:00
get authorized(){
return this._authorized;
}
set authorized(authorizedArg:boolean){
this._authorized = authorizedArg;
}
2016-04-25 04:06:20 +02:00
get type(){
2016-06-25 02:29:34 +02:00
if(this._privKey && this._pubKey){
2016-04-25 04:06:20 +02:00
return "duplex";
2016-06-25 02:29:34 +02:00
} else if(this._privKey){
2016-04-25 04:06:20 +02:00
return "private";
2016-06-25 02:29:34 +02:00
} else if(this._pubKey){
2016-04-25 04:06:20 +02:00
return "public";
}
};
2016-06-25 02:29:34 +02:00
set type(someVlueArg:any){
console.log("the type of an SshKey connot be set. This value is autpcomputed.")
2016-06-14 00:11:20 +02:00
}
2016-06-25 02:29:34 +02:00
// methods
2016-06-24 20:58:55 +02:00
read(filePathArg){
}
2016-06-26 04:07:03 +02:00
store(dirPathArg:string){
2016-06-25 14:13:26 +02:00
plugins.fs.ensureDirSync(dirPathArg);
let fileNameBase = this.host;
if(this._privKey){
2016-06-26 04:23:45 +02:00
let filePath = plugins.path.join(dirPathArg,fileNameBase);
plugins.smartfile.memory.toFsSync(this._privKey,filePath);
plugins.shelljs.chmod(600,filePath);
2016-06-25 14:13:26 +02:00
};
if (this._pubKey){
2016-06-26 04:23:45 +02:00
let filePath = plugins.path.join(dirPathArg,fileNameBase + ".pub");
plugins.smartfile.memory.toFsSync(this._pubKey,filePath);
plugins.shelljs.chmod(600,filePath);
2016-04-25 04:06:20 +02:00
}
}
2016-06-25 02:29:34 +02:00
}
let testKey = new SshKey();