lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.4-17-g02b30a9

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

python-pskc branch master updated. 0.4-17-g02b30a9



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  02b30a9ccb717e4efa5d1366b7e55a8d8e66c2c6 (commit)
       via  b1f8f870c9f751d7910e18d929f3753c521c654c (commit)
      from  e23a4674c960f09af8cac28f3cbe876f2bc496fc (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 -----------------------------------------------------------------
http://arthurdejong.org/git/python-pskc/commit/?id=02b30a9ccb717e4efa5d1366b7e55a8d8e66c2c6

commit 02b30a9ccb717e4efa5d1366b7e55a8d8e66c2c6
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Sep 19 18:41:40 2016 +0200

    Also move outer writing and parsing to modules

diff --git a/pskc/__init__.py b/pskc/__init__.py
index 53f63ff..1916cda 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -79,15 +79,8 @@ class PSKC(object):
         self.mac = MAC(self)
         self.devices = []
         if filename is not None:
-            from pskc.exceptions import ParseError
             from pskc.parser import PSKCParser
-            from pskc.xml import parse, remove_namespaces
-            try:
-                tree = parse(filename)
-            except Exception:
-                raise ParseError('Error parsing XML')
-            remove_namespaces(tree)
-            PSKCParser.parse_document(self, tree.getroot())
+            PSKCParser.parse_file(self, filename)
         else:
             self.version = '1.0'
 
@@ -126,15 +119,9 @@ class PSKC(object):
 
     def write(self, filename):
         """Write the PSKC file to the provided file."""
-        from pskc.xml import tostring
         from pskc.serialiser import PSKCSerialiser
         if hasattr(filename, 'write'):
-            xml = tostring(PSKCSerialiser.serialise_document(self))
-            try:
-                filename.write(xml)
-            except TypeError:  # pragma: no cover (Python 3 specific)
-                # fall back to writing as string for Python 3
-                filename.write(xml.decode('utf-8'))
+            PSKCSerialiser.serialise_file(self, filename)
         else:
             with open(filename, 'wb') as output:
                 self.write(output)
diff --git a/pskc/parser.py b/pskc/parser.py
index 98bfeef..a5dac2a 100644
--- a/pskc/parser.py
+++ b/pskc/parser.py
@@ -24,12 +24,22 @@
 from pskc.algorithms import normalise_algorithm
 from pskc.exceptions import ParseError
 from pskc.xml import (
-    find, findall, findtext, findint, findbin, findtime, getint, getbool)
+    find, findall, findbin, findint, findtext, findtime, getbool, getint,
+    parse, remove_namespaces)
 
 
 class PSKCParser(object):
 
     @classmethod
+    def parse_file(cls, pskc, filename):
+        try:
+            tree = parse(filename)
+        except Exception:
+            raise ParseError('Error parsing XML')
+        remove_namespaces(tree)
+        cls.parse_document(pskc, tree.getroot())
+
+    @classmethod
     def parse_document(cls, pskc, container):
         """Read information from the provided <KeyContainer> tree."""
         if container.tag != 'KeyContainer':
diff --git a/pskc/serialiser.py b/pskc/serialiser.py
index 5542be0..4df8046 100644
--- a/pskc/serialiser.py
+++ b/pskc/serialiser.py
@@ -23,12 +23,21 @@
 
 import base64
 
-from pskc.xml import find, mk_elem
+from pskc.xml import find, mk_elem, tostring
 
 
 class PSKCSerialiser(object):
 
     @classmethod
+    def serialise_file(cls, pskc, output):
+        xml = tostring(cls.serialise_document(pskc))
+        try:
+            output.write(xml)
+        except TypeError:  # pragma: no cover (Python 3 specific)
+            # fall back to writing as string for Python 3
+            output.write(xml.decode('utf-8'))
+
+    @classmethod
     def serialise_document(cls, pskc):
         container = mk_elem('pskc:KeyContainer', Version=pskc.version,
                             Id=pskc.id)

http://arthurdejong.org/git/python-pskc/commit/?id=b1f8f870c9f751d7910e18d929f3753c521c654c

commit b1f8f870c9f751d7910e18d929f3753c521c654c
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Sep 17 16:59:43 2016 +0200

    Add writing example to toplevel documentation

diff --git a/.gitignore b/.gitignore
index 4883d7f..919b186 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ __pycache__
 /build
 /coverage
 /dist
+/output.pskcxml
diff --git a/README b/README
index d52ded3..aa5956a 100644
--- a/README
+++ b/README
@@ -19,7 +19,7 @@ API
 The module provides a straightforward API that is mostly geared towards
 parsing existing PSKC files.
 
-Extracting key material from encrypted PSKC files is as simple as.
+Extracting key material from encrypted PSKC files is as simple as:
 
 >>> from pskc import PSKC
 >>> pskc = PSKC('tests/rfc6030/figure7.pskcxml')
@@ -28,6 +28,15 @@ Extracting key material from encrypted PSKC files is as 
simple as.
 ...     print key.serial, key.secret
 987654321 12345678901234567890
 
+Writing am encrypted PSKC file is as simple as:
+
+>>> pskc = PSKC()
+>>> key = pskc.add_key(
+...     id='456', secret='987654321', manufacturer='Manufacturer',
+...     algorithm = 'urn:ietf:params:xml:ns:keyprov:pskc:hotp')
+>>> pskc.encryption.setup_pbkdf2('passphrase')
+>>> pskc.write('output.pskcxml')
+
 The key object has a number of properties. See the pskc.key.Key documentation
 for details.
 
diff --git a/pskc/__init__.py b/pskc/__init__.py
index a99a4a5..53f63ff 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -37,6 +37,15 @@ The following prints all keys, decrypting using a password:
 ...     print('%s %s' % (key.serial, str(key.secret.decode())))
 987654321 12345678901234567890
 
+The following generates an encrypted PSKC file:
+
+>>> pskc = PSKC()
+>>> key = pskc.add_key(
+...     id='456', secret='987654321', manufacturer='Manufacturer',
+...     algorithm = 'urn:ietf:params:xml:ns:keyprov:pskc:hotp')
+>>> pskc.encryption.setup_pbkdf2('passphrase')
+>>> pskc.write('output.pskcxml')
+
 The module should be able to handle most common PSKC files.
 """
 

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

Summary of changes:
 .gitignore         |  1 +
 README             | 11 ++++++++++-
 pskc/__init__.py   | 26 +++++++++++---------------
 pskc/parser.py     | 12 +++++++++++-
 pskc/serialiser.py | 11 ++++++++++-
 5 files changed, 43 insertions(+), 18 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/