+/* --- @cmd_encode@, @cmd_decode@ --- */
+
+#define CMD_ENCODE { \
+ "encode", cmd_encode, \
+ "encode [-p] [-f FORMAT] [-b LABEL] [-o OUTPUT] [FILE]", \
+ "\
+Options:\n\
+\n\
+-f, --format=FORMAT Encode to FORMAT.\n\
+-b, --boundary=LABEL PEM boundary is LABEL.\n\
+-o, --output=FILE Write output to FILE.\n\
+-p, --progress Show progress on large files.\n\
+" }
+
+#define CMD_DECODE { \
+ "decode", cmd_decode, \
+ "decode [-p] [-f FORMAT] [-b LABEL] [-o OUTPUT] [FILE]", \
+ "\
+Options:\n\
+\n\
+-f, --format=FORMAT Decode from FORMAT.\n\
+-b, --boundary=LABEL PEM boundary is LABEL.\n\
+-o, --output=FILE Write output to FILE.\n\
+-p, --progress Show progress on large files.\n\
+" }
+
+extern int cmd_encode(int /*argc*/, char */*argv*/[]);
+extern int cmd_decode(int /*argc*/, char */*argv*/[]);
+
+/*----- Hash encoding functions -------------------------------------------*/
+
+/* --- Table --- */
+
+#define ENCODINGS(_) \
+ _(HEX, hex) \
+ _(BASE64, base64) \
+ _(BASE32, base32)
+
+enum {
+#define ENUM(tag, name) ENC_##tag,
+ ENCODINGS(ENUM)
+#undef ENUM
+ ENC_LIMIT
+};
+
+typedef struct encodeops {
+ const char *name;
+ void (*put)(const octet *, size_t, FILE *);
+ size_t (*get)(const char *, octet *, size_t, char **);
+} encodeops;
+
+extern const encodeops encodingtab[];
+
+/* --- @getencoding@ --- *
+ *
+ * Arguments: @const char *ename@ = encoding name
+ *
+ * Returns: Pointer to encoding table entry, or null.
+ *
+ * Use: Finds an encoding entry given its name.
+ */
+
+extern const encodeops *getencoding(const char */*ename*/);
+
+/*----- File hashing ------------------------------------------------------*/
+
+/* --- @gethash@ --- *
+ *
+ * Arguments: @const char *name@ = pointer to name string
+ *
+ * Returns: Pointer to appropriate hash class.
+ *
+ * Use: Chooses a hash function by name.
+ */
+
+extern const gchash *gethash(const char */*name*/);
+
+/* --- @fhash@ --- *
+ *
+ * Arguments: @const gchash *gch@ = pointer to hash function to use
+ * @unsigned f@ = flags to set
+ * @const char *file@ = file name to be hashed (null for stdin)
+ * @void *buf@ = pointer to hash output buffer
+ *
+ * Returns: Zero if it worked, nonzero on error.
+ *
+ * Use: Hashes a file.
+ */
+
+#define FHF_BINARY 256u
+#define FHF_PROGRESS 512u
+
+#define FHF_MASK 384u
+
+extern int fhash(const gchash */*gch*/, unsigned /*f*/,
+ const char */*file*/, void */*buf*/);
+
+/* --- @hfparse@ --- *
+ *
+ * Arguments: @hfpctx *hfp@ = pointer to the context structure
+ *
+ * Returns: A code indicating what happened.
+ *
+ * Use: Parses a line from the input file.
+ */
+
+enum { /* Meaning and members set */
+ HF_FILE, /* File hash: @dline@ and @hbuf@ */
+ HF_ENC, /* Encoding: @ee@ */
+ HF_HASH, /* Hash function: @gch@ */
+ HF_ESC, /* Name escape: @f@ */
+ HF_EOF, /* End of file */
+ HF_BAD /* Unrecognized line */
+};
+
+typedef struct hfpctx {
+ unsigned f; /* Flags to read */
+#define HFF_ESCAPE 1u /* File names are escaped */
+ FILE *fp; /* Input file to read */
+ dstr *dline; /* Line contents, corrupted */
+ const gchash *gch; /* Hash function to use */
+ const encodeops *ee; /* Encoding to apply to hashes */
+ dstr *dfile; /* File name for @HF_FILE@ lines */
+ octet *hbuf; /* Output buffer for hash data */
+} hfpctx;
+
+extern int hfparse(hfpctx */*hfp*/);
+
+/*----- String I/O --------------------------------------------------------*/
+
+#define GSF_RAW 4096u
+#define GSF_FILE 0u
+#define GSF_STRING 8192u
+
+#define GSF_MASK 61440u
+
+/* --- @getstring@ --- *
+ *
+ * Arguments: @void *in@ = input source
+ * @dstr *d@ = destination string
+ * @unsigned f@ = input flags
+ *
+ * Returns: Zero if OK, nonzero on end-of-file.
+ *
+ * Use: Reads a filename (or something similar) from a stream.
+ */
+
+extern int getstring(void */*in*/, dstr */*d*/, unsigned /*f*/);
+
+/* --- @putstring@ --- *
+ *
+ * Arguments: @FILE *fp@ = stream to write on
+ * @const char *p@ = pointer to text
+ * @unsigned f@ = output flags
+ *
+ * Returns: ---
+ *
+ * Use: Emits a string to a stream.
+ */
+
+extern void putstring(FILE */*fp*/, const char */*p*/, unsigned /*f*/);
+
+/*----- Lists of things ---------------------------------------------------*/
+