Skip to content

Commit

Permalink
ensure returned value is not encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jun 8, 2016
1 parent 9c79d40 commit 09a0f7a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion django_crypto_fields/field_cryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ def get_prep_value(self, value):
if value is None or value in ['', b'']:
return value
ciphertext = self.encrypt(value)
return ciphertext.split(CIPHER_PREFIX.encode(ENCODING))[0]
value = ciphertext.split(CIPHER_PREFIX.encode(ENCODING))[0]
try:
value.decode()
except AttributeError:
pass
return value # returns into CharField

def get_hash(self, ciphertext):
"""Returns the hashed_value given a ciphertext or None."""
Expand Down
16 changes: 14 additions & 2 deletions django_crypto_fields/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,22 @@
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': os.path.join(BASE_DIR.ancestor(1), 'etc', 'default.cnf'),
},
'HOST': '',
'PORT': '',
'ATOMIC_REQUESTS': True,
}
}

Expand Down
9 changes: 9 additions & 0 deletions etc/default.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# my.cnf
# Be sure to create the database with CHARACTER SET = utf8
# e.g. create database edc CHARACTER SET utf8;
[client]
database = edc
user = root
password = cc3721b
default-character-set = utf8
init_command = 'SET default_storage_engine=INNODB;'

0 comments on commit 09a0f7a

Please sign in to comment.