1 /*
2  * 20131204
3  * Jan Mojzis
4  * Public domain.
5  */
6 
7 #include "hexdecode.h"
8 #include "base32decode.h"
9 #include "byte.h"
10 #include "str.h"
11 #include "keyparse.h"
12 
keyparse(unsigned char * keys,long long keyslen,const char * xx)13 int keyparse(unsigned char *keys, long long keyslen, const char *xx) {
14 
15     long long len;
16     const unsigned char *x = (const unsigned char *)xx;
17 
18     if (!xx) return 0;
19     if (keyslen != 32) return 0;
20 
21     len = str_len(xx);
22 
23     switch (len) {
24         case 54:
25             if (!byte_isequal(x, 3, "uz5")) return 0;
26             if (!base32decode(keys, 32, x + 3, 51)) return 0;
27             break;
28         case 51:
29             if (!base32decode(keys, 32, x, 51)) return 0;
30             break;
31         case 64:
32             if (!hexdecode(keys, 32, x, 64)) return 0;
33             break;
34         default:
35             return 0;
36     }
37     return 1;
38 }
39