commit
675efa14ac
@ -19,10 +19,11 @@ from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
from cffi import FFI
|
||||
|
||||
import six
|
||||
|
||||
from . import __about__
|
||||
from .__about__ import *
|
||||
|
||||
@ -30,15 +31,6 @@ from .__about__ import *
|
||||
__all__ = ["gensalt", "hashpw"] + __about__.__all__
|
||||
|
||||
|
||||
# True if we are running on Python 3.
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
if PY3:
|
||||
text_type = str
|
||||
else:
|
||||
text_type = unicode
|
||||
|
||||
|
||||
_crypt_blowfish_dir = "crypt_blowfish-1.2"
|
||||
_bundled_dir = os.path.join(os.path.dirname(__file__), _crypt_blowfish_dir)
|
||||
|
||||
@ -87,7 +79,7 @@ def gensalt(rounds=12):
|
||||
|
||||
|
||||
def hashpw(password, salt):
|
||||
if isinstance(password, text_type) or isinstance(salt, text_type):
|
||||
if isinstance(password, six.text_type) or isinstance(salt, six.text_type):
|
||||
raise TypeError("Unicode-objects must be encoded before hashing")
|
||||
|
||||
hashed = _ffi.new("unsigned char[]", 128)
|
||||
|
||||
5
setup.py
5
setup.py
@ -6,6 +6,9 @@ from setuptools import setup
|
||||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
|
||||
SIX_DEPENDENCY = "six>=1.4.1"
|
||||
|
||||
|
||||
class _AttrDict(dict):
|
||||
|
||||
def __getattr__(self, key):
|
||||
@ -65,9 +68,11 @@ setup(
|
||||
|
||||
setup_requires=[
|
||||
"cffi",
|
||||
SIX_DEPENDENCY,
|
||||
],
|
||||
install_requires=[
|
||||
"cffi",
|
||||
SIX_DEPENDENCY,
|
||||
],
|
||||
extras_require={
|
||||
"tests": [
|
||||
|
||||
@ -2,6 +2,7 @@ import os
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
import bcrypt
|
||||
|
||||
@ -109,9 +110,9 @@ def test_hashpw_invalid():
|
||||
|
||||
def test_hashpw_str_password():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.hashpw(bcrypt.text_type("password"), b"$2a$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
bcrypt.hashpw(six.text_type("password"), b"$2a$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
|
||||
|
||||
def test_hashpw_str_salt():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.hashpw(b"password", bcrypt.text_type("$2a$04$cVWp4XaNU8a4v1uMRum2SO"))
|
||||
bcrypt.hashpw(b"password", six.text_type("$2a$04$cVWp4XaNU8a4v1uMRum2SO"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user