Coverage for pass_import/decrypters/gpg.py: 100%
14 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
1# -*- encoding: utf-8 -*-
2# pass import - Passwords importer swiss army knife
3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>.
4#
6import shutil
7from subprocess import PIPE, Popen # nosec
9from pass_import.core import register_detecters
10from pass_import.detecter import Decrypter
11from pass_import.errors import FormatError
14class GPG(Decrypter):
15 """Decrypter for GPG."""
16 format = 'gpg'
18 def decrypt(self):
19 """Import data is GPG encrypted, let's decrypt it."""
20 gpgbinary = shutil.which('gpg2') or shutil.which('gpg')
21 cmd = [gpgbinary, '--with-colons', '--batch', '--decrypt', self.prefix]
22 with Popen(cmd, shell=False, universal_newlines=False,
23 stdin=PIPE, stdout=PIPE, stderr=PIPE) as process:
24 (stdout, stderr) = process.communicate()
25 if process.wait(): # pragma: no cover
26 raise FormatError(f"{stderr} {stdout}")
27 return stdout.decode()[:-1]
30register_detecters(GPG)