3 * Parse group description strings
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb 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 Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
33 /*----- Main code ---------------------------------------------------------*/
35 /* --- @group_parse@ --- *
37 * Arguments: @qd_parse *qd@ = quick-and-dirty parser
39 * Returns: Group pointer, or null for failure.
41 * Use: Parses a group description and returns the group. This has
42 * the form `TYPE { SPEC }' where TYPE is `prime' or `ec', and
43 * SPEC is the appropriate kind of group specification of the
47 group
*group_parse(qd_parse
*qd
)
51 switch (qd_enum(qd
, "prime,bin,ec")) {
55 if (dh_parse(qd
, &dp
)) goto ouch
;
63 if (dhbin_parse(qd
, &dp
)) goto ouch
;
65 g
= group_binary(&dp
);
71 if (ec_infoparse(qd
, &ei
)) goto ouch
;
76 if (!g
) qd
->e
= "bad group parameters";
81 /* --- @group_fromstring@ --- *
83 * Arguments: @const char *p@ = pointer to string to read
84 * @group **gg@ = where to put the group pointer
86 * Returns: Null if OK, or an error string.
88 * Use: Parses a group spec from a string, and returns the group.
91 const char *group_fromstring(const char *p
, group
**gg
)
98 if ((g
= group_parse(&qd
)) == 0) return (qd
.e
);
99 if (!qd_eofp(&qd
)) { G_DESTROYGROUP(g
); return ("junk at end of string"); }
104 /*----- That's all, folks -------------------------------------------------*/