yaml-crypt
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -111,9 +111,10 @@ #!/usr/bin/env node | ||
}); | ||
parser.addArgument(["-G", "--generate-key"], { | ||
action: "append", | ||
parser.addArgument(["--generate-key"], { | ||
action: "storeTrue", | ||
help: "Generate a new random key. Use -a to specify the algorithm" | ||
}); | ||
parser.addArgument(["--write-key"], { | ||
metavar: "<name>", | ||
nargs: "?", | ||
help: | ||
"Generate a new random key. Use -a to specify the algorithm. " + | ||
"When a name is given, the key will be written to the configuration file, otherwise it will be printed to stdout" | ||
"Read a key from stdin and write it to the configuration file under the given name" | ||
}); | ||
@@ -253,3 +254,8 @@ parser.addArgument(["-k"], { | ||
} | ||
if (!args.generate_key && !args.k && (!config.keys || !config.keys.length)) { | ||
if ( | ||
!args.generate_key && | ||
!args.write_key && | ||
!args.k && | ||
(!config.keys || !config.keys.length) | ||
) { | ||
throw new UsageError("no keys given and no default keys configured!"); | ||
@@ -260,2 +266,5 @@ } | ||
} | ||
if (args.generate_key && args.write_key) { | ||
throw new UsageError("cannot combine --generate-key and --write-key!"); | ||
} | ||
if (args.generate_key && args.encrypt) { | ||
@@ -270,2 +279,11 @@ throw new UsageError("cannot combine --generate-key and --encrypt!"); | ||
} | ||
if (args.write_key && args.encrypt) { | ||
throw new UsageError("cannot combine --write-key and --encrypt!"); | ||
} | ||
if (args.write_key && args.decrypt) { | ||
throw new UsageError("cannot combine --write-key and --decrypt!"); | ||
} | ||
if (args.write_key && args.file && args.file.length) { | ||
throw new UsageError("option --write-key used, but files given!"); | ||
} | ||
try { | ||
@@ -325,16 +343,22 @@ _run(args, config, options); | ||
if (args.generate_key) { | ||
if (args.generate_key[0] != null) { | ||
const name = args.generate_key[0]; | ||
for (const key of configKeys) { | ||
if (key.name === name) { | ||
throw new UsageError(`key already exists: ${name}`); | ||
} | ||
const key = generateKey(algorithm); | ||
output.write(key); | ||
output.write("\n"); | ||
} else if (args.write_key) { | ||
const name = args.write_key; | ||
for (const key of configKeys) { | ||
if (key.name === name) { | ||
throw new UsageError(`key already exists: ${name}`); | ||
} | ||
const key = generateKey(algorithm); | ||
writeNewKey(key, name); | ||
} else { | ||
const key = generateKey(algorithm); | ||
output.write(key); | ||
output.write("\n"); | ||
} | ||
readInput(input, buf => { | ||
const key = buf.toString("utf8").trim(); | ||
if (key.length === 32) { | ||
writeNewKey(key, name); | ||
} else if (key.length > 0) { | ||
throw new UsageError(`key should be 32 bytes, but got ${key.length}`); | ||
} else { | ||
throw new UsageError("empty key given!"); | ||
} | ||
}); | ||
} else if (args.edit) { | ||
@@ -561,15 +585,14 @@ for (const file of args.file) { | ||
const lf = content.includes("\r\n") ? "\r\n" : "\n"; | ||
// no YAML parsing, to keep file comments! | ||
if (content.length > 0 && !content.endsWith("\n")) { | ||
content += "\n"; | ||
if (content.length > 0 && !content.endsWith(lf)) { | ||
content += lf; | ||
} | ||
if (!content.split("\n").includes("keys:")) { | ||
content += "keys:\n"; | ||
if (!content.split(lf).includes("keys:")) { | ||
content += `keys:${lf}`; | ||
} | ||
content += ` - name: '${name}'\n key: '${key}'\n`; | ||
content += ` - name: '${name}'${lf} key: '${key}'${lf}`; | ||
fs.writeFileSync(file, content, { encoding: "utf8", mode: 0o600 }); | ||
console.log(key); | ||
console.error(`key has been written to ${file}`); | ||
} | ||
@@ -576,0 +599,0 @@ |
{ | ||
"name": "yaml-crypt", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Encrypt and decrypt YAML documents", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77935
2189