3 * Parse group description strings
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Trivial IP Encryption (TrIPE).
12 * TrIPE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * TrIPE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
32 /*----- Main code ---------------------------------------------------------*/
34 /* --- @group_parse@ --- *
36 * Arguments: @qd_parse *qd@ = quick-and-dirty parser
38 * Returns: Group pointer, or null for failure.
40 * Use: Parses a group description and returns the group. This has
41 * the form `TYPE { SPEC }' where TYPE is `prime' or `ec', and
42 * SPEC is the appropriate kind of group specification of the
46 group *group_parse(qd_parse *qd)
50 switch (qd_enum(qd, "prime,ec")) {
54 if (dh_parse(qd, &dp)) goto ouch;
62 if (ec_infoparse(qd, &ei)) goto ouch;
67 if (!g) qd->e = "bad group parameters";
72 /* --- @group_fromstring@ --- *
74 * Arguments: @const char *p@ = pointer to string to read
75 * @group **gg@ = where to put the group pointer
77 * Returns: Null if OK, or an error string.
79 * Use: Parses a group spec from a string, and returns the group.
82 const char *group_fromstring(const char *p, group **gg)
89 if ((g = group_parse(&qd)) == 0) return (qd.e);
90 if (!qd_eofp(&qd)) { G_DESTROYGROUP(g); return ("junk at end of string"); }
95 /*----- That's all, folks -------------------------------------------------*/