Skip to content

Commit

Permalink
CLI: export all keys when no filter is specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
antonsviridenko authored and ronaldtse committed Aug 21, 2023
1 parent 0938233 commit b4ae749
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/rnp/fficli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ cli_rnp_keys_matching_string(cli_rnp_t * rnp,
if (rnp_locate_key(rnp->ffi, "fingerprint", fp, &handle) || !handle) {
goto done;
}
if (!key_matches_flags(handle, flags) || !key_matches_string(handle, str.c_str())) {
if (!key_matches_flags(handle, flags) || !key_matches_string(handle, str)) {
rnp_key_handle_destroy(handle);
continue;
}
Expand Down Expand Up @@ -2206,7 +2206,7 @@ cli_rnp_export_keys(cli_rnp_t *rnp, const char *filter)
int flags = secret ? CLI_SEARCH_SECRET : 0;
std::vector<rnp_key_handle_t> keys;

if (!cli_rnp_keys_matching_string(rnp, keys, filter, flags)) {
if (!cli_rnp_keys_matching_string(rnp, keys, filter ? filter : std::string(), flags)) {
ERR_MSG("Key(s) matching '%s' not found.", filter);
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions src/rnpkeys/rnpkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@ rnp_cmd(cli_rnp_t *rnp, optdefs_t cmd, const char *f)
fs = rnp->cfg().get_str(CFG_USERID, 0);
f = fs.c_str();
}
if (!f) {
ERR_MSG("No key specified.");
return 0;
}
return cli_rnp_export_keys(rnp, f);
}
case CMD_IMPORT:
Expand Down
8 changes: 4 additions & 4 deletions src/tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,10 @@ def test_export_keys(self):
# Import Alice's public key
ret, _, _ = run_proc(RNPK, ['--homedir', RNPDIR, '--import', data_path(KEY_ALICE_SUB_PUB)])
self.assertEqual(ret, 0)
# Attempt to export no key
ret, _, err = run_proc(RNPK, ['--homedir', RNPDIR, '--export-key'])
self.assertNotEqual(ret, 0)
self.assertRegex(err, r'(?s)^.*No key specified\.$')
# Export all keys (no search pattern)
ret, out, err = run_proc(RNPK, ['--homedir', RNPDIR, '--export-key'])
self.assertEqual(ret, 0)
self.assertRegex(out, PUB_KEY)
# Attempt to export wrong key
ret, _, err = run_proc(RNPK, ['--homedir', RNPDIR, '--export-key', 'boris'])
self.assertNotEqual(ret, 0)
Expand Down

0 comments on commit b4ae749

Please sign in to comment.