2 # -*- coding: utf-8 -*-
4 from __future__ import absolute_import, division, unicode_literals
6 # Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
8 # This program is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # This program is free software; you can redistribute it and/or modify it under
14 # the terms of the GNU Lesser General Public License as published by the Free
15 # Software Foundation; either version 2.1 of the License, or (at your option)
18 # This program is distributed in the hope that it will be useful, but WITHOUT
19 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 # FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
21 # Lesser General Public License for more details.
23 # You should have received a copy of the GNU General Public License and the GNU
24 # Lesser General Public along with this program; if not, see
25 # <http://www.gnu.org/licenses/>.
31 Clear-signs a file with a specified key. If entering both the key and the
32 filename on the command line, the key must be entered first.
37 filename = " ".join(sys.argv[2:])
38 elif len(sys.argv) == 3:
40 filename = sys.argv[2]
41 elif len(sys.argv) == 2:
43 filename = input("Enter the path and filename to sign: ")
45 logrus = input("Enter the fingerprint or key ID to sign with: ")
46 filename = input("Enter the path and filename to sign: ")
48 with open(filename, "rb") as f:
51 key = list(gpg.Context().keylist(pattern=logrus))
53 with gpg.Context(armor=True, signers=key) as c:
54 signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
55 with open("{0}.asc".format(filename), "wb") as f: