Skip to content

Commit

Permalink
http_utils update using std::span
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Feb 17, 2023
1 parent 9574cb1 commit 6479d27
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/utils/http_util/http_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::string http_transact(const std::string& hostname,
return oss.str();
}

bool needs_url_encoding(char c)
inline bool needs_url_encoding(char c)
{
if(c >= 'A' && c <= 'Z')
return false;
Expand Down
7 changes: 4 additions & 3 deletions src/lib/utils/http_util/http_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <botan/types.h>
#include <botan/exceptn.h>
#include <vector>
#include <span>
#include <map>
#include <string>
#include <functional>
Expand Down Expand Up @@ -40,7 +41,7 @@ class Response final
Response() : m_status_code(0), m_status_message("Uninitialized") {}

Response(unsigned int status_code, const std::string& status_message,
const std::vector<uint8_t>& body,
std::span<const uint8_t> body,
const std::map<std::string, std::string>& headers) :
m_status_code(status_code),
m_status_message(status_message),
Expand All @@ -49,7 +50,7 @@ class Response final

unsigned int status_code() const { return m_status_code; }

const std::vector<uint8_t>& body() const { return m_body; }
std::span<const uint8_t> body() const { return m_body; }

const std::map<std::string, std::string>& headers() const { return m_headers; }

Expand All @@ -64,7 +65,7 @@ class Response final
private:
unsigned int m_status_code;
std::string m_status_message;
std::vector<uint8_t> m_body;
std::span<const uint8_t> m_body;
std::map<std::string, std::string> m_headers;
};

Expand Down
3 changes: 2 additions & 1 deletion src/lib/x509/ocsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <botan/bigint.h>

#include <chrono>
#include <span>
#include <optional>

namespace Botan {
Expand Down Expand Up @@ -148,7 +149,7 @@ class BOTAN_PUBLIC_API(2,0) Response final
* Parses an OCSP response.
* @param response_bits response bits received
*/
Response(const std::vector<uint8_t>& response_bits) :
Response(std::span<const uint8_t> response_bits) :
Response(response_bits.data(), response_bits.size())
{}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/x509/x509_crl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ X509_CRL::X509_CRL(DataSource& src)
load_data(src);
}

X509_CRL::X509_CRL(const std::vector<uint8_t>& vec)
X509_CRL::X509_CRL(std::span<const uint8_t> vec)
{
DataSource_Memory src(vec.data(), vec.size());
load_data(src);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/x509/x509_crl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <botan/asn1_obj.h>
#include <botan/pkix_enums.h>
#include <vector>
#include <span>

namespace Botan {

Expand Down Expand Up @@ -166,7 +167,7 @@ class BOTAN_PUBLIC_API(2,0) X509_CRL final : public X509_Object
* Construct a CRL from a binary vector
* @param vec the binary (DER) representation of the CRL
*/
X509_CRL(const std::vector<uint8_t>& vec);
X509_CRL(std::span<const uint8_t> vec);

/**
* Construct a CRL
Expand Down

0 comments on commit 6479d27

Please sign in to comment.