Skip to content

Commit

Permalink
#12 dummy cryptor for cryptoless build
Browse files Browse the repository at this point in the history
  • Loading branch information
zhebrak committed May 2, 2017
1 parent c5d70d0 commit 53bb512
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions raftos/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def default_settings():
# For UDP messages encryption
'secret_key': b'raftos sample secret key',
'salt': b'raftos sample salt',
'crypto_enabled': True,

# Election callbacks
'on_leader': lambda: None,
Expand Down
26 changes: 20 additions & 6 deletions raftos/cryptor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import base64

from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

from .conf import config

try:
from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
except ImportError:
config.crypto_enabled = False


class Cryptor:
def __init__(self):
Expand All @@ -26,4 +29,15 @@ def decrypt(self, data):
return self.f.decrypt(data)


cryptor = Cryptor()
class DummyCryptor:
def encrypt(self, data):
return data

def decrypt(self, data):
return data


if config.crypto_enabled:
cryptor = Cryptor()
else:
cryptor = DummyCryptor()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup


__version__ = '0.2.3'
__version__ = '0.2.4'

short_description = 'Raft replication in Python'
requirements = [req.strip() for req in open('requirements.txt').readlines()]
Expand Down

0 comments on commit 53bb512

Please sign in to comment.