+#include<base32.tests.h>
+
+int main() {
+ unsigned char *buf;
+ ssize_t n;
+
+ buf = NULL;
+ n = 0;
+
+ assert(from_base32(NULL, NULL) == -1);
+ assert(from_base32(&buf, &n) == -1);
+
+ buf = malloc(3);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "XY");
+
+ assert(from_base32(&buf, &n) == -1);
+
+ n = 2;
+ assert(from_base32(&buf, &n) == 1);
+ assert(buf[0] == 190);
+ assert(n == 1);
+ free(buf);
+
+ buf = malloc(5);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "6LKQ");
+
+ n = 4;
+ assert(from_base32(&buf, &n) == 1);
+ assert(buf[0] == 242);
+ assert(buf[1] == 213);
+ assert(n == 2);
+ free(buf);
+
+ buf = malloc(6);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "LQ7YC");
+
+ n = 5;
+ assert(from_base32(&buf, &n) == 1);
+ assert(buf[0] == 92);
+ assert(buf[1] == 63);
+ assert(buf[2] == 129);
+ assert(n == 3);
+ free(buf);
+
+ buf = malloc(8);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "TOA5RWI");
+
+ n = 7;
+ assert(from_base32(&buf, &n) == 1);
+ assert(buf[0] == 155);
+ assert(buf[1] == 129);
+ assert(buf[2] == 216);
+ assert(buf[3] == 217);
+ assert(n == 4);
+ free(buf);
+
+ buf = malloc(14);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "RZLJOCOTSPYRC");
+
+ n = 13;
+ assert(from_base32(&buf, &n) == 1);
+ assert(buf[0] == 142);
+ assert(buf[1] == 86);
+ assert(buf[2] == 151);
+ assert(buf[3] == 9);
+ assert(buf[4] == 211);
+ assert(buf[5] == 147);
+ assert(buf[6] == 241);
+ assert(buf[7] == 17);
+ assert(n == 8);
+ free(buf);
+
+ buf = malloc(53);
+ assert(buf!=NULL);
+ strcpy((char *)buf, "4KFCI2A3CLB2FV7MAYKSYAXNKFIYH6BOP5UEOOGCF6MLEXTU6KGA");
+
+ n = 52;
+ assert(from_base32(&buf, &n) == 1);
+ unsigned char expected[] = { 226, 138, 36, 104, 27, 18, 195, 162, 215, 236, 6, 21, 44, 2, 237, 81, 81, 131,
+ 248, 46, 127, 104, 71, 56, 194, 47, 152, 178, 94, 116, 242, 140 };
+ assert(memcmp(buf, expected, 32) == 0);
+ assert(n == 32);
+ free(buf);
+
+ return EXIT_SUCCESS;
+}