Skip to content

Commit

Permalink
Add more KBX and G10 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
antonsviridenko authored and ronaldtse committed Jun 4, 2023
1 parent feed13c commit 12133aa
Show file tree
Hide file tree
Showing 6 changed files with 574 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librekey/key_store_kbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ rnp_key_store_kbx_from_src(rnp_key_store_t * key_store,
uint8_t * buf = (uint8_t *) mem.memory();

if (has_bytes < BLOB_FIRST_SIZE) {
RNP_LOG("Too few bytes for valid KBX");
return false;
RNP_LOG("Too few bytes for valid KBX");
return false;
}
while (has_bytes > 4) {
size_t blob_length = read_uint32(buf);
Expand Down
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ add_executable(rnp_tests
large-mpi.cpp
load-g10.cpp
load-g23.cpp
load-kbx.cpp
load-pgp.cpp
log-switch.cpp
partial-length.cpp
Expand Down
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions src/tests/load-g10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@
#include "rnp_tests.h"
#include "support.h"

TEST_F(rnp_tests, test_invalid_g10)
{
rnp_key_store_t * pub_store = NULL;
rnp_key_store_t * sec_store = NULL;
pgp_key_provider_t key_provider(rnp_key_provider_store);
// load pubring
pub_store =
new rnp_key_store_t(PGP_KEY_STORE_KBX, "data/keyrings/3/pubring.kbx", global_ctx);
assert_true(rnp_key_store_load_from_path(pub_store, NULL));
// trigger "Unsupported public key algorithm:" error message
sec_store = new rnp_key_store_t(
PGP_KEY_STORE_G10, "data/test_invalid_g10/private-keys-v1.d", global_ctx);
key_provider.userdata = pub_store;
assert_true(rnp_key_store_load_from_path(sec_store, &key_provider));
// NULL key_provider
assert_true(rnp_key_store_load_from_path(sec_store, NULL));

delete pub_store;
delete sec_store;
}

/* This test loads G10 keyrings and verifies certain properties
* of the keys are correct.
*/
Expand Down
Loading

0 comments on commit 12133aa

Please sign in to comment.