lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.5-12-geef681b

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-pskc branch master updated. 0.5-12-geef681b



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-pskc".

The branch, master has been updated
       via  eef681bfda4692ff5b232d319773482196a5a7ec (commit)
       via  6f78dd6ab7fd0f075cd7c5b48715ad932e4ee092 (commit)
       via  cc3acc2b948b533004310df23080c555a60e4de1 (commit)
      from  0c00c8047d82a226a1a8d2f29968218b1768cbf7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-pskc/commit/?id=eef681bfda4692ff5b232d319773482196a5a7ec

commit eef681bfda4692ff5b232d319773482196a5a7ec
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Wed Sep 20 23:10:25 2017 +0200

    Add --secret-encoding option to pskc2csv
    
    This option can be used to configure the encoding of the secret in the
    CSV file (still hex by default).

diff --git a/pskc2csv.py b/pskc2csv.py
index 4089968..7a7ed32 100755
--- a/pskc2csv.py
+++ b/pskc2csv.py
@@ -22,6 +22,7 @@
 
 from __future__ import print_function
 import argparse
+import base64
 import csv
 import getpass
 import operator
@@ -89,21 +90,23 @@ parser.add_argument(
 parser.add_argument(
     '-s', '--secret', metavar='KEY/FILE',
     help='hex encoded encryption key or file containing the binary key')
+encodings = {
+    'hex': b2a_hex,
+    'base32': base64.b32encode,
+    'base64': base64.b64encode,
+}
+parser.add_argument(
+    '-e', '--secret-encoding', choices=sorted(encodings.keys()),
+    help='encoding used for outputting key material',
+    default='hex')
 
 
-# Python 3 compatible version of b2a_hex
-def decode(f):
-    return lambda x: str(f(x).decode())
-
-
-b2a_hex = decode(b2a_hex)
-
-
-def get_column(key, column):
+def get_column(key, column, encoding):
     """Return a string value for the given column."""
     value = operator.attrgetter(column)(key)
     if column == 'secret':
-        return b2a_hex(value)
+        # Python 3 compatible construct for outputting a string
+        return str(encodings[encoding](value).decode())
     return value
 
 
@@ -149,4 +152,5 @@ if __name__ == '__main__':
         csvfile.writerow(args.columns)
         for key in pskcfile.keys:
             csvfile.writerow([
-                get_column(key, column) for column in args.columns])
+                get_column(key, column, args.secret_encoding)
+                for column in args.columns])

https://arthurdejong.org/git/python-pskc/commit/?id=6f78dd6ab7fd0f075cd7c5b48715ad932e4ee092

commit 6f78dd6ab7fd0f075cd7c5b48715ad932e4ee092
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Wed Sep 20 22:27:31 2017 +0200

    Run flake8 from tox
    
    This also makes a few small code formatting changes to ensure that the
    flake8 tests pass.

diff --git a/pskc/__init__.py b/pskc/__init__.py
index def4a33..3ceaba2 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -86,7 +86,7 @@ class PSKC(object):
 
     @property
     def keys(self):
-        """list of keys"""
+        """Provide a list of keys."""
         return tuple(key for device in self.devices for key in device.keys)
 
     def add_device(self, **kwargs):
diff --git a/pskc/crypto/aeskw.py b/pskc/crypto/aeskw.py
index eeafed1..416d79b 100644
--- a/pskc/crypto/aeskw.py
+++ b/pskc/crypto/aeskw.py
@@ -26,7 +26,7 @@ from Crypto.Cipher import AES
 from Crypto.Util.number import bytes_to_long, long_to_bytes
 from Crypto.Util.strxor import strxor
 
-from pskc.exceptions import EncryptionError, DecryptionError
+from pskc.exceptions import DecryptionError, EncryptionError
 
 
 def _split(value):
diff --git a/pskc/crypto/tripledeskw.py b/pskc/crypto/tripledeskw.py
index a135ebd..0802141 100644
--- a/pskc/crypto/tripledeskw.py
+++ b/pskc/crypto/tripledeskw.py
@@ -26,11 +26,11 @@ from Crypto import Random
 from Crypto.Cipher import DES3
 from Crypto.Hash import SHA
 
