-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil_misc.hpp
72 lines (51 loc) · 1.21 KB
/
util_misc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2019 David Butler <[email protected]>
#pragma once
#include "util_types.hpp"
template<u64 LEN> struct StackBuffer {
u8 space[LEN];
operator Buffer() { return { space, LEN }; }
Buffer buffer() { return { space, LEN }; }
};
struct LineReadBuffer {
Buffer buffer;
size_t used;
Buffer line;
void initialize(Buffer buffer_) {
buffer=buffer_;
used=0;
line={ buffer.start, 0};
}
};
struct Stream {
int fd;
bool read_line(LineReadBuffer&lrbuffer);
void write(Buffer buffer);
void close();
};
struct TCPServer {
int fd;
static TCPServer listen(u16 port);
u16 get_port();
Stream accept();
void close();
};
struct HashMeow {
alignas(16) u8 _internal_meow_hash_state[144];
u8 _internal_end[0];
void initialize();
// DO NOT MIX THESE TWO UPDATE CALLS!
void update(Buffer buffer);
// void update(u8 buffer[static 64]); // NOT TESTED
u64 finalize();
};
struct hash_MD5 {
unsigned state[4];
u64 count;
union {
char c[64];
unsigned i[16];
} tmp_buffer;
void initialize();
void update(Buffer buffer);
void finalize(u8*hash_out16);
};