Skip to content

Commit

Permalink
hotplace rev.451 http
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Jan 7, 2024
1 parent 2305d87 commit a956b3c
Show file tree
Hide file tree
Showing 28 changed files with 1,135 additions and 207 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@
* RFC 8996 Deprecating TLS 1.0 and TLS 1.1
* sdk/net/tls/

* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* RFC 2069 An Extension to HTTP : Digest Access Authentication
* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* RFC 7616 HTTP Digest Access Authentication
* merlin project
* sdk/net/http
* test/httpserver

## not applied

* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* RFC 2069 An Extension to HTTP : Digest Access Authentication
* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* merlin project

## studying

Expand Down
4 changes: 2 additions & 2 deletions sdk/base/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class stream_t {
public:
virtual ~stream_t() {}

virtual byte_t* data() = 0;
virtual uint64 size() = 0;
virtual byte_t* data() const = 0;
virtual uint64 size() const = 0;
virtual return_t write(void* data, size_t size) = 0;
virtual return_t fill(size_t l, char c) = 0;
virtual return_t clear() = 0;
Expand Down
29 changes: 24 additions & 5 deletions sdk/base/stream/basic_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ basic_stream::basic_stream(const basic_stream& stream) : _handle(nullptr) {

basic_stream::~basic_stream() { _bio.close(_handle); }

const char* basic_stream::c_str() {
const char* basic_stream::c_str() const {
char* data = nullptr;
size_t size = 0;

_bio.get(_handle, (byte_t**)&data, &size);
return data;
}

byte_t* basic_stream::data() {
byte_t* basic_stream::data() const {
byte_t* data = nullptr;
size_t size = 0;

_bio.get(_handle, &data, &size);
return data;
}

uint64 basic_stream::size() {
uint64 basic_stream::size() const {
byte_t* data = nullptr;
size_t size = 0;

Expand Down Expand Up @@ -115,12 +115,26 @@ return_t basic_stream::printf(const wchar_t* buf, ...) {
return_t basic_stream::vprintf(const wchar_t* buf, va_list ap) { return _bio.vprintf(_handle, buf, ap); }
#endif

basic_stream& basic_stream::operator=(basic_stream obj) {
basic_stream& basic_stream::operator=(basic_stream const& obj) {
clear();
write(obj.data(), obj.size());
return *this;
}

basic_stream& basic_stream::operator=(std::string const& str) {
clear();
printf(str.c_str());
return *this;
}

basic_stream& basic_stream::operator=(const char* str) {
clear();
if (str) {
printf(str);
}
return *this;
}

basic_stream& basic_stream::operator<<(const char* str) {
if (str) {
printf(str);
Expand Down Expand Up @@ -148,7 +162,12 @@ basic_stream& basic_stream::operator<<(unsigned long value) {
return *this;
}

int basic_stream::compare(basic_stream obj) { return strcmp((*this).c_str(), obj.c_str()); }
basic_stream& basic_stream::operator<<(std::string const& value) {
printf("%s", value.c_str());
return *this;
}

int basic_stream::compare(basic_stream const& obj) { return strcmp((*this).c_str(), obj.c_str()); }

int basic_stream::compare(basic_stream& lhs, basic_stream& rhs) { return strcmp(lhs.c_str(), rhs.c_str()); }

Expand Down
13 changes: 8 additions & 5 deletions sdk/base/stream/basic_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class basic_stream : public stream_t {
/**
* @brief c-style string
*/
const char* c_str();
const char* c_str() const;
/**
* @brief data
*/
byte_t* data();
byte_t* data() const;
/**
* @brief size
*/
uint64 size();
uint64 size() const;
/**
* @brief write
* @param void* data [in]
Expand Down Expand Up @@ -95,18 +95,21 @@ class basic_stream : public stream_t {
basic_stream& operator<<(unsigned int value);
basic_stream& operator<<(long value);
basic_stream& operator<<(unsigned long value);
basic_stream& operator<<(std::string const& value);

/**
* @brief operator =
* @param basic_stream obj [in]
*/
basic_stream& operator=(basic_stream obj);
basic_stream& operator=(basic_stream const& obj);
basic_stream& operator=(std::string const& str);
basic_stream& operator=(const char* str);

/**
* @brief compare
* @param basic_stream obj [in]
*/
int compare(basic_stream obj);
int compare(basic_stream const& obj);
/**
* @brief compare
* @param basic_stream lhs [in]
Expand Down
4 changes: 2 additions & 2 deletions sdk/base/stream/bufferio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ return_t bufferio::close(bufferio_context_t* handle) {
return ret;
}

return_t bufferio::extend(bufferio_context_t* handle, size_t alloc_size, bufferio_t** allocated_pointer, uint32 flag) {
return_t bufferio::extend(bufferio_context_t* handle, size_t alloc_size, bufferio_t** allocated_pointer, uint32 flag) const {
return_t ret = errorcode_t::success;
void* memory_allocated = nullptr;
bufferio_t* bufferio_newly_allocated = nullptr;
Expand Down Expand Up @@ -273,7 +273,7 @@ return_t bufferio::size(bufferio_context_t* handle, size_t* contents_size) {
return ret;
}

return_t bufferio::get(bufferio_context_t* handle, byte_t** contents, size_t* contents_size, uint32 flags) {
return_t bufferio::get(bufferio_context_t* handle, byte_t** contents, size_t* contents_size, uint32 flags) const {
return_t ret = errorcode_t::success;
size_t index = 0;
size_t data_size = 0;
Expand Down
4 changes: 2 additions & 2 deletions sdk/base/stream/bufferio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class bufferio {
* @param uint32 flag [IN] flag
* @return error code (see error.hpp)
*/
return_t get(bufferio_context_t* handle, byte_t** contents, size_t* contents_size, uint32 flag = 0);
return_t get(bufferio_context_t* handle, byte_t** contents, size_t* contents_size, uint32 flag = 0) const;
/**
* @brief compare
* @param bufferio_context_t* handle [IN] handle
Expand Down Expand Up @@ -269,7 +269,7 @@ class bufferio {
* @return
* @remarks
*/
return_t extend(bufferio_context_t* handle, size_t alloc_size, bufferio_t** allocated_pointer, uint32 flag = 0);
return_t extend(bufferio_context_t* handle, size_t alloc_size, bufferio_t** allocated_pointer, uint32 flag = 0) const;

/**
* @brief find
Expand Down
50 changes: 50 additions & 0 deletions sdk/crypto/basic/openssl_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,5 +525,55 @@ return_t openssl_digest::digest(hash_algorithm_t alg, binary_t const& input, bin
return ret;
}

return_t openssl_digest::digest(const char* alg, basic_stream const& input, binary_t& output) {
return_t ret = errorcode_t::success;
hash_context_t* handle = nullptr;

__try2 {
ret = open(&handle, alg);
if (errorcode_t::success != ret) {
__leave2;
}
init(handle);
update(handle, input.data(), input.size());
finalize(handle, output);
}
__finally2 { close(handle); }
return ret;
}

return_t openssl_digest::digest(const char* alg, basic_stream const& input, std::string& hashstring) {
return_t ret = errorcode_t::success;
binary_t output;
ret = digest(alg, input, output);
hashstring = base16_encode(output);
return ret;
}

return_t openssl_digest::digest(const char* alg, std::string const& input, binary_t& output) {
return_t ret = errorcode_t::success;
hash_context_t* handle = nullptr;

__try2 {
ret = open(&handle, alg);
if (errorcode_t::success != ret) {
__leave2;
}
init(handle);
update(handle, (byte_t*)input.c_str(), input.size());
finalize(handle, output);
}
__finally2 { close(handle); }
return ret;
}

return_t openssl_digest::digest(const char* alg, std::string const& input, std::string& hashstring) {
return_t ret = errorcode_t::success;
binary_t output;
ret = digest(alg, input, output);
hashstring = base16_encode(output);
return ret;
}

} // namespace crypto
} // namespace hotplace
6 changes: 6 additions & 0 deletions sdk/crypto/basic/openssl_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ class openssl_digest : public openssl_hash {

return_t digest(const char* alg, binary_t const& input, binary_t& output);
return_t digest(hash_algorithm_t alg, binary_t const& input, binary_t& output);

return_t digest(const char* alg, basic_stream const& input, binary_t& output);
return_t digest(const char* alg, basic_stream const& input, std::string& hashstring);

return_t digest(const char* alg, std::string const& input, binary_t& output);
return_t digest(const char* alg, std::string const& input, std::string& hashstring);
};

class openssl_mac : public openssl_hash {
Expand Down
11 changes: 11 additions & 0 deletions sdk/crypto/basic/openssl_prng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,16 @@ return_t openssl_prng::random(uint32& i, uint32 mask) {
return ret;
}

std::string openssl_prng::nonce(size_t size) {
std::string ret_value;

binary_t buffer;
buffer.resize(size);
RAND_bytes(&buffer[0], buffer.size());
base16_encode(buffer, ret_value);

return ret_value;
}

} // namespace crypto
} // namespace hotplace
1 change: 1 addition & 0 deletions sdk/crypto/basic/openssl_prng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class openssl_prng {
return_t random(unsigned char* buf, size_t size);
return_t random(binary_t& buffer, size_t size);
return_t random(uint32& i, uint32 mask = (uint32)~1);
std::string nonce(size_t size);
};

} // namespace crypto
Expand Down
1 change: 1 addition & 0 deletions sdk/crypto/cose/cbor_object_signing_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sdk/crypto/basic/openssl_ecdh.hpp>
#include <sdk/crypto/basic/openssl_hash.hpp>
#include <sdk/crypto/basic/openssl_kdf.hpp>
#include <sdk/crypto/basic/openssl_prng.hpp>
#include <sdk/crypto/basic/openssl_sign.hpp>
#include <sdk/crypto/cose/cbor_object_encryption.hpp>
#include <sdk/crypto/cose/cbor_object_signing.hpp>
Expand Down
Loading

0 comments on commit a956b3c

Please sign in to comment.