600127f0 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: keycheck.h,v 1.1 2001/02/03 16:08:24 mdw Exp $ |
4 | * |
5 | * Framework for checking consistency of keys |
6 | * |
7 | * (c) 2001 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb 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 Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: keycheck.h,v $ |
33 | * Revision 1.1 2001/02/03 16:08:24 mdw |
34 | * Add consistency checking for public keys. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CATACOMB_KEYCHECK_H |
39 | #define CATACOMB_KEYCHECK_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #ifndef CATACOMB_MP_H |
48 | # include "mp.h" |
49 | #endif |
50 | |
51 | /*----- Data structures ---------------------------------------------------*/ |
52 | |
53 | enum { |
54 | KCSEV_ALL, |
55 | KCSEV_INFO = KCSEV_ALL, |
56 | KCSEV_WARN, |
57 | KCSEV_ERR, |
58 | KCSEV_MAX |
59 | }; |
60 | |
61 | typedef struct keycheck { |
62 | unsigned sev[KCSEV_MAX]; |
63 | int (*func)(unsigned /*sev*/, const char */*msg*/, void */*p*/); |
64 | void *p; |
65 | } keycheck; |
66 | |
67 | typedef struct keycheck_reportctx { |
68 | FILE *fp; |
69 | unsigned sev; |
70 | } keycheck_reportctx; |
71 | |
72 | /*----- Generic functions -------------------------------------------------*/ |
73 | |
74 | /* --- @keycheck_report@ --- * |
75 | * |
76 | * Arguments: @keycheck *kc@ = keycheck state |
77 | * @unsigned sev@ = severity of this report |
78 | * @const char *msg@ = message to send along |
79 | * @...@ = things to fill the message in with |
80 | * |
81 | * Returns: Zero to continue, or nonzero to stop and give up. |
82 | * |
83 | * Use: Reports a message to the user function. |
84 | */ |
85 | |
86 | extern int keycheck_report(keycheck */*kc*/, unsigned /*sev*/, |
87 | const char */*msg*/, ...); |
88 | |
89 | /* --- @keycheck_init@ --- * |
90 | * |
91 | * Arguments: @keycheck *kc@ = pointer to block to initialize |
92 | * @int (*func)(unsigned sev, const char *msg, void *p)@ = |
93 | * handler function for problems |
94 | * @void *p@ = pointer to give to handler |
95 | * |
96 | * Returns: --- |
97 | * |
98 | * Use: Initializes a key checking context. |
99 | */ |
100 | |
101 | extern void keycheck_init(keycheck */*kc*/, |
102 | int (*/*func*/)(unsigned /*sev*/, |
103 | const char */*msg*/, |
104 | void */*p*/), |
105 | void */*p*/); |
106 | |
107 | /* --- @keycheck_allclear@ --- * |
108 | * |
109 | * Arguments: @keycheck *kc@ = pointer to keycheck context |
110 | * @unsigned sev@ = minimum severity to care about |
111 | * |
112 | * Returns: Nonzero if no problems of @sev@ or above were noticed. |
113 | */ |
114 | |
115 | extern int keycheck_allclear(keycheck */*kc*/, unsigned /*sev*/); |
116 | |
117 | /*----- A standard report function ----------------------------------------*/ |
118 | |
119 | /* --- @keycheck_stdreport@ --- * |
120 | * |
121 | * Arguments: @unsigned sev@ = problem severity |
122 | * @const char *msg@ = message to report |
123 | * @void *p@ = pointer to a @keycheck_reportctx@ structure |
124 | * |
125 | * Returns: Zero. |
126 | * |
127 | * Use: Reports a message to stderr. |
128 | */ |
129 | |
130 | extern int keycheck_stdreport(unsigned /*sev*/, |
131 | const char */*msg*/, void */*p*/); |
132 | |
133 | /*----- Special support functions for large integers ----------------------*/ |
134 | |
135 | /* --- @keycheck_prime@ --- * |
136 | * |
137 | * Arguments: @keycheck *kc@ = keycheck state |
138 | * @unsigned sev@ = severity if not prime |
139 | * @mp *m@ = a number to check for primality |
140 | * @const char *name@ = name of this number |
141 | * |
142 | * Returns: Zero if OK, or return status from function. |
143 | * |
144 | * Use: Checks that a number is prime. |
145 | */ |
146 | |
147 | extern int keycheck_prime(keycheck */*kc*/, unsigned /*sev*/, |
148 | mp */*m*/, const char */*name*/); |
149 | |
150 | /*----- That's all, folks -------------------------------------------------*/ |
151 | |
152 | #ifdef __cplusplus |
153 | } |
154 | #endif |
155 | |
156 | #endif |