aboutsummaryrefslogtreecommitdiffstats
path: root/g10/armor.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/armor.c')
-rw-r--r--g10/armor.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/g10/armor.c b/g10/armor.c
index e9efa779d..8f22f316c 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -114,6 +114,54 @@ static char *tail_strings[] = {
};
+static int armor_filter ( void *opaque, int control,
+ iobuf_t chain, byte *buf, size_t *ret_len);
+
+
+
+
+/* Create a new context for armor filters. */
+armor_filter_context_t *
+new_armor_context (void)
+{
+ armor_filter_context_t *afx;
+
+ afx = xcalloc (1, sizeof *afx);
+ afx->refcount = 1;
+
+ return afx;
+}
+
+/* Release an armor filter context. Passing NULL is explicitly
+ allowed and a no-op. */
+void
+release_armor_context (armor_filter_context_t *afx)
+{
+ if (!afx)
+ return;
+ assert (afx->refcount);
+ if ( --afx->refcount )
+ return;
+ xfree (afx);
+}
+
+/* Push the armor filter onto the iobuf stream IOBUF. */
+int
+push_armor_filter (armor_filter_context_t *afx, iobuf_t iobuf)
+{
+ int rc;
+
+ afx->refcount++;
+ rc = iobuf_push_filter (iobuf, armor_filter, afx);
+ if (rc)
+ afx->refcount--;
+ return rc;
+}
+
+
+
+
+
static void
initialize(void)
{
@@ -862,7 +910,7 @@ radix64_read( armor_filter_context_t *afx, IOBUF a, size_t *retn,
/****************
* This filter is used to handle the armor stuff
*/
-int
+static int
armor_filter( void *opaque, int control,
IOBUF a, byte *buf, size_t *ret_len)
{
@@ -1168,6 +1216,7 @@ armor_filter( void *opaque, int control,
"probably a buggy MTA has been used\n") );
xfree( afx->buffer );
afx->buffer = NULL;
+ release_armor_context (afx);
}
else if( control == IOBUFCTRL_DESC )
*(char**)buf = "armor_filter";