Skip to content

Commit

Permalink
Add function to check run-time version of the library
Browse files Browse the repository at this point in the history
This adds p11_kit_check_version function, which can be used to check
the run-time version of p11-kit.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed May 7, 2024
1 parent 652927d commit 45c60f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 14 additions & 2 deletions p11-kit/test-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "test.h"

static void
test_check (void)
test_check_compile_time (void)
{
#if !P11_KIT_CHECK_VERSION (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO)
assert_not_reached ();
Expand All @@ -66,13 +66,25 @@ test_check (void)
#endif
}

static void
test_check_run_time (void)
{
assert_num_eq (CKR_OK, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO));
assert_num_eq (CKR_OK, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, 0));
assert_num_eq (CKR_OK, p11_kit_check_version (P11_KIT_VERSION_MAJOR, 0, 0));
assert_num_eq (CKR_ARGUMENTS_BAD, p11_kit_check_version (P11_KIT_VERSION_MAJOR + 1, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO));
assert_num_eq (CKR_ARGUMENTS_BAD, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR + 1, P11_KIT_VERSION_MICRO));
assert_num_eq (CKR_ARGUMENTS_BAD, p11_kit_check_version (P11_KIT_VERSION_MAJOR, P11_KIT_VERSION_MINOR, P11_KIT_VERSION_MICRO + 1));
}

int
main (int argc,
char *argv[])
{
p11_library_init ();

p11_test (test_check, "/version/test_check");
p11_test (test_check_compile_time, "/version/test_check_compile_time");
p11_test (test_check_run_time, "/version/test_check_run_time");

return p11_test_run (argc, argv);
}
19 changes: 19 additions & 0 deletions p11-kit/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,22 @@ _p11_get_progname_unlocked (void)
return NULL;
return p11_my_progname;
}

/**
* p11_kit_check_version:
* @major: major version
* @minor: minor version
* @micro: micro version
*
* Check if the run-time version of p11-kit meets the requirement
* given by a triple: @major, @minor, and @micro.
*
* Returns: %CKR_OK if the version requirement meets; %CKR_ARGUMENTS_BAD otherwise.
* Since: 0.25.4
*/
CK_RV
p11_kit_check_version (int major, int minor, int micro)
{
return P11_KIT_CHECK_VERSION (major, minor, micro) ?
CKR_OK : CKR_ARGUMENTS_BAD;
}

0 comments on commit 45c60f7

Please sign in to comment.