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 3 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, see <http://www.gnu.org/licenses/>.
38 * Take an armor file and write it out without armor
41 dearmor_file( const char *fname
)
43 armor_filter_context_t
*afx
;
44 IOBUF inp
= NULL
, out
= NULL
;
48 afx
= new_armor_context ();
51 inp
= iobuf_open(fname
);
52 if (inp
&& is_secured_file (iobuf_get_fd (inp
)))
59 rc
= gpg_error_from_syserror ();
60 log_error(_("can't open `%s': %s\n"), fname
? fname
: "[stdin]",
65 push_armor_filter ( afx
, inp
);
67 if( (rc
= open_outfile( fname
, 0, &out
)) )
70 while( (c
= iobuf_get(inp
)) != -1 )
79 release_armor_context (afx
);
85 * Take file and write it out with armor
88 enarmor_file( const char *fname
)
90 armor_filter_context_t
*afx
;
91 IOBUF inp
= NULL
, out
= NULL
;
95 afx
= new_armor_context ();
98 inp
= iobuf_open(fname
);
99 if (inp
&& is_secured_file (iobuf_get_fd (inp
)))
106 rc
= gpg_error_from_syserror ();
107 log_error(_("can't open `%s': %s\n"), fname
? fname
: "[stdin]",
113 if( (rc
= open_outfile( fname
, 1, &out
)) )
117 afx
->hdrlines
= "Comment: Use \"gpg --dearmor\" for unpacking\n";
118 push_armor_filter ( afx
, out
);
120 while( (c
= iobuf_get(inp
)) != -1 )
130 release_armor_context (afx
);