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