From c60e57615ac5dc348178acbb01a60cbda983d6d7 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 19 Nov 2016 16:26:55 +0300 Subject: [PATCH] Move hexdigest implementation to common PEP247 class --- pygost/gost28147_mac.py | 4 ---- pygost/gost34112012.py | 2 -- pygost/gost341194.py | 3 --- pygost/iface.py | 4 +++- 4 files changed, 3 insertions(+), 10 deletions(-) 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()) -- 2.44.0