aboutsummaryrefslogtreecommitdiff
path: root/gnunet/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'gnunet/__init__.py')
-rw-r--r--gnunet/__init__.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/gnunet/__init__.py b/gnunet/__init__.py
new file mode 100644
index 0000000..425ab86
--- /dev/null
+++ b/gnunet/__init__.py
@@ -0,0 +1,31 @@
1import gnunet.strings as strings
2
3class GNUNetDaemonError(Exception):
4 pass
5
6class _Key:
7 def __init__(self, arg, subtype, bits):
8 if isinstance(arg, subtype):
9 self._data = arg.data
10 elif isinstance(arg, str):
11 self._data = strings.string_to_data(arg)
12 else:
13 try:
14 self._data = bytearray(arg)
15 except:
16 raise TypeError("'arg' must be a " + type(subtype).__name__ + ", a string or an array of bytes. Not a '" + type(arg).__name__ + "'.")
17
18 if len(self._data) * 8 != bits:
19 raise ValueError("'arg' must be a " + bits + " bit hash. Got " + len(self._data) + " bits.")
20
21 def __str__(self):
22 return strings.data_to_string(self._data)
23
24
25class HashCode(_Key):
26 def __init__(self, arg):
27 _Key.__init__(self, arg, HashCode, 512)
28
29 def __repr__(self):
30 return "gnunet.HashCode('" + str(self) + "')"
31