2 * This file is part of secnet.
3 * See README for full list of copyright holders.
5 * secnet is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * secnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * version 3 along with secnet; if not, see
17 * https://www.gnu.org/licenses/gpl.html.
21 #include "base91s/base91.h"
23 #include "pubkeys.yy.h"
25 void keyset_dispose(struct peer_keyset **ks_io)
27 struct peer_keyset *ks=*ks_io;
31 assert(ks->refcount>=0);
32 if (ks->refcount) return;
34 for (ki=0; ki<ks->nkeys; ki++) {
35 struct sigpubkey_if *pk=ks->keys[ki].pubkey;
41 const struct sigscheme_info *sigscheme_lookup(const char *name)
43 const struct sigscheme_info *scheme;
44 for (scheme=sigschemes; scheme->name; scheme++)
45 if (!strcmp(name,scheme->name))
50 static list_t *makepublic_apply(closure_t *self, struct cloc loc,
51 dict_t *context, list_t *args)
53 CL_GET_STR_ARG(0,algname,"algorithm name");
54 CL_GET_STR_ARG(1,b91d,"base91s-encoded public key");
56 const struct sigscheme_info *sch=sigscheme_lookup(algname);
57 if (!sch) cfgfatal(algname_i->loc,"make-public",
58 "unknown algorithm `%s'",algname);
60 size_t b91l=strlen(b91d);
61 if (b91l > INT_MAX/4) cfgfatal(algname_i->loc,"make-public",
62 "base91s data unreasonably long");
65 buffer_new(&buf,base91s_decode_maxlen(b91l));
66 BUF_ALLOC(&buf,"make-public data buf");
67 assert(buf.start == buf.base);
70 buf.size= base91s_decode(&b91,b91d,b91l,buf.start);
71 buf.size += base91s_decode_end(&b91,buf.start+buf.size);
72 assert(buf.size <= buf.alloclen);
74 struct cfgfile_log log;
75 cfgfile_log_init(&log,loc,"make-public");
77 struct sigpubkey_if *pubkey;
79 bool_t ok=sch->loadpub(sch,&buf,&pubkey,&cl,&log.log,loc);
80 if (!ok) cfgfatal(loc,"make-public","public key loading failed");
84 return new_closure(cl);
87 void pubkeys_init(dict_t *dict) {
88 add_closure(dict,"make-public",makepublic_apply);