Skip to content

Conversation

@lukin-oleksiy
Copy link
Contributor

The "kmipclient" C++ library implementation is added, that wraps low-level "kmip.h" calls and bypasses mid-level "kmip_bio" level. The kmip.h file was splitted in 3 to export enums, structures and functions separately.
Comparing to the 1st version (POC), The interface was simplified and uses exceptions now.
There are plans to replace C implementation of the protocol serialization/deserialization (kmip.c and others) with C++ code, so the current version of "kmipclient" library contains a lot of TODO and skeletons for future work. Ath this stage of development, the middle-level C implementation (kmip_bio.c) is removed and the library works directly with kmip.c.
Previous PR of POC is closed.

The "kmipclient" C++ library implementation is added, that wraps low-level
"kmip.h" calls and bypasses mid-level "kmip_bio" level.
https://perconadev.atlassian.net/browse/PS-10068

Addressing PR comments and other fixes, finallizing the interface of the library,
adding test suite
@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch from f5f8fbc to 6da142e Compare January 8, 2026 10:37
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -g")

include_directories(${PROJECT_SOURCE_DIR}/include)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to target_include_directories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 4 to 6
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Optional, but recommended for standard compliance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use target-specific options

target_compile_features(target INTERFACE cxx_std_20)
set_target_properties(my_target PROPERTIES
  CXX_STANDARD_REQUIRED YES
  CXX_EXTENSIONS NO
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Kid of. I still need 2 statements at the top of CMakeLists.txt to compile

Comment on lines 8 to 9
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -g")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionaly always enabled Address Sanitazer looks weird to me. I would declare an option

option(WITH_ASAN "Enable Address Sanitizer" OFF)
if(WITH_ASAN)
  target_compile_options(mytarget INTERFACE "-fsanitize=address")
  target_link_options(mytarget INTERFACE "-fsanitize=address")
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

)

target_link_libraries(kmipclient kmip)
set_property(TARGET kmipclient PROPERTY POSITION_INDEPENDENT_CODE ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_target_property()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed, there's no such funtion


macro(add_example name)
add_executable(example_${name} examples/example_${name}.cpp)
target_link_libraries(example_${name} kmipclient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_link_libraries(example_${name} kmipclient)
target_link_libraries(example_${name} PRIVATE kmipclient)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 35 to 39
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client)
{
io = std::make_unique<IOUtils> (net_client);
logger = log;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client)
{
io = std::make_unique<IOUtils> (net_client);
logger = log;
}
KmipClient::KmipClient (NetClient &net_client, const std::shared_ptr<Logger> &log) : net_client (net_client),
io(std::make_unique<IOUtils> (net_client)),
logger(log)
{}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in all constructors

Comment on lines +84 to +85
int buffer_blocks = 1;
const int buffer_block_size = 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, signed types for sizes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the reason is signed types in the lower level functions (kmip.h).

inline void
KmipRequest::add_batch_item (RequestBatchItem *rbi)
{
// Sorry, C++ guys, we have to use address arithmetic here because of the lower level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, I know... The goal of the next development iteration is to replace kmip.c with KmipSerializer and KmipDeserializer classes and get rid of all malloc's and address arithmetic. So, ... let's keep it for a while this way. You can't imageine what a mess we have in a "heritage" code.

return BIO_read (bio_, data, dlen);
}

} // namespace No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No EOL at the end of file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 35 to 54
static void create_get_rq (KmipCtx &ctx, const id_t &id);
static void create_activate_rq (KmipCtx &ctx, const id_t &id);
static void create_create_aes_rq (KmipCtx &ctx, const name_t &name, const name_t &group);
static void create_register_key_rq (KmipCtx &ctx, const name_t &name, const name_t &group, const Key &k);
static void create_register_secret_rq (KmipCtx &ctx, const name_t &name, const name_t &group, std::string &secret,
int secret_data_type);
static void create_revoke_rq (KmipCtx &ctx, const id_t &id, int reason, const name_t &message,
time_t occurrence_time);
static void create_destroy_rq (KmipCtx &ctx, const id_t &id);
static void create_get_attributes_rq (KmipCtx &ctx, const id_t &id, const std::vector<std::string> &attr_names);
static void create_get_attribute_list_rq (KmipCtx &ctx, const id_t &id);
static void create_locate_by_name_rq (KmipCtx &ctx, const name_t &name, enum object_type o_type, int max_items,
int offset);
static void create_locate_by_group_rq (KmipCtx &ctx, const name_t &group_name, enum object_type o_type, int max_items,
size_t offset);
static void create_locate_all_rq (KmipCtx &ctxm, enum object_type o_type, int max_items, int offset);

private:
static void create_locate_rq (KmipCtx &ctx, bool is_group, const name_t &name, enum object_type o_type, int max_items,
size_t offset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove enum for types, use std::size_t for sizes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch from c407d1d to 95a4c5f Compare January 21, 2026 11:09
@lukin-oleksiy lukin-oleksiy force-pushed the PS-9697-POC-of-kmip-cpp branch from 95a4c5f to 8e534f5 Compare January 21, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants