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 <https://www.gnu.org/licenses/>.
37 * Take an armor file and write it out without armor
40 dearmor_file( const char *fname )
42 armor_filter_context_t *afx;
43 IOBUF inp = NULL, out = NULL;
47 afx = new_armor_context ();
50 inp = iobuf_open(fname);
51 if (inp && is_secured_file (iobuf_get_fd (inp)))
55 gpg_err_set_errno (EPERM);
58 rc = gpg_error_from_syserror ();
59 log_error(_("can't open '%s': %s\n"), fname? fname: "[stdin]",
64 push_armor_filter ( afx, inp );
66 if( (rc = open_outfile (-1, fname, 0, 0, &out)) )
69 while( (c = iobuf_get(inp)) != -1 )
78 release_armor_context (afx);
84 * Take file and write it out with armor
87 enarmor_file( const char *fname )
89 armor_filter_context_t *afx;
90 IOBUF inp = NULL, out = NULL;
94 afx = new_armor_context ();
97 inp = iobuf_open(fname);
98 if (inp && is_secured_file (iobuf_get_fd (inp)))
102 gpg_err_set_errno (EPERM);
105 rc = gpg_error_from_syserror ();
106 log_error(_("can't open '%s': %s\n"), fname? fname: "[stdin]",
112 if( (rc = open_outfile (-1, fname, 1, 0, &out )) )
116 afx->hdrlines = "Comment: Use \"gpg --dearmor\" for unpacking\n";
117 push_armor_filter ( afx, out );
119 while( (c = iobuf_get(inp)) != -1 )
129 release_armor_context (afx);