-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstream_test.c
36 lines (29 loc) · 1.21 KB
/
stream_test.c
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
#include "stream.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void test_parse_aesgcm_url() {
char expected_url[] = "https://example.org";
unsigned char expected_nonce[AESGCM_URL_NONCE_LEN / 2] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x00, 0x00, 0x00, 0x00};
unsigned char expected_key[AESGCM_URL_KEY_LEN / 2] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
char raw_url[] =
"aesgcm://"
"example.org#"
"123456789ABCdef000000000" // Nonce
"123456789abcDEF000000000123456789aBCDEf000000000123456789AbcdeF0"; // Key
unsigned char key[AESGCM_URL_KEY_LEN / 2];
unsigned char nonce[AESGCM_URL_NONCE_LEN / 2];
char *parsed_url;
parsed_url =
parse_aesgcm_url(raw_url, nonce, sizeof(nonce), key, sizeof(key));
assert(parsed_url != NULL);
assert(strcmp(parsed_url, expected_url) == 0);
assert(memcmp(nonce, expected_nonce, sizeof(nonce)) == 0);
assert(memcmp(key, expected_key, sizeof(key)) == 0);
free(parsed_url);
}
int main(int argc, char **argv) { test_parse_aesgcm_url(); }