From: Sergey Matveev Date: Sat, 19 Nov 2016 13:26:55 +0000 (+0300) Subject: Move hexdigest implementation to common PEP247 class X-Git-Tag: 3.0~18 X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=commitdiff_plain;h=c60e57615ac5dc348178acbb01a60cbda983d6d7 Move hexdigest implementation to common PEP247 class --- diff --git a/pygost/gost28147_mac.py b/pygost/gost28147_mac.py index 5f1ce69..164abcb 100644 --- a/pygost/gost28147_mac.py +++ b/pygost/gost28147_mac.py @@ -29,7 +29,6 @@ from pygost.gost28147 import validate_sbox from pygost.gost28147 import xcrypt from pygost.gost3413 import pad1 from pygost.iface import PEP247 -from pygost.utils import hexenc from pygost.utils import strxor from pygost.utils import xrange @@ -96,9 +95,6 @@ class MAC(PEP247): )[::-1] return ns2block(prev) - def hexdigest(self): - return hexenc(self.digest()) - def new(key, data=b"", iv=8 * b"\x00", sbox=DEFAULT_SBOX): return MAC(key, data, iv, sbox) diff --git a/pygost/gost34112012.py b/pygost/gost34112012.py index 7ba2b5d..de4ef2e 100644 --- a/pygost/gost34112012.py +++ b/pygost/gost34112012.py @@ -272,5 +272,3 @@ class GOST34112012(PEP247): hsh = g(0, hsh, chk) return hsh[-self._digest_size:] - def hexdigest(self): - return hexenc(self.digest()) diff --git a/pygost/gost341194.py b/pygost/gost341194.py index 90a5f82..adc0925 100644 --- a/pygost/gost341194.py +++ b/pygost/gost341194.py @@ -180,9 +180,6 @@ class GOST341194(PEP247): h = _step(h, checksum, self.sbox) return h[::-1] - def hexdigest(self): - return hexenc(self.digest()) - def new(data=b"", sbox=DEFAULT_SBOX): return GOST341194(data, sbox) diff --git a/pygost/iface.py b/pygost/iface.py index 887d69f..e2d6a4c 100644 --- a/pygost/iface.py +++ b/pygost/iface.py @@ -1,6 +1,8 @@ from abc import ABCMeta from abc import abstractmethod +from pygost.utils import hexenc + # This function is taken from six package as is def add_metaclass(metaclass): @@ -42,7 +44,7 @@ class PEP247(object): """Return the hash value as a string containing 8-bit data. """ - @abstractmethod def hexdigest(self): """Return the hash value as a string containing hexadecimal digits. """ + return hexenc(self.digest())