Skip to content

Commit 87c02af

Browse files
committed
feat: add ssh encryption command
1 parent 76ae897 commit 87c02af

15 files changed

Lines changed: 117 additions & 12 deletions

File tree

lib/commands/debian-repository.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

lib/commands/docker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

lib/commands/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

lib/commands/generate.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

@@ -26,6 +26,11 @@ export default class extends Command {
2626
"title": "Create Telegram session",
2727
"module": () => new URL( "generate/telegram-session.js", import.meta.url ),
2828
},
29+
"ssh": {
30+
"short": "S",
31+
"title": "Encrypt / decrypt data with SSH private key",
32+
"module": () => new URL( "generate/ssh.js", import.meta.url ),
33+
},
2934
},
3035
};
3136
}

lib/commands/generate/ssh.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Command from "#lib/command";
2+
3+
export default class extends Command {
4+
5+
// static
6+
static cli () {
7+
return {
8+
"commands": {
9+
"encrypt": {
10+
"short": "e",
11+
"title": "Encrypt data with SSH private key",
12+
"module": () => new URL( "ssh/encrypt.js", import.meta.url ),
13+
},
14+
"decrypt": {
15+
"short": "d",
16+
"title": "Decrypt data with SSH private key",
17+
"module": () => new URL( "ssh/decrypt.js", import.meta.url ),
18+
},
19+
},
20+
};
21+
}
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { pipeline } from "node:stream";
2+
import { decryptSsh } from "#core/crypto";
3+
import Command from "#lib/command";
4+
5+
export default class extends Command {
6+
7+
// static
8+
static cli () {
9+
return {
10+
"options": {
11+
"input-encoding": {
12+
"description": "Input encoding.",
13+
"schema": { "enum": [ "base", "base64url", "hex", "latin1", "utf8" ] },
14+
},
15+
"output-encoding": {
16+
"description": "Output encoding.",
17+
"schema": { "enum": [ "base", "base64url", "hex", "latin1", "utf8" ] },
18+
},
19+
},
20+
"arguments": {
21+
"github-username": {
22+
"description": "GitHub username",
23+
"required": true,
24+
"schema": { "type": "string" },
25+
},
26+
},
27+
};
28+
}
29+
30+
// public
31+
async run () {
32+
const stream = await decryptSsh( process.cli.arguments[ "github-username" ], process.stdin, {
33+
"inputEncoding": process.cli.options[ "input-encoding" ],
34+
"outputEncoding": process.cli.options[ "output-encoding" ],
35+
} );
36+
37+
return new Promise( resolve => pipeline( stream, process.stdout, resolve ) );
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { pipeline } from "node:stream";
2+
import { encryptSsh } from "#core/crypto";
3+
import Command from "#lib/command";
4+
5+
export default class extends Command {
6+
7+
// static
8+
static cli () {
9+
return {
10+
"options": {
11+
"input-encoding": {
12+
"description": "Input encoding.",
13+
"schema": { "enum": [ "base", "base64url", "hex", "latin1", "utf8" ] },
14+
},
15+
"output-encoding": {
16+
"description": "Output encoding.",
17+
"schema": { "enum": [ "base", "base64url", "hex", "latin1", "utf8" ] },
18+
},
19+
},
20+
"arguments": {
21+
"github-username": {
22+
"description": "GitHub username",
23+
"required": true,
24+
"schema": { "type": "string" },
25+
},
26+
},
27+
};
28+
}
29+
30+
// public
31+
async run () {
32+
const stream = await encryptSsh( process.cli.arguments[ "github-username" ], process.stdin, {
33+
"inputEncoding": process.cli.options[ "input-encoding" ],
34+
"outputEncoding": process.cli.options[ "output-encoding" ],
35+
} );
36+
37+
return new Promise( resolve => pipeline( stream, process.stdout, resolve ) );
38+
}
39+
}

lib/commands/git.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

lib/commands/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import Command from "#lib/command";
12
import { lintPatterns } from "#lib/lint";
2-
import Command from "../command.js";
33

44
export default class extends Command {
55

lib/commands/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Command from "../command.js";
1+
import Command from "#lib/command";
22

33
export default class extends Command {
44

0 commit comments

Comments
 (0)