hash-utils: added method to make it return str instead of bytes
This commit is contained in:
parent
0e5495de20
commit
decb5f5681
1 changed files with 17 additions and 7 deletions
|
|
@ -19,28 +19,38 @@
|
|||
# and proprietary license terms, please see https://rhodecode.com/licenses/
|
||||
|
||||
import hashlib
|
||||
from rhodecode.lib.str_utils import safe_bytes
|
||||
from rhodecode.lib.str_utils import safe_bytes, safe_str
|
||||
|
||||
|
||||
def md5(s):
|
||||
return hashlib.md5(s).hexdigest()
|
||||
|
||||
|
||||
def md5_safe(s):
|
||||
return md5(safe_bytes(s))
|
||||
def md5_safe(s, return_type=''):
|
||||
|
||||
val = md5(safe_bytes(s))
|
||||
if return_type == 'str':
|
||||
val = safe_str(val)
|
||||
return val
|
||||
|
||||
|
||||
def sha1(s):
|
||||
return hashlib.sha1(s).hexdigest()
|
||||
|
||||
|
||||
def sha1_safe(s):
|
||||
return sha1(safe_bytes(s))
|
||||
def sha1_safe(s, return_type=''):
|
||||
val = sha1(safe_bytes(s))
|
||||
if return_type == 'str':
|
||||
val = safe_str(val)
|
||||
return val
|
||||
|
||||
|
||||
def sha256(s):
|
||||
return hashlib.sha256(s).hexdigest()
|
||||
|
||||
|
||||
def sha256_safe(s):
|
||||
return sha256(safe_bytes(s))
|
||||
def sha256_safe(s, return_type=''):
|
||||
val = sha256(safe_bytes(s))
|
||||
if return_type == 'str':
|
||||
val = safe_str(val)
|
||||
return val
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue