mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Add EncodeHex() and DecodeHex() to Redbean
This commit is contained in:
parent
00acd81b2f
commit
a186143f62
9 changed files with 97 additions and 13 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/str/blake2.h"
|
||||
#include "libc/str/highwayhash64.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
@ -266,6 +267,13 @@ TEST(sha512, test) {
|
|||
EXPECT_EQ(0, memcmp(want, d, 64));
|
||||
}
|
||||
|
||||
static const uint64_t kTestKey1[4] = {
|
||||
0x0706050403020100,
|
||||
0x0F0E0D0C0B0A0908,
|
||||
0x1716151413121110,
|
||||
0x1F1E1D1C1B1A1918,
|
||||
};
|
||||
|
||||
BENCH(mbedtls, bench) {
|
||||
uint8_t d[64];
|
||||
EZBENCH_N("md5", kHyperionSize, mbedtls_md5_ret(kHyperion, kHyperionSize, d));
|
||||
|
@ -280,6 +288,8 @@ BENCH(mbedtls, bench) {
|
|||
EZBENCH_N("blake2b256", kHyperionSize,
|
||||
BLAKE2B256(kHyperion, kHyperionSize, d));
|
||||
EZBENCH_N("crc32_z", kHyperionSize, crc32_z(0, kHyperion, kHyperionSize));
|
||||
EZBENCH_N("highwayhash64", kHyperionSize,
|
||||
HighwayHash64(kHyperion, kHyperionSize, kTestKey1));
|
||||
}
|
||||
|
||||
char *mpi2str(mbedtls_mpi *m) {
|
||||
|
|
|
@ -47,6 +47,9 @@ assert(hex(0x1940efe9d47ae889) == "0x1940efe9d47ae889")
|
|||
assert(oct(0x1940efe9d47ae889) == "0145007376472436564211")
|
||||
assert(bin(0x1940efe9d47ae889) == "0b0001100101000000111011111110100111010100011110101110100010001001")
|
||||
|
||||
assert(EncodeHex("\1\2\3\4\255") == "01020304ff")
|
||||
assert(DecodeHex("01020304ff") == "\1\2\3\4\255")
|
||||
|
||||
assert(EscapeHtml(nil) == nil)
|
||||
assert(EscapeHtml("?hello&there<>") == "?hello&there<>")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue