]> Cypherpunks.ru repositories - pygost.git/blob - pygost/iface.py
Use curve's cofactor during VKO calculations
[pygost.git] / pygost / iface.py
1 from abc import ABCMeta
2 from abc import abstractmethod
3
4 from pygost.utils import hexenc
5
6
7 # This function is taken from six package as is
8 def add_metaclass(metaclass):
9     """Class decorator for creating a class with a metaclass."""
10     def wrapper(cls):
11         orig_vars = cls.__dict__.copy()
12         slots = orig_vars.get("__slots__")
13         if slots is not None:
14             if isinstance(slots, str):
15                 slots = [slots]
16             for slots_var in slots:
17                 orig_vars.pop(slots_var)
18         orig_vars.pop("__dict__", None)
19         orig_vars.pop("__weakref__", None)
20         return metaclass(cls.__name__, cls.__bases__, orig_vars)
21     return wrapper
22
23
24 @add_metaclass(ABCMeta)
25 class PEP247(object):
26     @property
27     @abstractmethod
28     def digest_size(self):
29         """The size of the digest produced by the hashing objects.
30         """
31
32     @abstractmethod
33     def copy(self):
34         """Return a separate copy of this hashing object.
35         """
36
37     @abstractmethod
38     def update(self, data):
39         """Hash data into the current state of the hashing object.
40         """
41
42     @abstractmethod
43     def digest(self):
44         """Return the hash value as a string containing 8-bit data.
45         """
46
47     def hexdigest(self):
48         """Return the hash value as a string containing hexadecimal digits.
49         """
50         return hexenc(self.digest())