1 /* dearmor.c - Armor utility
2 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
40 * Take an armor file and write it out without armor
43 dearmor_file( const char *fname
)
45 armor_filter_context_t afx
;
46 IOBUF inp
= NULL
, out
= NULL
;
50 memset( &afx
, 0, sizeof afx
);
53 inp
= iobuf_open(fname
);
54 if (inp
&& is_secured_file (iobuf_get_fd (inp
)))
61 log_error(_("can't open `%s': %s\n"), fname
? fname
: "[stdin]",
63 rc
= G10ERR_OPEN_FILE
;
67 iobuf_push_filter( inp
, armor_filter
, &afx
);
69 if( (rc
= open_outfile( fname
, 0, &out
)) )
74 while( (c
= iobuf_get(inp
)) != -1 )
89 * Take file and write it out with armor
92 enarmor_file( const char *fname
)
94 armor_filter_context_t afx
;
95 IOBUF inp
= NULL
, out
= NULL
;
99 memset( &afx
, 0, sizeof afx
);
102 inp
= iobuf_open(fname
);
103 if (inp
&& is_secured_file (iobuf_get_fd (inp
)))
110 log_error(_("can't open `%s': %s\n"), fname
? fname
: "[stdin]",
112 rc
= G10ERR_OPEN_FILE
;
117 if( (rc
= open_outfile( fname
, 1, &out
)) )
121 afx
.hdrlines
= "Comment: Use \"gpg --dearmor\" for unpacking\n";
122 iobuf_push_filter( out
, armor_filter
, &afx
);
124 while( (c
= iobuf_get(inp
)) != -1 )