aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnunet/__init__.py16
-rw-r--r--gnunet/crypto.py3
2 files changed, 10 insertions, 9 deletions
diff --git a/gnunet/__init__.py b/gnunet/__init__.py
index dc4e701..c4c5648 100644
--- a/gnunet/__init__.py
+++ b/gnunet/__init__.py
@@ -6,8 +6,8 @@ class GNUNetDaemonError(Exception):
6 6
7 7
8class _Key: 8class _Key:
9 def __init__(self, arg, subtype, bits): 9 def __init__(self, arg):
10 if isinstance(arg, subtype): 10 if isinstance(arg, type(self)):
11 self._data = arg._data 11 self._data = arg._data
12 elif isinstance(arg, str): 12 elif isinstance(arg, str):
13 self._data = strings.string_to_data(arg) 13 self._data = strings.string_to_data(arg)
@@ -15,18 +15,20 @@ class _Key:
15 try: 15 try:
16 self._data = bytearray(arg) 16 self._data = bytearray(arg)
17 except: 17 except:
18 raise TypeError("'arg' must be a " + type(subtype).__name__ + ", a string or an array of bytes. Not a '" + type(arg).__name__ + "'.") 18 raise TypeError("'arg' must be a %s, a string or an array "
19 "of bytes. Not a '%s'." %
20 (type(self).__name__, type(arg).__name__),)
19 21
20 if len(self._data) * 8 != bits: 22 if len(self._data) * 8 != self.__bits__:
21 raise ValueError("'arg' must be a " + bits + " bit hash. Got " + len(self._data) + " bits.") 23 raise ValueError("'arg' must be a %s bit hash. Got %s bits."
24 % (self.__bits__, len(self._data) * 8))
22 25
23 def __str__(self): 26 def __str__(self):
24 return strings.data_to_string(self._data) 27 return strings.data_to_string(self._data)
25 28
26 29
27class HashCode(_Key): 30class HashCode(_Key):
28 def __init__(self, arg): 31 __bits__ = 512
29 _Key.__init__(self, arg, HashCode, 512)
30 32
31 def __repr__(self): 33 def __repr__(self):
32 return "gnunet.HashCode('" + str(self) + "')" 34 return "gnunet.HashCode('" + str(self) + "')"
diff --git a/gnunet/crypto.py b/gnunet/crypto.py
index 461b0cc..253f46e 100644
--- a/gnunet/crypto.py
+++ b/gnunet/crypto.py
@@ -3,8 +3,7 @@ import gnunet.strings as strings
3 3
4 4
5class EcdsaPublicKey(_Key): 5class EcdsaPublicKey(_Key):
6 def __init__(self, arg): 6 __bits__ = 256
7 _Key.__init__(self, arg, EcdsaPublicKey, 256)
8 7
9 def __repr__(self): 8 def __repr__(self):
10 return "gnunet.crypto.EcdsaPublicKey('" + str(self) + "')" 9 return "gnunet.crypto.EcdsaPublicKey('" + str(self) + "')"