-from pskc.exceptions import EncryptionError, DecryptionError
+from pskc.exceptions import DecryptionError, EncryptionError
 
 
 def _cms_hash(value):
-    """The key checksum algorithm described in RFC 3217 section 2."""
+    """Return the key hash algorithm described in RFC 3217 section 2."""
     return SHA.new(value).digest()[:8]
 
 
@@ -42,7 +42,8 @@ def wrap(plaintext, key, iv=None):
 
     This uses the algorithm from RFC 3217 to encrypt the plaintext (the key
     to wrap) using the provided key. If the iv is None, it is randomly
-    generated."""
+    generated.
+    """
     if len(plaintext) % DES3.block_size != 0:
         raise EncryptionError('Plaintext length wrong')
     if iv is None:
@@ -57,7 +58,8 @@ def unwrap(ciphertext, key):
     """Unwrap a key (typically Triple DES key ) with another Triple DES key.
 
     This uses the algorithm from RFC 3217 to decrypt the ciphertext (the
-    previously wrapped key) using the provided key."""
+    previously wrapped key) using the provided key.
+    """
     if len(ciphertext) % DES3.block_size != 0:
         raise DecryptionError('Ciphertext length wrong')
     cipher = DES3.new(key, DES3.MODE_CBC, RFC3217_IV)
diff --git a/pskc/exceptions.py b/pskc/exceptions.py
index 45b0557..e5e4436 100644
--- a/pskc/exceptions.py
+++ b/pskc/exceptions.py
@@ -23,6 +23,7 @@
 
 class PSKCError(Exception):
     """General top-level exception."""
+
     pass
 
 
@@ -30,12 +31,15 @@ class ParseError(PSKCError):
     """Something went wrong with parsing the PSKC file.
 
     Either the file is invalid XML or required elements or attributes are
-    missing."""
+    missing.
+    """
+
     pass
 
 
 class EncryptionError(PSKCError):
     """There was a problem encrypting the value."""
+
     pass
 
 
