aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_decompose_chain1.c
blob: 216c649d7bee799e5409bfa3ff47149fcb767e84 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


extern inline size_t librecrypt_decompose_chain1(char *hash);


#else


#define CHECK(IN, OUT, N)\
	do {\
		assert(sizeof(IN) <= sizeof(buf));\
		assert(sizeof(IN) == sizeof(OUT));\
		stpcpy(buf, (IN));\
		n = librecrypt_decompose_chain1(buf);\
		EXPECT(n == (N));\
		EXPECT(n == librecrypt_chain_length(IN));\
		EXPECT(!memcmp(buf, (OUT), sizeof(IN)));\
	} while (0)


int
main(void)
{
	char buf[64u];
	size_t n;

	SET_UP_ALARM();

	/* Check each '>' was replaced with NUL, and number
	 * of '>' plus 1 (number of algorithms) was returned */
	CHECK("", "", 1u);
	CHECK(">", "\0", 2u);
	CHECK("a$b>c$d>e$f", "a$b\0c$d\0e$f", 3u);

	return 0;
}


#endif