deprecate sha1/md5_constructor from koji.util

These functions are now fully provided by hashlib. Commit removes their
usage from koji's codebase and leaves deprecation message in lib.

Final removal from lib is scheduled to 1.21.

Fixes: https://pagure.io/koji/issue/1487
This commit is contained in:
Tomas Kopecek 2019-06-11 11:37:51 +02:00 committed by Mike McLean
parent c76573312a
commit dfbe322222
8 changed files with 29 additions and 29 deletions

View file

@ -22,6 +22,7 @@
from __future__ import absolute_import
from __future__ import division
import hashlib
import os
import os.path
import re
@ -38,7 +39,6 @@ from koji.server import ServerRedirect
from kojiweb.util import _initValues
from kojiweb.util import _genHTML
from kojiweb.util import _getValidTokens
from koji.util import sha1_constructor
from six.moves import range
import six
@ -58,7 +58,7 @@ def _setUserCookie(environ, user):
digest_string = value + options['Secret'].value
if six.PY3:
digest_string = digest_string.encode('utf-8')
shasum = sha1_constructor(digest_string)
shasum = hashlib.sha1(digest_string)
value = "%s:%s" % (shasum.hexdigest(), value)
cookies = six.moves.http_cookies.SimpleCookie()
cookies['user'] = value
@ -97,7 +97,7 @@ def _getUserCookie(environ):
digest_string = value + options['Secret'].value
if six.PY3:
digest_string = digest_string.encode('utf-8')
shasum = sha1_constructor(digest_string)
shasum = hashlib.sha1(digest_string)
if shasum.hexdigest() != sig:
authlogger.warn('invalid user cookie: %s:%s', sig, value)
return None

View file

@ -24,8 +24,8 @@ from __future__ import division
import cgi
import Cheetah.Template
import datetime
import hashlib
import koji
from koji.util import md5_constructor
import os
import six
import ssl
@ -170,7 +170,7 @@ def _genToken(environ, tstamp=None):
value = user + str(tstamp) + environ['koji.options']['Secret'].value
if six.PY3:
value = value.encode('utf-8')
return md5_constructor(value).hexdigest()[-8:]
return hashlib.md5(value).hexdigest()[-8:]
def _getValidTokens(environ):
tokens = []