From a359bac196c309a2375de99eb91611a9ee0da386 Mon Sep 17 00:00:00 2001 From: Kouhei Maeda Date: Fri, 23 May 2014 19:20:35 +0900 Subject: [PATCH] Added is_signed(), parse_changes(), verify_signature(). Signed-off-by: Kouhei Maeda --- pydebsign/debsign.py | 14 +++++++++++--- requirements.txt | 1 + setup.py | 3 ++- tox.ini | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pydebsign/debsign.py b/pydebsign/debsign.py index 8d8ba86..7868ccb 100644 --- a/pydebsign/debsign.py +++ b/pydebsign/debsign.py @@ -12,6 +12,7 @@ """ import hashlib import gnupg +import deb822 class Debsign(object): @@ -24,14 +25,20 @@ def is_signed(self, file_path): Returns: `bool` True is signed, False is unsigned. :param file_path: expecting .dsc file or .changes file. """ - pass + with open(file_path, 'rb') as fileobj: + if self.gpg.verify(fileobj.read()).status is None: + return False + else: + return True def parse_changes(self, changes_path): """ parse .changes and retrieve efile size and file name list. Returns: file list with file size and checksums. :param changes_path: .changes file path """ - pass + with open(changes_path, 'rb') as fileobj: + changes = deb822.Changes(fileobj) + return [_file for _file in changes['Files']] def retrieve_dsc_path(self, file_list): """ retrieve dsc file path from file list. @@ -103,7 +110,8 @@ def verify_signature(self, file_path): Returns: `bool` True is valid, False is invalid :param file_path: expecting .dsc file path or .changes file path """ - pass + with open(file_path) as fileobj: + return self.gpg.verify(fileobj.read()).valid def verify_with_dput(self, changes_path): """ verify .changes and .dsc files with `dput` command. diff --git a/requirements.txt b/requirements.txt index e18f74f..75b7bf1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ python_gnupg +python_debian diff --git a/setup.py b/setup.py index e36495a..510ee40 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,8 @@ def run_tests(self): open(os.path.join("docs", "TODO.rst")).read()) requires = ['setuptools', - 'python_gnupg'] + 'python_gnupg', + 'python_debian'] setup(name='pydebsign', version='0.1.0', diff --git a/tox.ini b/tox.ini index b73dd04..fb7f16a 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ commands = [py] deps= python_gnupg + python_debian pep8 coverage pytest