-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A fairly major upgrade. Many minor improvements and fixes. TANK(servi…
…ce) now uses a new Elastic Binary Trees timers scheduler for performance and simplicity. New API for reloading a topic's partition configuration and a matching TANK CLI command for that. Cluster support(via consule integration) forthcoming.
- Loading branch information
1 parent
3c35e8d
commit 4c54b9f
Showing
292 changed files
with
129,343 additions
and
1,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include "switch.h" | ||
#include "base64.h" | ||
|
||
std::size_t Base64::decoded_repr_length(const str_view32 s) { | ||
size_t l = s.size(), padding; | ||
|
||
if (l && s.data()[l - 1] == '=') { | ||
if (l >= 2 && s.data()[l - 2] == '=') | ||
padding = 2; | ||
else | ||
padding = 1; | ||
} | ||
padding = 0; | ||
|
||
return (l * 3) / 4 - padding; | ||
} | ||
|
||
uint16_t b64_int(const uint8_t c) noexcept { | ||
if (c == 43) | ||
return 62; | ||
else if (c == 47) | ||
return 63; | ||
else if (c == 61) | ||
return 64; | ||
else if (c > 47 && c < 58) | ||
return c + 4; | ||
else if (c > 64 && c < 91) | ||
return c - 'A'; | ||
else if (c > 96 && c < 123) | ||
return (c - 'a') + 26; | ||
else | ||
return 256; | ||
} | ||
|
||
uint32_t Base64::Encode(const uint8_t *in, size_t in_len, Buffer *out) { | ||
static constexpr const char *b64_chr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
uint32_t s[3], j{0}; | ||
const auto saved{out->size()}; | ||
|
||
for (uint32_t i{0}; i != in_len; ++i) { | ||
s[j++] = in[i]; | ||
|
||
if (j == 3) { | ||
uint8_t o[4]; | ||
|
||
o[0] = b64_chr[(s[0] & 255) >> 2]; | ||
o[1] = b64_chr[((s[0] & 0x03) << 4) + ((s[1] & 0xF0) >> 4)]; | ||
o[2] = b64_chr[((s[1] & 0x0F) << 2) + ((s[2] & 0xC0) >> 6)]; | ||
o[3] = b64_chr[s[2] & 0x3F]; | ||
j = 0; | ||
|
||
out->append(str_view32(reinterpret_cast<const char *>(o), 4)); | ||
} | ||
} | ||
|
||
if (j) { | ||
uint8_t o[4]; | ||
|
||
if (j == 1) | ||
s[1] = 0; | ||
|
||
o[0] = b64_chr[(s[0] & 255) >> 2]; | ||
o[1] = b64_chr[((s[0] & 0x03) << 4) + ((s[1] & 0xF0) >> 4)]; | ||
|
||
if (j == 2) | ||
o[2] = b64_chr[((s[1] & 0x0F) << 2)]; | ||
else | ||
o[2] = '='; | ||
|
||
o[3] = '='; | ||
|
||
out->append(str_view32(reinterpret_cast<const char *>(o), 4)); | ||
} | ||
|
||
return out->size() - saved; | ||
} | ||
|
||
int32_t Base64::Decode(const uint8_t *in, const size_t in_len, Buffer *out) { | ||
uint32_t s[4], j{0}; | ||
const auto saved{out->size()}; | ||
|
||
for (uint32_t i{0}; i < in_len; i++) { | ||
if (const auto v = b64_int(in[i]); v == 256) | ||
return -1; | ||
else | ||
s[j++] = v; | ||
|
||
if (j == 4) { | ||
uint8_t k{0}, o[4]; | ||
|
||
o[0] = ((s[0] & 255) << 2) + ((s[1] & 0x30) >> 4); | ||
if (s[2] != 64) { | ||
o[1] = ((s[1] & 0x0F) << 4) + ((s[2] & 0x3C) >> 2); | ||
|
||
if ((s[3] != 64)) { | ||
o[2] = ((s[2] & 0x03) << 6) + (s[3]); | ||
k = 3; | ||
} else { | ||
k = 2; | ||
} | ||
} else { | ||
k = 1; | ||
} | ||
|
||
out->append(str_view32(reinterpret_cast<const char *>(o), k)); | ||
j = 0; | ||
} | ||
} | ||
|
||
return out->size() - saved; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include "switch.h" | ||
#include "buffer.h" | ||
#include <openssl/bio.h> | ||
#include <openssl/evp.h> | ||
|
||
static inline bool is_base64(const uint8_t c) noexcept | ||
{ | ||
return c == '+' || c == '/' || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); | ||
} | ||
|
||
|
||
namespace Base64 | ||
{ | ||
size_t decoded_repr_length(const str_view32 s); | ||
|
||
uint32_t Encode(const uint8_t *in, size_t in_len, Buffer *out); | ||
|
||
int32_t Decode(const uint8_t *in, const size_t in_len, Buffer *out); | ||
} |
Oops, something went wrong.