@@ -43,10 +47,13 @@ class DecryptionError(PSKCError):
     """There was a problem decrypting the value.
 
     The encrypted value as available but something went wrong with decrypting
-    it."""
+    it.
+    """
+
     pass
 
 
 class KeyDerivationError(PSKCError):
     """There was a problem performing the key derivation."""
+
     pass
diff --git a/pskc/mac.py b/pskc/mac.py
index d771b9b..5ac1a92 100644
--- a/pskc/mac.py
+++ b/pskc/mac.py
@@ -92,7 +92,7 @@ class MAC(object):
 
     @property
     def key(self):
-        """Provides access to the MAC key binary value if available."""
+        """Provide access to the MAC key binary value if available."""
         if self.key_plain_value:
             return self.key_plain_value
         elif self.key_cipher_value:
diff --git a/pskc/parser.py b/pskc/parser.py
index a899e82..dd7d01a 100644
--- a/pskc/parser.py
+++ b/pskc/parser.py
@@ -153,8 +153,10 @@ class PSKCParser(object):
             name = data.get('Name')
             if name:
                 cls.parse_datatype(dict(
-                    secret=key._secret, counter=key._counter,
-                    time=key._time_offset, time_interval=key._time_interval
+                    secret=key._secret,
+                    counter=key._counter,
+                    time=key._time_offset,
+                    time_interval=key._time_interval,
                 ).get(name.lower()), data)
 
         key.issuer = findtext(key_elm, 'Issuer')
diff --git a/pskc/policy.py b/pskc/policy.py
index 09ea13b..62c6519 100644
--- a/pskc/policy.py
+++ b/pskc/policy.py
@@ -136,7 +136,7 @@ class Policy(object):
 
     @property
     def pin_key(self):
-        """Reference to the PSKC Key that holds the PIN (if any)."""
+        """Provide the PSKC Key that holds the PIN (if any)."""
         if self.pin_key_id and self.key and self.key.device.pskc:
             for key in self.key.device.pskc.keys:
                 if key.id == self.pin_key_id:
@@ -144,7 +144,7 @@ class Policy(object):
 
     @property
     def pin(self):
-        """PIN value referenced by PINKeyId if any."""
+        """Provide the PIN value referenced by PINKeyId if any."""
         key = self.pin_key
         if key:
             return str(key.secret.decode())
diff --git a/pskc/serialiser.py b/pskc/serialiser.py
index 57eccf2..3aa1a26 100644
--- a/pskc/serialiser.py
+++ b/pskc/serialiser.py
@@ -192,8 +192,7 @@ class PSKCSerialiser(object):
                     dt.value_mac).decode())
             elif dt.pskc.mac.algorithm:
                 mk_elem(element, 'pskc:ValueMAC', base64.b64encode(
-                    dt.pskc.mac.generate_mac(dt.cipher_value)
-                ).decode())
+                    dt.pskc.mac.generate_mac(dt.cipher_value)).decode())
         else:
             mk_elem(element, 'pskc:PlainValue', dt._to_text(dt.value))
 
diff --git a/setup.cfg b/setup.cfg
index d702dfb..9690303 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -17,3 +17,8 @@ cover-min-percentage=100
 
 [build_sphinx]
 all_files  = 1
+
+[flake8]
+ignore = D101,D102,D105,D202,D205,D209,D400,N806
+max-complexity = 12
+max-line-length = 78
diff --git a/tox.ini b/tox.ini
index 076ea63..c5c4383 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py{27,34,35,36}{,-lxml}
+envlist = py{27,34,35,36}{,-lxml},flake8
 skip_missing_interpreters = True
 
 [testenv]
@@ -11,3 +11,22 @@ deps = nose
 commands = nosetests
 setenv=
     PYTHONWARNINGS=all
+
+[testenv:flake8]
+skip_install = true
+deps = flake8
+       flake8-author
+       flake8-blind-except
+       py{35,36}: flake8-bugbear
+       flake8-class-newline
+       flake8-commas
+       flake8-deprecated
+       flake8-docstrings
+       flake8-exact-pin
+       flake8-import-order
+       flake8-print
+       flake8-quotes
+       flake8-tidy-imports
+       flake8-tuple
+       pep8-naming
+commands = flake8 pskc *.py

https://arthurdejong.org/git/python-pskc/commit/?id=cc3acc2b948b533004310df23080c555a60e4de1

commit cc3acc2b948b533004310df23080c555a60e4de1
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Sep 11 21:56:51 2017 +0200

    Simplify Tox configuration

diff --git a/tox.ini b/tox.ini
index a8a8204..076ea63 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,31 +1,13 @@
 [tox]
-envlist = {py27,py34,py35,py36,py27-lxml,py34-lxml,py35-lxml,py36-lxml}
+envlist = py{27,34,35,36}{,-lxml}
+skip_missing_interpreters = True
 
 [testenv]
 deps = nose
        coverage
        pycrypto
        python-dateutil
+       lxml: lxml
 commands = nosetests
 setenv=
     PYTHONWARNINGS=all
-
-[testenv:py27-lxml]
-basepython = python2.7
-deps = {[testenv]deps}
-       lxml
-
-[testenv:py34-lxml]
-basepython = python3.4
-deps = {[testenv]deps}
-       lxml
-
-[testenv:py35-lxml]
-basepython = python3.5
-deps = {[testenv]deps}
-       lxml
-
-[testenv:py36-lxml]
-basepython = python3.6
-deps = {[testenv]deps}
-       lxml

-----------------------------------------------------------------------

Summary of changes:
 pskc/__init__.py           |  2 +-
 pskc/crypto/aeskw.py       |  2 +-
 pskc/crypto/tripledeskw.py | 10 ++++++----
 pskc/exceptions.py         | 11 +++++++++--
 pskc/mac.py                |  2 +-
 pskc/parser.py             |  6 ++++--
 pskc/policy.py             |  4 ++--
 pskc/serialiser.py         |  3 +--
 pskc2csv.py                | 26 +++++++++++++++-----------
 setup.cfg                  |  5 +++++
 tox.ini                    | 41 +++++++++++++++++++++--------------------
 11 files changed, 66 insertions(+), 46 deletions(-)


hooks/post-receive
-- 
python-pskc
-- 
To unsubscribe send an email to
python-pskc-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-pskc-commits/