Gather up another utility.
[u/mdw/catacomb] / key.h
diff --git a/key.h b/key.h
index 4ce7b7c..ada6260 100644 (file)
--- a/key.h
+++ b/key.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: key.h,v 1.6 2000/06/17 11:27:43 mdw Exp $
+ * $Id: key.h,v 1.11 2004/04/08 01:36:15 mdw Exp $
  *
  * Simple key management
  *
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: key.h,v $
- * Revision 1.6  2000/06/17 11:27:43  mdw
- * Add key fetching interface.
- *
- * Revision 1.5  2000/02/12 18:55:40  mdw
- * Make it all compile properly.
- *
- * Revision 1.4  2000/02/12 18:21:02  mdw
- * Overhaul of key management (again).
- *
- * Revision 1.3  1999/12/22 15:47:48  mdw
- * Major key-management revision.
- *
- * Revision 1.2  1999/12/10 23:29:48  mdw
- * Change header file guard names.
- *
- * Revision 1.1  1999/09/03 08:41:12  mdw
- * Initial import.
- *
- */
-
 #ifndef CATACOMB_KEY_H
 #define CATACOMB_KEY_H
 
 #  include "key-data.h"
 #endif
 
+#ifndef CATACOMB_GHASH_H
+#  include "ghash.h"
+#endif
+
 #ifndef CATACOMB_MP_H
 #  include "mp.h"
 #endif
@@ -141,10 +122,8 @@ typedef struct key_file {
 
 /* --- Key file flags --- */
 
-enum {
-  KF_WRITE = 1,                                /* File opened for writing */
-  KF_MODIFIED = 2                      /* File has been modified */
-};
+#define KF_WRITE 1u                    /* File opened for writing */
+#define KF_MODIFIED 2u                 /* File has been modified */
 
 /* --- Iterating over keys --- *
  *
@@ -166,10 +145,10 @@ typedef struct key_fetchdef {
 
 /* --- File opening options --- */
 
-enum {
-  KOPEN_READ,
-  KOPEN_WRITE
-};
+#define KOPEN_READ 0u
+#define KOPEN_WRITE 1u
+#define KOPEN_MASK 0xff
+#define KOPEN_NOFILE 0x100
 
 /* --- Various other magic numbers --- */
 
@@ -192,6 +171,7 @@ enum {
   KERR_BADPASS = -10,                  /* Error decrypting locked key */
   KERR_WRONGTYPE = -11,                        /* Key has incorrect type */
   KERR_NOTFOUND = -12,                 /* Key couldn't be found */
+  KERR_BADATTR = -13,                  /* Malformed attribute name */
   KERR_MAX                             /* Largest possible error */
 };
 
@@ -250,7 +230,7 @@ extern int key_extract(key_file */*f*/, key */*k*/, FILE */*fp*/,
  *
  * Arguments:  @key_file *f@ = pointer to file structure to initialize
  *             @const char *file@ = pointer to the file name
- *             @int how@ = opening options (@KOPEN_*@).
+ *             @unsigned how@ = opening options (@KOPEN_*@).
  *             @key_reporter *rep@ = error reporting function
  *             @void *arg@ = argument for function
  *
@@ -264,7 +244,7 @@ extern int key_extract(key_file */*f*/, key */*k*/, FILE */*fp*/,
  *             owner only.
  */
 
-extern int key_open(key_file */*f*/, const char */*file*/, int /*how*/,
+extern int key_open(key_file */*f*/, const char */*file*/, unsigned /*how*/,
                    key_reporter */*rep*/, void */*arg*/);
 
 /* --- @key_close@ --- *
@@ -301,7 +281,7 @@ extern int key_save(key_file */*f*/);
  *
  * Arguments:  @key_file *f@ = pointer to file structure to initialize
  *             @const char *file@ = pointer to the file name
- *             @int how@ = opening options (@KOPEN_*@).
+ *             @unsigned how@ = opening options (@KOPEN_*@).
  *
  * Returns:    Zero if it worked, nonzero otherwise.
  *
@@ -316,7 +296,8 @@ extern int key_save(key_file */*f*/);
  *             for the private use of @key_open@.
  */
 
-extern int key_lockfile(key_file */*f*/, const char */*file*/, int /*how*/);
+extern int key_lockfile(key_file */*f*/, const char */*file*/,
+                       unsigned /*how*/);
 
 /*----- Creating and manipulating keys ------------------------------------*/
 
@@ -368,6 +349,15 @@ extern key *key_new(key_file */*f*/, uint32 /*id*/, const char */*type*/,
 
 extern int key_delete(key_file */*f*/, key */*k*/);
 
+/* --- @key_expired@ --- *
+ *
+ * Arguments:  @key *k@ = pointer to key block
+ *
+ * Returns:    Zero if the key is OK, nonzero if it's expired.
+ */
+
+int key_expired(key */*k*/);
+
 /* --- @key_expire@ --- *
  *
  * Arguments:  @key_file *f@ = pointer to file block
@@ -402,6 +392,20 @@ extern int key_expire(key_file */*f*/, key */*k*/);
 
 extern int key_used(key_file */*f*/, key */*k*/, time_t /*t*/);
 
+/* --- @key_fingerprint@ --- *
+ *
+ * Arguments:  @key *k@ = the key to fingerprint
+ *             @ghash *h@ = the hash to use
+ *             @const key_filter *kf@ = filter to apply
+ *
+ * Returns:    Nonzero if the key slightly matched the filter.
+ *
+ * Use:                Updates the hash context with the key contents.
+ */
+
+extern int key_fingerprint(key */*k*/, ghash */*h*/,
+                          const key_filter */*kf*/);
+
 /*----- Setting and reading attributes ------------------------------------*/
 
 /* --- @key_chkident@ --- *