Skip to content

Commit

Permalink
make use of compat
Browse files Browse the repository at this point in the history
  • Loading branch information
albu-diku committed Oct 5, 2024
1 parent 7daf45f commit 49bbb54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mig/shared/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def _is_unicode(val):
return (type(val) == _TYPE_UNICODE)


def encode_unicode_string(unicode_string):
"""Convert a unicode string value to bytes."""

return codecs.encode(unicode_string, 'utf8')


def ensure_native_string(string_or_bytes):
"""Given a supplied input which can be either a string or bytes
return a representation providing string operations while ensuring that
Expand Down
3 changes: 2 additions & 1 deletion mig/shared/pwcrypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import time

from mig.shared.base import force_utf8, mask_creds, string_snippet
from mig.shared.compat import encode_unicode_string
from mig.shared.defaults import keyword_auto, RESET_TOKEN_TTL


Expand Down Expand Up @@ -118,7 +119,7 @@ def best_crypt_salt(configuration):
def make_hash(password, _urandom=urandom):
"""Generate a random salt and return a new hash for the password."""
salt = b64encode(_urandom(SALT_LENGTH))
password_bytes = codecs.encode(password, 'utf8')
password_bytes = encode_unicode_string(password)
password_hashed = hashlib.pbkdf2_hmac(HASH_FUNCTION,
password_bytes, salt,
COST_FACTOR, KEY_LENGTH)
Expand Down

0 comments on commit 49bbb54

Please sign in to comment.