lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.2-8-g1363564

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

python-pskc branch master updated. 0.2-8-g1363564



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  13635648b47e500d3c1649d994bac2485fc10dee (commit)
       via  e468ebe48719e29203214e8c7ee5886f36b1eace (commit)
      from  480e2d0efeba8fb916b9d4e96a196786e59acad8 (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=13635648b47e500d3c1649d994bac2485fc10dee

commit 13635648b47e500d3c1649d994bac2485fc10dee
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Jun 30 23:36:40 2014 +0200

    Move encryption functions in pskc.crypto package
    
    This moves the encryption functions under the pskc.crypto package to
    more clearly separate it from the other code. Ideally this should be
    replaced by third-party library code.

diff --git a/pskc/crypto/__init__.py b/pskc/crypto/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pskc/aeskw.py b/pskc/crypto/aeskw.py
similarity index 100%
rename from pskc/aeskw.py
rename to pskc/crypto/aeskw.py
diff --git a/pskc/tripledeskw.py b/pskc/crypto/tripledeskw.py
similarity index 100%
rename from pskc/tripledeskw.py
rename to pskc/crypto/tripledeskw.py
diff --git a/pskc/encryption.py b/pskc/encryption.py
index f4ccb2a..fec4166 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -92,14 +92,14 @@ class EncryptedValue(object):
         elif self.algorithm.endswith('#kw-aes128') or \
                 self.algorithm.endswith('#kw-aes192') or \
                 self.algorithm.endswith('#kw-aes256'):
-            from pskc.aeskw import unwrap
+            from pskc.crypto.aeskw import unwrap
             from Crypto.Cipher import AES
             if len(key) * 8 != int(self.algorithm[-3:]) or \
                len(key) not in AES.key_size:
                 raise DecryptionError('Invalid key length')
             return unwrap(self.cipher_value, key)
         elif self.algorithm.endswith('#kw-tripledes'):
-            from pskc.tripledeskw import unwrap
+            from pskc.crypto.tripledeskw import unwrap
             from Crypto.Cipher import DES3
             if len(key) not in DES3.key_size:
                 raise DecryptionError('Invalid key length')
diff --git a/tests/test_aeskw.doctest b/tests/test_aeskw.doctest
index ad3a0f9..2d9cbd7 100644
--- a/tests/test_aeskw.doctest
+++ b/tests/test_aeskw.doctest
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 
 
->>> from pskc.aeskw import wrap, unwrap
+>>> from pskc.crypto.aeskw import wrap, unwrap
 
 
 Wrap 128 bits of Key Data with a 128-bit KEK (test vector 4.1 from RFC 3394).
diff --git a/tests/test_tripledeskw.doctest b/tests/test_tripledeskw.doctest
index 6f7629a..6f2760b 100644
--- a/tests/test_tripledeskw.doctest
+++ b/tests/test_tripledeskw.doctest
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 
 >>> import re
->>> from pskc.tripledeskw import wrap, unwrap
+>>> from pskc.crypto.tripledeskw import wrap, unwrap
 >>> def fromhex(value):
 ...     return re.sub(r'\s', '', value).decode('hex')
 

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

commit e468ebe48719e29203214e8c7ee5886f36b1eace
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Jun 30 23:25:59 2014 +0200

    Rename pskc.parse to pskc.xml
    
    This renames the parse module to xml to better reflect the purpose of
    the module and it's functions.
    
    This also introduces a parse() function that wraps etree.parse().

diff --git a/pskc/__init__.py b/pskc/__init__.py
index 7c9e2da..6edef85 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -72,9 +72,9 @@ class PSKC(object):
         self.mac = MAC(self)
         self.keys = []
         if filename is not None:
-            from pskc.parse import etree
+            from pskc.xml import parse
             try:
-                tree = etree.parse(filename)
+                tree = parse(filename)
             except Exception:
                 raise ParseError('Error parsing XML')
             self.parse(tree.getroot())
@@ -85,7 +85,7 @@ class PSKC(object):
         """Read information from the provided <KeyContainer> tree."""
         from pskc.exceptions import ParseError
         from pskc.key import Key
-        from pskc.parse import find, findall
+        from pskc.xml import find, findall
         if not container.tag.endswith('KeyContainer'):
             raise ParseError('Missing KeyContainer')
         # the version of the PSKC schema
@@ -103,7 +103,7 @@ class PSKC(object):
             self.keys.append(Key(self, key_package))
 
     def make_xml(self):
-        from pskc.parse import mk_elem
+        from pskc.xml import mk_elem
         container = mk_elem('pskc:KeyContainer', Version=self.version,
                             Id=self.id)
         for key in self.keys:
@@ -127,7 +127,7 @@ class PSKC(object):
 
     def write(self, filename):
         """Write the PSKC file to the provided file."""
-        from pskc.parse import tostring
+        from pskc.xml import tostring
         if hasattr(filename, 'write'):
             filename.write(tostring(self.make_xml()))
         else:
diff --git a/pskc/encryption.py b/pskc/encryption.py
index b57053c..f4ccb2a 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -51,7 +51,7 @@ class EncryptedValue(object):
 
     def parse(self, encrypted_value):
         """Read encrypted data from the <EncryptedValue> XML tree."""
-        from pskc.parse import find, findbin
+        from pskc.xml import find, findbin
         if encrypted_value is None:
             return
         encryption_method = find(encrypted_value, 'xenc:EncryptionMethod')
@@ -131,7 +131,7 @@ class KeyDerivation(object):
 
     def parse(self, key_deriviation):
         """Read derivation parameters from a <KeyDerivationMethod> element."""
-        from pskc.parse import find, findint, findbin
+        from pskc.xml import find, findint, findbin
         if key_deriviation is None:
             return
         self.algorithm = key_deriviation.get('Algorithm')
@@ -199,7 +199,7 @@ class Encryption(object):
 
     def parse(self, key_info):
         """Read encryption information from the <EncryptionKey> XML tree."""
-        from pskc.parse import find, findall, findtext
+        from pskc.xml import find, findall, findtext
         if key_info is None:
             return
         self.id = key_info.get('Id')
diff --git a/pskc/key.py b/pskc/key.py
index 1814a48..9e29e2e 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -51,7 +51,7 @@ class DataType(object):
         The element is expected to contain <PlainValue>, <EncryptedValue>
         and/or ValueMAC elements that contain information on the actual
         value."""
-        from pskc.parse import find, findtext
+        from pskc.xml import find, findtext
         if element is None:
             return
         value = findtext(element, 'pskc:PlainValue')
@@ -61,7 +61,7 @@ class DataType(object):
         self.value_mac.parse(find(element, 'pskc:ValueMAC'))
 
     def make_xml(self, key, tag):
-        from pskc.parse import find, mk_elem
+        from pskc.xml import find, mk_elem
         # skip empty values
         value = self.get_value()
         if value is None:
@@ -212,7 +212,7 @@ class Key(object):
 
     def parse(self, key_package):
         """Read key information from the provided <KeyPackage> tree."""
-        from pskc.parse import find, findtext, findtime, getint, getbool
+        from pskc.xml import find, findtext, findtime, getint, getbool
         if key_package is None:
             return
 
@@ -278,7 +278,7 @@ class Key(object):
         self.policy.parse(find(key_package, 'pskc:Key/pskc:Policy'))
 
     def make_xml(self, container):
-        from pskc.parse import mk_elem
+        from pskc.xml import mk_elem
 
         key_package = mk_elem(container, 'pskc:KeyPackage', empty=True)
 
diff --git a/pskc/mac.py b/pskc/mac.py
index 7e66d6e..961c934 100644
--- a/pskc/mac.py
+++ b/pskc/mac.py
@@ -57,7 +57,7 @@ class ValueMAC(object):
 
     def parse(self, value_mac):
         """Read MAC information from the <ValueMAC> XML tree."""
-        from pskc.parse import findbin
+        from pskc.xml import findbin
         if value_mac is None:
             return
         self._value_mac = findbin(value_mac, '.')
@@ -100,7 +100,7 @@ class MAC(object):
 
     def parse(self, mac_method):
         """Read MAC information from the <MACMethod> XML tree."""
-        from pskc.parse import find, findtext
+        from pskc.xml import find, findtext
         if mac_method is None:
             return
         self.algorithm = mac_method.get('Algorithm')
diff --git a/pskc/policy.py b/pskc/policy.py
index f1d976c..4f0c64c 100644
--- a/pskc/policy.py
+++ b/pskc/policy.py
@@ -109,7 +109,7 @@ class Policy(object):
 
     def parse(self, policy):
         """Read key policy information from the provided <Policy> tree."""
-        from pskc.parse import (
+        from pskc.xml import (
             find, findall, findtext, findint, findtime, getint)
         if policy is None:
             return
@@ -137,7 +137,7 @@ class Policy(object):
         # policy rejects any key usage (set unknown_policy_elements)
 
     def make_xml(self, key):
-        from pskc.parse import mk_elem
+        from pskc.xml import mk_elem
         # check if any policy attribute is set
         if not self.key_usage and all(x is None for x in (
                 self.start_date, self.expiry_date,
diff --git a/pskc/parse.py b/pskc/xml.py
similarity index 93%
rename from pskc/parse.py
rename to pskc/xml.py
index 98839ad..539870b 100644
--- a/pskc/parse.py
+++ b/pskc/xml.py
@@ -1,4 +1,4 @@
-# parse.py - module for reading PSKC files
+# xml.py - module for parsing and writing XML for PSKC files
 # coding: utf-8
 #
 # Copyright (C) 2014 Arthur de Jong
@@ -18,11 +18,13 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""Module for parsing PSKC files.
+"""Module for parsing XML in PSKC files.
 
-This module provides some utility functions for parsing PSKC files.
+This module provides some utility functions for parsing XML files.
 """
 
+from __future__ import absolute_import
+
 # try to find a usable ElementTree module
 try:
     from lxml import etree
@@ -50,6 +52,11 @@ for ns, namespace in namespaces.items():
     etree.register_namespace(ns, namespace)
 
 
+def parse(source):
+    """Parse the provided file and return an element tree."""
+    return etree.parse(source)
+
+
 def findall(tree, match):
     """Find a child element (or None)."""
     return tree.findall(match, namespaces=namespaces)

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

Summary of changes:
 pskc/__init__.py                 |   10 +++++-----
 pskc/{ => crypto}/aeskw.py       |    0
 pskc/{ => crypto}/tripledeskw.py |    0
 pskc/encryption.py               |   10 +++++-----
 pskc/key.py                      |    8 ++++----
 pskc/mac.py                      |    4 ++--
 pskc/policy.py                   |    4 ++--
 pskc/{parse.py => xml.py}        |   13 ++++++++++---
 tests/test_aeskw.doctest         |    2 +-
 tests/test_tripledeskw.doctest   |    2 +-
 10 files changed, 30 insertions(+), 23 deletions(-)
 create mode 100644 pskc/crypto/__init__.py
 rename pskc/{ => crypto}/aeskw.py (100%)
 rename pskc/{ => crypto}/tripledeskw.py (100%)
 rename pskc/{parse.py => xml.py} (93%)


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