lists.arthurdejong.org
RSS feed

python-pskc branch master updated. 0.1-33-g566e447

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

python-pskc branch master updated. 0.1-33-g566e447



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  566e4477f40f632205d572e57394d712e7d55f63 (commit)
       via  5d60ee2f83791da436d80d5aee23b688847a4470 (commit)
       via  6a34c01a777b92ccc64b094361dd75c8e8feb2d1 (commit)
      from  4d92b937bddea136a709bb29b66a2ce6fe0ac943 (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=566e4477f40f632205d572e57394d712e7d55f63

commit 566e4477f40f632205d572e57394d712e7d55f63
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Jun 14 12:19:17 2014 +0200

    Support various ElementTree implementations
    
    When using a recent enough lxml, even Python 2.6 should work now. The
    most important requirement is that the findall() function supports the
    namespaces argument.
    
    This also now catches all exceptions when parsing the PSKC file fails
    and wraps it in ParseError because various implementations raise
    different exceptions, even between versions (Python 2.6's ElementTree
    raises ExpatError, lxml raises XMLSyntaxError).

diff --git a/pskc/__init__.py b/pskc/__init__.py
index 356f50e..f7ae2c2 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -65,7 +65,6 @@ class PSKC(object):
     """
 
     def __init__(self, filename=None):
-        from xml.etree import ElementTree
         from pskc.encryption import Encryption
         from pskc.exceptions import ParseError
         from pskc.mac import MAC
@@ -75,9 +74,10 @@ class PSKC(object):
         self.mac = MAC(self)
         self.keys = []
         if filename is not None:
+            from pskc.parse import etree
             try:
-                tree = ElementTree.parse(filename)
-            except ElementTree.ParseError:
+                tree = etree.parse(filename)
+            except:
                 raise ParseError('Error parsing XML')
             self.parse(tree.getroot())
         else:
diff --git a/pskc/parse.py b/pskc/parse.py
index 7157fbb..b35b507 100644
--- a/pskc/parse.py
+++ b/pskc/parse.py
@@ -23,6 +23,21 @@
 This module provides some utility functions for parsing PSKC files.
 """
 
+# try to find a usable ElementTree module
+try:
+    from lxml import etree
+except ImportError:  # pragma: no cover (different implementations)
+    try:
+        import xml.etree.cElementTree as etree
+    except ImportError:
+        try:
+            import xml.etree.ElementTree as etree
+        except ImportError:
+            try:
+                import cElementTree as etree
+            except ImportError:
+                import elementtree.ElementTree as etree
+
 
 # the relevant XML namespaces for PSKC
 namespaces = dict(
diff --git a/setup.py b/setup.py
index 7547058..716288d 100755
--- a/setup.py
+++ b/setup.py
@@ -49,6 +49,7 @@ setup(
         'Operating System :: OS Independent',
         'Programming Language :: Python',
         'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
         'Topic :: Software Development :: Libraries :: Python Modules',
     ],

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

commit 5d60ee2f83791da436d80d5aee23b688847a4470
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Jun 13 21:28:09 2014 +0200

    Have parse module provide find() functions
    
    This changes the parse module functions to better match the ElementTree
    API and extends it with findint(), findtime() and findbin().
    
    It also passes the namespaces to all calls that require it without
    duplicating this throughout the normal code.

diff --git a/pskc/__init__.py b/pskc/__init__.py
index 9604d8a..356f50e 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -87,7 +87,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 namespaces
+        from pskc.parse import find, findall
         if not container.tag.endswith('KeyContainer'):
             raise ParseError('Missing KeyContainer')
         # the version of the PSKC schema
@@ -97,14 +97,11 @@ class PSKC(object):
         # unique identifier for the container
         self.id = container.get('Id')
         # handle EncryptionKey entries
-        self.encryption.parse(container.find(
-            'pskc:EncryptionKey', namespaces=namespaces))
+        self.encryption.parse(find(container, 'pskc:EncryptionKey'))
         # handle MACMethod entries
-        self.mac.parse(container.find(
-            'pskc:MACMethod', namespaces=namespaces))
+        self.mac.parse(find(container, 'pskc:MACMethod'))
         # handle KeyPackage entries
-        for key_package in container.findall(
-                'pskc:KeyPackage', namespaces=namespaces):
+        for key_package in findall(container, 'pskc:KeyPackage'):
             self.keys.append(Key(self, key_package))
 
     def add_key(self, **kwargs):
diff --git a/pskc/encryption.py b/pskc/encryption.py
index cc91f7c..518e8f5 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -28,9 +28,6 @@ The encryption key can be derived using the KeyDerivation 
class.
 """
 
 
-import base64
-
-
 def unpad(value):
     """Remove padding from the plaintext."""
     return value[0:-ord(value[-1])]
@@ -54,15 +51,13 @@ class EncryptedValue(object):
 
     def parse(self, encrypted_value):
         """Read encrypted data from the <EncryptedValue> XML tree."""
-        from pskc.parse import g_e_v, namespaces
+        from pskc.parse import find, findbin
         if encrypted_value is None:
             return
-        encryption_method = encrypted_value.find(
-            'xenc:EncryptionMethod', namespaces=namespaces)
+        encryption_method = find(encrypted_value, 'xenc:EncryptionMethod')
         self.algorithm = encryption_method.get('Algorithm')
-        value = g_e_v(encrypted_value, 'xenc:CipherData/xenc:CipherValue')
-        if value is not None:
-            self.cipher_value = base64.b64decode(value)
+        self.cipher_value = findbin(
+            encrypted_value, 'xenc:CipherData/xenc:CipherValue')
 
     def decrypt(self):
         """Decrypt the linked value and return the plaintext value."""
@@ -135,27 +130,23 @@ class KeyDerivation(object):
 
     def parse(self, key_deriviation):
         """Read derivation parameters from a <KeyDerivationMethod> element."""
-        from pskc.parse import g_e_v, g_e_i, namespaces
+        from pskc.parse import find, findint, findbin
         if key_deriviation is None:
             return
         self.algorithm = key_deriviation.get('Algorithm')
         # PBKDF2 properties
-        pbkdf2 = key_deriviation.find(
-            'xenc11:PBKDF2-params', namespaces=namespaces)
+        pbkdf2 = find(key_deriviation, 'xenc11:PBKDF2-params')
         if pbkdf2 is None:
-            pbkdf2 = key_deriviation.find(
-                'pkcs5:PBKDF2-params', namespaces=namespaces)
+            pbkdf2 = find(key_deriviation, 'pkcs5:PBKDF2-params')
         if pbkdf2 is not None:
             # get used salt
-            value = g_e_v(pbkdf2, 'Salt/Specified')
-            if value is not None:
-                self.pbkdf2_salt = base64.b64decode(value)
+            self.pbkdf2_salt = findbin(pbkdf2, 'Salt/Specified')
             # required number of iterations
-            self.pbkdf2_iterations = g_e_i(pbkdf2, 'IterationCount')
+            self.pbkdf2_iterations = findint(pbkdf2, 'IterationCount')
             # key length
-            self.pbkdf2_key_length = g_e_i(pbkdf2, 'KeyLength')
+            self.pbkdf2_key_length = findint(pbkdf2, 'KeyLength')
             # pseudorandom function used
-            prf = pbkdf2.find('PRF', namespaces=namespaces)
+            prf = find(pbkdf2, 'PRF')
             if prf is not None:
                 self.pbkdf2_prf = prf.get('Algorithm')
 
@@ -203,19 +194,17 @@ class Encryption(object):
 
     def parse(self, key_info):
         """Read encryption information from the <EncryptionKey> XML tree."""
-        from pskc.parse import g_e_v, namespaces
+        from pskc.parse import find, findall, findtext
         if key_info is None:
             return
         self.id = key_info.get('Id')
-        for name in key_info.findall('ds:KeyName', namespaces=namespaces):
-            self.key_names.append(g_e_v(name, '.'))
-        for name in key_info.findall(
-                'xenc11:DerivedKey/xenc11:MasterKeyName',
-                namespaces=namespaces):
-            self.key_names.append(g_e_v(name, '.'))
-        self.derivation.parse(key_info.find(
-            'xenc11:DerivedKey/xenc11:KeyDerivationMethod',
-            namespaces=namespaces))
+        for name in findall(key_info, 'ds:KeyName'):
+            self.key_names.append(findtext(name, '.'))
+        for name in findall(
+                key_info, 'xenc11:DerivedKey/xenc11:MasterKeyName'):
+            self.key_names.append(findtext(name, '.'))
+        self.derivation.parse(find(
+            key_info, 'xenc11:DerivedKey/xenc11:KeyDerivationMethod'))
 
     @property
     def key_name(self):
diff --git a/pskc/key.py b/pskc/key.py
index cd12213..444ef42 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -52,14 +52,12 @@ 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 g_e_v, namespaces
+        from pskc.parse import find, findtext
         if element is None:
             return
-        self.plain_value = g_e_v(element, 'pskc:PlainValue')
-        self.encrypted_value.parse(element.find(
-            'pskc:EncryptedValue', namespaces=namespaces))
-        self.value_mac.parse(element.find(
-            'pskc:ValueMAC', namespaces=namespaces))
+        self.plain_value = findtext(element, 'pskc:PlainValue')
+        self.encrypted_value.parse(find(element, 'pskc:EncryptedValue'))
+        self.value_mac.parse(find(element, 'pskc:ValueMAC'))
 
     def check(self):
         """Check whether the embedded MAC is correct."""
@@ -183,56 +181,55 @@ class Key(object):
 
     def parse(self, key_package):
         """Read key information from the provided <KeyPackage> tree."""
-        from pskc.parse import g_e_v, g_e_d, namespaces
+        from pskc.parse import find, findtext, findtime
         if key_package is None:
             return
 
-        key = key_package.find('pskc:Key', namespaces=namespaces)
+        key = find(key_package, 'pskc:Key')
         if key is not None:
             self.id = key.get('Id')
             self.algorithm = key.get('Algorithm')
 
-        data = key_package.find('pskc:Key/pskc:Data', namespaces=namespaces)
+        data = find(key_package, 'pskc:Key/pskc:Data')
         if data is not None:
-            self._secret.parse(data.find(
-                'pskc:Secret', namespaces=namespaces))
-            self._counter.parse(data.find(
-                'pskc:Counter', namespaces=namespaces))
-            self._time_offset.parse(data.find(
-                'pskc:Time', namespaces=namespaces))
-            self._time_interval.parse(data.find(
-                'pskc:TimeInterval', namespaces=namespaces))
-            self._time_drift.parse(data.find(
-                'pskc:TimeDrift', namespaces=namespaces))
-
-        self.issuer = g_e_v(key_package, 'pskc:Key/pskc:Issuer')
-        self.key_profile = g_e_v(key_package, 'pskc:Key/pskc:KeyProfileId')
-        self.key_reference = g_e_v(key_package, 'pskc:Key/pskc:KeyReference')
-        self.friendly_name = g_e_v(key_package, 'pskc:Key/pskc:FriendlyName')
+            self._secret.parse(find(data, 'pskc:Secret'))
+            self._counter.parse(find(data, 'pskc:Counter'))
+            self._time_offset.parse(find(data, 'pskc:Time'))
+            self._time_interval.parse(find(data, 'pskc:TimeInterval'))
+            self._time_drift.parse(find(data, 'pskc:TimeDrift'))
+
+        self.issuer = findtext(key_package, 'pskc:Key/pskc:Issuer')
+        self.key_profile = findtext(key_package, 'pskc:Key/pskc:KeyProfileId')
+        self.key_reference = findtext(
+            key_package, 'pskc:Key/pskc:KeyReference')
+        self.friendly_name = findtext(
+            key_package, 'pskc:Key/pskc:FriendlyName')
         # TODO: support multi-language values of <FriendlyName>
-        self.key_userid = g_e_v(key_package, 'pskc:Key/pskc:UserId')
+        self.key_userid = findtext(key_package, 'pskc:Key/pskc:UserId')
 
-        self.manufacturer = g_e_v(
+        self.manufacturer = findtext(
             key_package, 'pskc:DeviceInfo/pskc:Manufacturer')
-        self.serial = g_e_v(key_package, 'pskc:DeviceInfo/pskc:SerialNo')
-        self.model = g_e_v(key_package, 'pskc:DeviceInfo/pskc:Model')
-        self.issue_no = g_e_v(key_package, 'pskc:DeviceInfo/pskc:IssueNo')
-        self.device_binding = g_e_v(
+        self.serial = findtext(key_package, 'pskc:DeviceInfo/pskc:SerialNo')
+        self.model = findtext(key_package, 'pskc:DeviceInfo/pskc:Model')
+        self.issue_no = findtext(key_package, 'pskc:DeviceInfo/pskc:IssueNo')
+        self.device_binding = findtext(
             key_package, 'pskc:DeviceInfo/pskc:DeviceBinding')
-        self.start_date = g_e_d(key_package, 'pskc:DeviceInfo/pskc:StartDate')
-        self.expiry_date = g_e_d(
+        self.start_date = findtime(
+            key_package, 'pskc:DeviceInfo/pskc:StartDate')
+        self.expiry_date = findtime(
             key_package, 'pskc:DeviceInfo/pskc:ExpiryDate')
-        self.device_userid = g_e_v(key_package, 'pskc:DeviceInfo/pskc:UserId')
+        self.device_userid = findtext(
+            key_package, 'pskc:DeviceInfo/pskc:UserId')
 
-        self.crypto_module = g_e_v(
+        self.crypto_module = findtext(
             key_package, 'pskc:CryptoModuleInfo/pskc:Id')
 
-        self.algorithm_suite = g_e_v(
+        self.algorithm_suite = findtext(
             key_package, 'pskc:Key/pskc:AlgorithmParameters/pskc:Suite')
 
-        challenge_format = key_package.find(
-            'pskc:Key/pskc:AlgorithmParameters/pskc:ChallengeFormat',
-            namespaces=namespaces)
+        challenge_format = find(
+            key_package,
+            'pskc:Key/pskc:AlgorithmParameters/pskc:ChallengeFormat')
         if challenge_format is not None:
             self.challenge_encoding = challenge_format.get('Encoding')
             value = challenge_format.get('Min')
@@ -245,9 +242,9 @@ class Key(object):
             if value:
                 self.challenge_check = value.lower() == 'true'
 
-        response_format = key_package.find(
-            'pskc:Key/pskc:AlgorithmParameters/pskc:ResponseFormat',
-            namespaces=namespaces)
+        response_format = find(
+            key_package,
+            'pskc:Key/pskc:AlgorithmParameters/pskc:ResponseFormat')
         if response_format is not None:
             self.response_encoding = response_format.get('Encoding')
             value = response_format.get('Length')
@@ -257,8 +254,7 @@ class Key(object):
             if value:
                 self.response_check = value.lower() == 'true'
 
-        self.policy.parse(key_package.find(
-            'pskc:Key/pskc:Policy', namespaces=namespaces))
+        self.policy.parse(find(key_package, 'pskc:Key/pskc:Policy'))
 
     @property
     def secret(self):
diff --git a/pskc/mac.py b/pskc/mac.py
index b035d74..d65ccdb 100644
--- a/pskc/mac.py
+++ b/pskc/mac.py
@@ -29,7 +29,6 @@ with the PSKC encryption key.
 """
 
 
-import base64
 import hashlib
 import hmac
 
@@ -46,12 +45,10 @@ class ValueMAC(object):
 
     def parse(self, value_mac):
         """Read MAC information from the <ValueMAC> XML tree."""
-        from pskc.parse import g_e_v
+        from pskc.parse import findbin
         if value_mac is None:
             return
-        value = g_e_v(value_mac, '.')
-        if value is not None:
-            self._value_mac = base64.b64decode(value)
+        self._value_mac = findbin(value_mac, '.')
 
     def check(self, value):
         """Check if the provided value matches the MAC.
@@ -84,13 +81,12 @@ class MAC(object):
 
     def parse(self, mac_method):
         """Read MAC information from the <MACMethod> XML tree."""
-        from pskc.parse import g_e_v, namespaces
+        from pskc.parse import find, findtext
         if mac_method is None:
             return
         self.algorithm = mac_method.get('Algorithm')
-        self._mac_key.parse(mac_method.find(
-            'pskc:MACKey', namespaces=namespaces))
-        mac_key_reference = g_e_v(mac_method, 'pskc:MACKeyReference')
+        self._mac_key.parse(find(mac_method, 'pskc:MACKey'))
+        mac_key_reference = findtext(mac_method, 'pskc:MACKeyReference')
 
     @property
     def key(self):
diff --git a/pskc/parse.py b/pskc/parse.py
index 27de5f7..7157fbb 100644
--- a/pskc/parse.py
+++ b/pskc/parse.py
@@ -39,23 +39,44 @@ namespaces = dict(
 )
 
 
-def g_e_v(tree, match):
+def findall(tree, match):
+    """Find a child element (or None)."""
+    return tree.findall(match, namespaces=namespaces)
+
+
+def find(tree, match):
+    """Find a child element (or None)."""
+    try:
+        return iter(findall(tree, match)).next()
+    except StopIteration:
+        return None
+
+
+def findtext(tree, match):
     """Get the text value of an element (or None)."""
-    element = tree.find(match, namespaces=namespaces)
+    element = find(tree, match)
     if element is not None:
         return element.text.strip()
 
 
-def g_e_i(tree, match):
+def findint(tree, match):
     """Return an element value as an int (or None)."""
-    element = tree.find(match, namespaces=namespaces)
-    if element is not None:
-        return int(element.text.strip())
+    value = findtext(tree, match)
+    if value:
+        return int(value)
 
 
-def g_e_d(tree, match):
+def findtime(tree, match):
     """Return an element value as a datetime (or None)."""
-    element = tree.find(match, namespaces=namespaces)
-    if element is not None:
+    value = findtext(tree, match)
+    if value:
         import dateutil.parser
-        return dateutil.parser.parse(element.text.strip())
+        return dateutil.parser.parse(value)
+
+
+def findbin(tree, match):
+    """Return the binary element value base64 decoded."""
+    value = findtext(tree, match)
+    if value:
+        import base64
+        return base64.b64decode(value)
diff --git a/pskc/policy.py b/pskc/policy.py
index a1eb330..a93d94b 100644
--- a/pskc/policy.py
+++ b/pskc/policy.py
@@ -109,20 +109,18 @@ class Policy(object):
 
     def parse(self, policy):
         """Read key policy information from the provided <Policy> tree."""
-        from pskc.parse import g_e_v, g_e_i, g_e_d, namespaces
+        from pskc.parse import find, findall, findtext, findint, findtime
         if policy is None:
             return
 
-        self.start_date = g_e_d(policy, 'pskc:StartDate')
-        self.expiry_date = g_e_d(policy, 'pskc:ExpiryDate')
-        self.number_of_transactions = g_e_i(
+        self.start_date = findtime(policy, 'pskc:StartDate')
+        self.expiry_date = findtime(policy, 'pskc:ExpiryDate')
+        self.number_of_transactions = findint(
             policy, 'pskc:NumberOfTransactions')
-        for key_usage in policy.findall(
-                'pskc:KeyUsage', namespaces=namespaces):
-            self.key_usage.append(g_e_v(key_usage, '.'))
+        for key_usage in findall(policy, 'pskc:KeyUsage'):
+            self.key_usage.append(findtext(key_usage, '.'))
 
-        pin_policy = policy.find(
-            'pskc:PINPolicy', namespaces=namespaces)
+        pin_policy = find(policy, 'pskc:PINPolicy')
         if pin_policy is not None:
             self.pin_key_id = pin_policy.get('PINKeyId')
             self.pin_usage = pin_policy.get('PINUsageMode')

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

commit 6a34c01a777b92ccc64b094361dd75c8e8feb2d1
Author: Arthur de Jong <arthur@west.nl>
Date:   Wed Jun 11 13:04:13 2014 +0200

    Use get() instead of attrib.get() (shorter)

diff --git a/pskc/__init__.py b/pskc/__init__.py
index 71e2f89..9604d8a 100644
--- a/pskc/__init__.py
+++ b/pskc/__init__.py
@@ -91,11 +91,11 @@ class PSKC(object):
         if not container.tag.endswith('KeyContainer'):
             raise ParseError('Missing KeyContainer')
         # the version of the PSKC schema
-        self.version = container.attrib.get('Version')
+        self.version = container.get('Version')
         if self.version != '1.0':
             raise ParseError('Unsupported version %r' % self.version)
         # unique identifier for the container
-        self.id = container.attrib.get('Id')
+        self.id = container.get('Id')
         # handle EncryptionKey entries
         self.encryption.parse(container.find(
             'pskc:EncryptionKey', namespaces=namespaces))
diff --git a/pskc/encryption.py b/pskc/encryption.py
index 48b9ef5..cc91f7c 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -59,7 +59,7 @@ class EncryptedValue(object):
             return
         encryption_method = encrypted_value.find(
             'xenc:EncryptionMethod', namespaces=namespaces)
-        self.algorithm = encryption_method.attrib.get('Algorithm')
+        self.algorithm = encryption_method.get('Algorithm')
         value = g_e_v(encrypted_value, 'xenc:CipherData/xenc:CipherValue')
         if value is not None:
             self.cipher_value = base64.b64decode(value)
@@ -138,7 +138,7 @@ class KeyDerivation(object):
         from pskc.parse import g_e_v, g_e_i, namespaces
         if key_deriviation is None:
             return
-        self.algorithm = key_deriviation.attrib.get('Algorithm')
+        self.algorithm = key_deriviation.get('Algorithm')
         # PBKDF2 properties
         pbkdf2 = key_deriviation.find(
             'xenc11:PBKDF2-params', namespaces=namespaces)
@@ -157,7 +157,7 @@ class KeyDerivation(object):
             # pseudorandom function used
             prf = pbkdf2.find('PRF', namespaces=namespaces)
             if prf is not None:
-                self.pbkdf2_prf = prf.attrib.get('Algorithm')
+                self.pbkdf2_prf = prf.get('Algorithm')
 
     def derive(self, password):
         """Derive a key from the password."""
@@ -206,7 +206,7 @@ class Encryption(object):
         from pskc.parse import g_e_v, namespaces
         if key_info is None:
             return
-        self.id = key_info.attrib.get('Id')
+        self.id = key_info.get('Id')
         for name in key_info.findall('ds:KeyName', namespaces=namespaces):
             self.key_names.append(g_e_v(name, '.'))
         for name in key_info.findall(
diff --git a/pskc/key.py b/pskc/key.py
index 3a5de99..cd12213 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -189,8 +189,8 @@ class Key(object):
 
         key = key_package.find('pskc:Key', namespaces=namespaces)
         if key is not None:
-            self.id = key.attrib.get('Id')
-            self.algorithm = key.attrib.get('Algorithm')
+            self.id = key.get('Id')
+            self.algorithm = key.get('Algorithm')
 
         data = key_package.find('pskc:Key/pskc:Data', namespaces=namespaces)
         if data is not None:
@@ -234,28 +234,28 @@ class Key(object):
             'pskc:Key/pskc:AlgorithmParameters/pskc:ChallengeFormat',
             namespaces=namespaces)
         if challenge_format is not None:
-            self.challenge_encoding = challenge_format.attrib.get('Encoding')
-            v = challenge_format.attrib.get('Min')
-            if v:
-                self.challenge_min_length = int(v)
-            v = challenge_format.attrib.get('Max')
-            if v:
-                self.challenge_max_length = int(v)
-            v = challenge_format.attrib.get('CheckDigits')
-            if v:
-                self.challenge_check = v.lower() == 'true'
+            self.challenge_encoding = challenge_format.get('Encoding')
+            value = challenge_format.get('Min')
+            if value:
+                self.challenge_min_length = int(value)
+            value = challenge_format.get('Max')
+            if value:
+                self.challenge_max_length = int(value)
+            value = challenge_format.get('CheckDigits')
+            if value:
+                self.challenge_check = value.lower() == 'true'
 
         response_format = key_package.find(
             'pskc:Key/pskc:AlgorithmParameters/pskc:ResponseFormat',
             namespaces=namespaces)
         if response_format is not None:
-            self.response_encoding = response_format.attrib.get('Encoding')
-            v = response_format.attrib.get('Length')
-            if v:
-                self.response_length = int(v)
-            v = response_format.attrib.get('CheckDigits')
-            if v:
-                self.response_check = v.lower() == 'true'
+            self.response_encoding = response_format.get('Encoding')
+            value = response_format.get('Length')
+            if value:
+                self.response_length = int(value)
+            value = response_format.get('CheckDigits')
+            if value:
+                self.response_check = value.lower() == 'true'
 
         self.policy.parse(key_package.find(
             'pskc:Key/pskc:Policy', namespaces=namespaces))
diff --git a/pskc/mac.py b/pskc/mac.py
index 3e7f248..b035d74 100644
--- a/pskc/mac.py
+++ b/pskc/mac.py
@@ -87,7 +87,7 @@ class MAC(object):
         from pskc.parse import g_e_v, namespaces
         if mac_method is None:
             return
-        self.algorithm = mac_method.attrib.get('Algorithm')
+        self.algorithm = mac_method.get('Algorithm')
         self._mac_key.parse(mac_method.find(
             'pskc:MACKey', namespaces=namespaces))
         mac_key_reference = g_e_v(mac_method, 'pskc:MACKeyReference')
diff --git a/pskc/policy.py b/pskc/policy.py
index 6b2bc79..a1eb330 100644
--- a/pskc/policy.py
+++ b/pskc/policy.py
@@ -124,18 +124,18 @@ class Policy(object):
         pin_policy = policy.find(
             'pskc:PINPolicy', namespaces=namespaces)
         if pin_policy is not None:
-            self.pin_key_id = pin_policy.attrib.get('PINKeyId')
-            self.pin_usage = pin_policy.attrib.get('PINUsageMode')
-            v = pin_policy.attrib.get('MaxFailedAttempts')
-            if v:
-                self.pin_max_failed_attemtps = int(v)
-            v = pin_policy.attrib.get('MinLength')
-            if v:
-                self.pin_min_length = int(v)
-            v = pin_policy.attrib.get('MaxLength')
-            if v:
-                self.pin_max_length = int(v)
-            self.pin_encoding = pin_policy.attrib.get('PINEncoding')
+            self.pin_key_id = pin_policy.get('PINKeyId')
+            self.pin_usage = pin_policy.get('PINUsageMode')
+            value = pin_policy.get('MaxFailedAttempts')
+            if value:
+                self.pin_max_failed_attemtps = int(value)
+            value = pin_policy.get('MinLength')
+            if value:
+                self.pin_min_length = int(value)
+            value = pin_policy.get('MaxLength')
+            if value:
+                self.pin_max_length = int(value)
+            self.pin_encoding = pin_policy.get('PINEncoding')
             # TODO: check if there are any other attributes set for PINPolicy
             # of if there are any children and set unknown_policy_elementss
 

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

Summary of changes:
 pskc/__init__.py   |   21 ++++-----
 pskc/encryption.py |   57 ++++++++++--------------
 pskc/key.py        |  124 +++++++++++++++++++++++++---------------------------
 pskc/mac.py        |   16 +++----
 pskc/parse.py      |   56 +++++++++++++++++++-----
 pskc/policy.py     |   40 ++++++++---------
 setup.py           |    1 +
 7 files changed, 164 insertions(+), 151 deletions(-)


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/