python-pskc branch master updated. 0.3-4-ga82a60b
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-pskc branch master updated. 0.3-4-ga82a60b
- From: Commits of the python-pskc project <python-pskc-commits [at] lists.arthurdejong.org>
- To: python-pskc-commits [at] lists.arthurdejong.org
- Reply-to: python-pskc-users [at] lists.arthurdejong.org
- Subject: python-pskc branch master updated. 0.3-4-ga82a60b
- Date: Mon, 30 Nov 2015 20:00:09 +0100 (CET)
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 a82a60b2bfbb27fe7f7d9cd45f8d394ee1dde3d2 (commit)
via e711a30315766f809aec2aa1618487b63ca918d1 (commit)
via 1577687508a8af0bead31ea741fae0d2a522465e (commit)
via 3aa2a6f86cc5a19f9ff604c2a422d69fb3787252 (commit)
from c155d158df9dc9e76f47b6b0193387fa403c7522 (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=a82a60b2bfbb27fe7f7d9cd45f8d394ee1dde3d2
commit a82a60b2bfbb27fe7f7d9cd45f8d394ee1dde3d2
Author: Mathias Laurin <Mathias.Laurin+github.com@gmail.com>
Date: Mon Nov 30 15:51:50 2015 +0100
Make value conversion methods static private
- the conversions do not call self: they are static
- the conversions are not to be used out of the class: make private
diff --git a/pskc/key.py b/pskc/key.py
index 82994bc..00b1225 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -56,19 +56,23 @@ class DataType(object):
return
value = findtext(element, 'pskc:PlainValue')
if value is not None:
- self.value = self.from_text(value)
+
+ self.value = self._from_text(value)
self.encrypted_value.parse(find(element, 'pskc:EncryptedValue'))
self.value_mac.parse(find(element, 'pskc:ValueMAC'))
- def from_text(self, value):
+ @staticmethod
+ def _from_text(value):
"""Convert the plain value to native representation."""
raise NotImplementedError
- def to_text(self, value):
+ @staticmethod
+ def _to_text(value):
"""Convert the value to an unencrypted string representation."""
raise NotImplementedError
- def from_bin(self, value):
+ @staticmethod
+ def _from_bin(value):
"""Convert the unencrypted binary to native representation."""
return value
@@ -83,7 +87,7 @@ class DataType(object):
if data is None:
data = mk_elem(key, 'pskc:Data', empty=True)
element = mk_elem(data, tag, empty=True)
- mk_elem(element, 'pskc:PlainValue', self.to_text(self.value))
+ mk_elem(element, 'pskc:PlainValue', self._to_text(self.value))
def get_value(self):
"""Provide the raw binary value."""
@@ -92,7 +96,7 @@ class DataType(object):
if self.encrypted_value.cipher_value:
# check MAC and decrypt
self.check()
- return self.from_bin(self.encrypted_value.decrypt())
+ return self._from_bin(self.encrypted_value.decrypt())
def set_value(self, value):
"""Set the unencrypted value."""
@@ -108,11 +112,13 @@ class DataType(object):
class BinaryDataType(DataType):
"""Subclass of DataType for binary data (e.g. keys)."""
- def from_text(self, value):
+ @staticmethod
+ def _from_text(value):
"""Convert the plain value to native representation."""
return base64.b64decode(value)
- def to_text(self, value):
+ @staticmethod
+ def _to_text(value):
"""Convert the value to an unencrypted string representation."""
# force conversion to bytestring on Python 3
if not isinstance(value, type(b'')):
@@ -123,15 +129,18 @@ class BinaryDataType(DataType):
class IntegerDataType(DataType):
"""Subclass of DataType for integer types (e.g. counters)."""
- def from_text(self, value):
+ @staticmethod
+ def _from_text(value):
"""Convert the plain value to native representation."""
return int(value)
- def to_text(self, value):
+ @staticmethod
+ def _to_text(value):
"""Convert the value to an unencrypted string representation."""
return str(value)
- def from_bin(self, value):
+ @staticmethod
+ def _from_bin(value):
"""Convert the unencrypted binary to native representation."""
result = 0
for x in value:
http://arthurdejong.org/git/python-pskc/commit/?id=e711a30315766f809aec2aa1618487b63ca918d1
commit e711a30315766f809aec2aa1618487b63ca918d1
Author: Mathias Laurin <Mathias.Laurin+github.com@gmail.com>
Date: Mon Nov 30 15:40:06 2015 +0100
Provide abstract methods to clarify API
diff --git a/pskc/key.py b/pskc/key.py
index af5f87d..82994bc 100644
--- a/pskc/key.py
+++ b/pskc/key.py
@@ -60,6 +60,18 @@ class DataType(object):
self.encrypted_value.parse(find(element, 'pskc:EncryptedValue'))
self.value_mac.parse(find(element, 'pskc:ValueMAC'))
+ def from_text(self, value):
+ """Convert the plain value to native representation."""
+ raise NotImplementedError
+
+ def to_text(self, value):
+ """Convert the value to an unencrypted string representation."""
+ raise NotImplementedError
+
+ def from_bin(self, value):
+ """Convert the unencrypted binary to native representation."""
+ return value
+
def make_xml(self, key, tag):
from pskc.xml import find, mk_elem
# skip empty values
@@ -107,10 +119,6 @@ class BinaryDataType(DataType):
value = value.encode()
return base64.b64encode(value).decode()
- def from_bin(self, value):
- """Convert the unencrypted binary to native representation."""
- return value
-
class IntegerDataType(DataType):
"""Subclass of DataType for integer types (e.g. counters)."""
http://arthurdejong.org/git/python-pskc/commit/?id=1577687508a8af0bead31ea741fae0d2a522465e
commit 1577687508a8af0bead31ea741fae0d2a522465e
Author: Mathias Laurin <Mathias.Laurin+github.com@gmail.com>
Date: Mon Nov 30 13:39:43 2015 +0100
Fix typo in variable name
diff --git a/pskc/encryption.py b/pskc/encryption.py
index 4911662..eeda41a 100644
--- a/pskc/encryption.py
+++ b/pskc/encryption.py
@@ -120,24 +120,24 @@ class KeyDerivation(object):
pbkdf2_prf: name of pseudorandom function used
"""
- def __init__(self, key_deriviation=None):
+ def __init__(self, key_derivation=None):
self.algorithm = None
# PBKDF2 properties
self.pbkdf2_salt = None
self.pbkdf2_iterations = None
self.pbkdf2_key_length = None
self.pbkdf2_prf = None
- self.parse(key_deriviation)
+ self.parse(key_derivation)
- def parse(self, key_deriviation):
+ def parse(self, key_derivation):
"""Read derivation parameters from a <KeyDerivationMethod> element."""
from pskc.xml import find, findint, findbin
- if key_deriviation is None:
+ if key_derivation is None:
return
- self.algorithm = key_deriviation.get('Algorithm')
+ self.algorithm = key_derivation.get('Algorithm')
# PBKDF2 properties
pbkdf2 = find(
- key_deriviation, 'xenc11:PBKDF2-params', 'pkcs5:PBKDF2-params')
+ key_derivation, 'xenc11:PBKDF2-params', 'pkcs5:PBKDF2-params')
if pbkdf2 is not None:
# get used salt
self.pbkdf2_salt = findbin(
http://arthurdejong.org/git/python-pskc/commit/?id=3aa2a6f86cc5a19f9ff604c2a422d69fb3787252
commit 3aa2a6f86cc5a19f9ff604c2a422d69fb3787252
Author: Mathias Laurin <Mathias.Laurin+github.com@gmail.com>
Date: Mon Nov 30 13:27:57 2015 +0100
Fix doctest: IGNORE_EXCEPTION_DETAL
diff --git a/tests/test_invalid.doctest b/tests/test_invalid.doctest
index 4a1c314..5ee43d1 100644
--- a/tests/test_invalid.doctest
+++ b/tests/test_invalid.doctest
@@ -43,7 +43,7 @@ ParseError: Missing KeyContainer
This file has an unknown PSKC version.
->>> pskc = PSKC('tests/invalid-wrongversion.pskcxml')
+>>> pskc = PSKC('tests/invalid-wrongversion.pskcxml') # doctest:
+IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ParseError: Unsupported version
@@ -61,7 +61,7 @@ Traceback (most recent call last):
...
DecryptionError: No key available
>>> pskc.encryption.key = a2b_hex('12345678901234567890123456789012')
->>> key.secret
+>>> key.secret # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
DecryptionError: Unsupported algorithm: ...
@@ -81,7 +81,7 @@ Specify an unknown key derivation algorithm specified.
>>> pskc.encryption.derive_key('qwerty')
Traceback (most recent call last):
...
-KeyDerivationError: Unsupported algorithm: ...
+KeyDerivationError: Unsupported algorithm: 'unknown'
Figure 6 does use encryption but with a pre-shared key. Attempting key
@@ -101,7 +101,7 @@ Specify an unknown PBKDF2 PRF (pseudorandom function).
>>> pskc.encryption.derive_key('qwerty')
Traceback (most recent call last):
...
-KeyDerivationError: Pseudorandom function unsupported: ...
+KeyDerivationError: Pseudorandom function unsupported: 'unknown'
There is a ValueMAC element but no MACMethod element.
@@ -124,7 +124,7 @@ There is an unknown algorithm specified in MACMethod.
>>> key = pskc.keys[0]
>>> key.id
'12345678'
->>> key.secret
+>>> key.secret # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
DecryptionError: Unsupported MAC algorithm: ...
-----------------------------------------------------------------------
Summary of changes:
pskc/encryption.py | 12 ++++++------
pskc/key.py | 41 +++++++++++++++++++++++++++++------------
tests/test_invalid.doctest | 10 +++++-----
3 files changed, 40 insertions(+), 23 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/
- python-pskc branch master updated. 0.3-4-ga82a60b,
Commits of the python-pskc project