Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kmipclient/examples/example_create_aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

#include <iomanip>
#include <iostream>
#include <span>

using namespace kmipclient;

namespace {

void print_hex(const std::vector<unsigned char> &bytes) {
void print_hex(std::span<const unsigned char> bytes) {
for (const auto b : bytes) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(b);
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include "kmipclient/kmipclient_version.hpp"

#include <iostream>
#include <span>

using namespace kmipclient;

void print_hex(const std::vector<unsigned char> &key) {
void print_hex(std::span<const unsigned char> key) {
for (auto const &c : key) {
std::cout << std::hex << static_cast<int>(c);
}
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_get_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include "kmipcore/kmip_basics.hpp"

#include <iostream>
#include <span>

using namespace kmipclient;

void print_hex(const std::vector<unsigned char> &key) {
void print_hex(std::span<const unsigned char> key) {
for (auto const &c : key) {
std::cout << std::hex << static_cast<int>(c);
}
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_get_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <iostream>
#include <memory>
#include <span>

using namespace kmipclient;

Expand All @@ -31,7 +32,7 @@ namespace {
}
};

void print_hex(const std::vector<unsigned char> &key) {
void print_hex(std::span<const unsigned char> key) {
for (auto const &c : key) {
std::cout << std::hex << static_cast<int>(c);
}
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_get_tls_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

#include <iostream>
#include <optional>
#include <span>
#include <string_view>

using namespace kmipclient;

namespace {

void print_hex(const std::vector<unsigned char> &key) {
void print_hex(std::span<const unsigned char> key) {
for (auto const &c : key) {
std::cout << std::hex << static_cast<int>(c);
}
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_register_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

#include <iomanip>
#include <iostream>
#include <span>

using namespace kmipclient;

namespace {

void print_hex(const std::vector<unsigned char> &bytes) {
void print_hex(std::span<const unsigned char> bytes) {
for (const auto b : bytes) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(b);
Expand Down
3 changes: 2 additions & 1 deletion kmipclient/examples/example_register_secret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

#include <iomanip>
#include <iostream>
#include <span>
#include <string>

using namespace kmipclient;

namespace {

void print_hex(const std::vector<unsigned char> &bytes) {
void print_hex(std::span<const unsigned char> bytes) {
for (const auto b : bytes) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(b);
Expand Down
7 changes: 3 additions & 4 deletions kmipclient/include/kmipclient/KeyBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace kmipclient {

// ---- Raw bytes ----

[[nodiscard]] const std::vector<unsigned char> &value() const noexcept {
[[nodiscard]] const kmipcore::secure_bytes &value() const noexcept {
return key_value_;
}

Expand Down Expand Up @@ -103,11 +103,10 @@ namespace kmipclient {
* @param value Key material bytes.
* @param attrs Type-safe attribute bag (algorithm, length, mask, …).
*/
Key(const std::vector<unsigned char> &value,
kmipcore::Attributes attrs = {});
Key(std::span<const unsigned char> value, kmipcore::Attributes attrs = {});

private:
std::vector<unsigned char> key_value_;
kmipcore::secure_bytes key_value_;
kmipcore::Attributes attributes_;
};

Expand Down
4 changes: 2 additions & 2 deletions kmipclient/include/kmipclient/kmipclient_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/** @brief kmipclient semantic version major component. */
#define KMIPCLIENT_VERSION_MAJOR 0
/** @brief kmipclient semantic version minor component. */
#define KMIPCLIENT_VERSION_MINOR 2
#define KMIPCLIENT_VERSION_MINOR 3
/** @brief kmipclient semantic version patch component. */
#define KMIPCLIENT_VERSION_PATCH 1
#define KMIPCLIENT_VERSION_PATCH 0

/** @brief Internal helper for macro-stringification. */
#define KMIPCLIENT_STRINGIFY_I(x) #x
Expand Down
13 changes: 6 additions & 7 deletions kmipclient/src/IOUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace kmipclient {
}
}

void IOUtils::send(const std::vector<uint8_t> &request_bytes) const {
void IOUtils::send(std::span<const uint8_t> request_bytes) const {
const int dlen = static_cast<int>(request_bytes.size());
if (dlen <= 0) {
throw KmipIOException(
Expand All @@ -63,8 +63,7 @@ namespace kmipclient {
int total_sent = 0;
while (total_sent < dlen) {
const int sent = net_client.send(
std::span<const uint8_t>(request_bytes)
.subspan(static_cast<size_t>(total_sent))
request_bytes.subspan(static_cast<size_t>(total_sent))
);
if (sent <= 0) {
std::ostringstream oss;
Expand Down Expand Up @@ -92,7 +91,7 @@ namespace kmipclient {
}
}

std::vector<uint8_t> IOUtils::receive_message(size_t max_message_size) {
kmipcore::secure_bytes IOUtils::receive_message(size_t max_message_size) {
std::array<uint8_t, KMIP_MSG_LENGTH_BYTES> msg_len_buf{};

read_exact(msg_len_buf);
Expand All @@ -107,7 +106,7 @@ namespace kmipclient {
throw KmipIOException(kmipcore::KMIP_EXCEED_MAX_MESSAGE_SIZE, oss.str());
}

std::vector<uint8_t> response(
kmipcore::secure_bytes response(
KMIP_MSG_LENGTH_BYTES + static_cast<size_t>(length)
);
memcpy(response.data(), msg_len_buf.data(), KMIP_MSG_LENGTH_BYTES);
Expand All @@ -123,8 +122,8 @@ namespace kmipclient {
}

void IOUtils::do_exchange(
const std::vector<uint8_t> &request_bytes,
std::vector<uint8_t> &response_bytes,
std::span<const uint8_t> request_bytes,
kmipcore::secure_bytes &response_bytes,
size_t max_message_size
) {
try {
Expand Down
9 changes: 5 additions & 4 deletions kmipclient/src/IOUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "kmipclient/NetClient.hpp"
#include "kmipclient/types.hpp"
#include "kmipcore/kmip_logger.hpp"
#include "kmipcore/secure_memory.hpp"

#include <cstdint>
#include <memory>
Expand All @@ -27,15 +28,15 @@ namespace kmipclient {
: net_client(nc), logger_(logger) {};

void do_exchange(
const std::vector<uint8_t> &request_bytes,
std::vector<uint8_t> &response_bytes,
std::span<const uint8_t> request_bytes,
kmipcore::secure_bytes &response_bytes,
size_t max_message_size
);

private:
void log_debug(const char *event, std::span<const uint8_t> ttlv) const;
void send(const std::vector<uint8_t> &request_bytes) const;
std::vector<uint8_t> receive_message(size_t max_message_size);
void send(std::span<const uint8_t> request_bytes) const;
kmipcore::secure_bytes receive_message(size_t max_message_size);

/**
* Reads exactly n bytes from the network into the buffer.
Expand Down
4 changes: 2 additions & 2 deletions kmipclient/src/Key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace kmipclient {

Key::Key(const std::vector<unsigned char> &value, kmipcore::Attributes attrs)
: key_value_(value), attributes_(std::move(attrs)) {}
Key::Key(std::span<const unsigned char> value, kmipcore::Attributes attrs)
: key_value_(value.begin(), value.end()), attributes_(std::move(attrs)) {}

kmipcore::Key Key::to_core_key() const {
return kmipcore::Key(key_value_, type(), attributes_);
Expand Down
32 changes: 16 additions & 16 deletions kmipclient/src/KmipClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand All @@ -183,7 +183,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -300,7 +300,7 @@ namespace kmipclient {
id, {}, request.getHeader().getProtocolVersion(), true
)
);
std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -343,7 +343,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -408,7 +408,7 @@ namespace kmipclient {
id, {}, request.getHeader().getProtocolVersion(), true
)
);
std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -448,7 +448,7 @@ namespace kmipclient {
const auto batch_item_id =
request.add_batch_item(kmipcore::ActivateRequest(id));

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand All @@ -467,7 +467,7 @@ namespace kmipclient {
const auto batch_item_id =
request.add_batch_item(kmipcore::GetAttributeListRequest(id));

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -495,7 +495,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -546,7 +546,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -649,7 +649,7 @@ namespace kmipclient {
)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -761,7 +761,7 @@ namespace kmipclient {
);
const auto batch_item_id = request.add_batch_item(std::move(item));

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -809,7 +809,7 @@ namespace kmipclient {
item.setRequestPayload(payload);
const auto batch_item_id = request.add_batch_item(std::move(item));

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down Expand Up @@ -856,7 +856,7 @@ namespace kmipclient {
kmipcore::RevokeRequest(id, reason, message, occurrence_time)
);

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand All @@ -874,7 +874,7 @@ namespace kmipclient {
const auto batch_item_id =
request.add_batch_item(kmipcore::DestroyRequest(id));

std::vector<uint8_t> response_bytes;
kmipcore::secure_bytes response_bytes;
io->do_exchange(
request.serialize(), response_bytes, request.getMaxResponseSize()
);
Expand Down
Loading
Loading