~sircmpwn/himitsu-ssh

09b33fef81617fae200d8853cc18adb9ebc62119 — Armin Preiml 10 months ago 0cf03a1 0.3
hiss-import: add -c to overwrite/add key comments
1 files changed, 27 insertions(+), 0 deletions(-)

M cmd/hissh-import/main.ha
M cmd/hissh-import/main.ha => cmd/hissh-import/main.ha +27 -0
@@ 13,8 13,27 @@ use os;
use path;
use shlex;
use unix::tty;
use strings;

export fn main() void = {
	const cmd = getopt::parse(os::args,
		"hissh import",
		('c', "comment", "add or overwrite comment prior importing"),
	);
	defer getopt::finish(&cmd);

	let comment: (str | void) = void;
	for (let i = 0z; i < len(cmd.opts); i += 1) {
		const opt = cmd.opts[i];
		switch (opt.0) {
		case 'c' =>
			comment = strings::dup(opt.1);
		case =>
			fmt::fatalf("unknown option");
		};
	};


	const key = match (ssh::decodesshprivate(os::stdin)) {
	case let key: ssh::sshprivkey =>
		yield key;


@@ 34,6 53,14 @@ export fn main() void = {
	};
	defer ssh::key_free(privkey);

	match (comment) {
	case void =>
		yield;
	case let c: str =>
		free(privkey.comment);
		privkey.comment = c;
	};

	let buf = memio::dynamic();
	defer io::close(&buf)!;
	fmt::fprintf(&buf, "add proto=ssh type={} pkey='", ssh::keytype(privkey))!;