diff options
author | drebs <drebs@leap.se> | 2013-01-24 11:58:56 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-01-24 11:58:56 -0200 |
commit | 2f761fea9e72554806b012c64d00fcae80e1d254 (patch) | |
tree | 74d564de2d5abd1a15c2e953598f2ce1c70a3f12 /__init__.py | |
parent | 67a3919aea0908db3cefca0af2a8603f576c9ae1 (diff) |
Source files stick to pep8.
Diffstat (limited to '__init__.py')
-rw-r--r-- | __init__.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/__init__.py b/__init__.py index 26e982ba..c83627f0 100644 --- a/__init__.py +++ b/__init__.py @@ -10,12 +10,13 @@ from leap.soledad.backends import sqlcipher from leap.soledad.util import GPGWrapper import util + class Soledad(object): # paths - PREFIX = os.environ['HOME'] + '/.config/leap/soledad' - SECRET_PATH = PREFIX + '/secret.gpg' - GNUPG_HOME = PREFIX + '/gnupg' + PREFIX = os.environ['HOME'] + '/.config/leap/soledad' + SECRET_PATH = PREFIX + '/secret.gpg' + GNUPG_HOME = PREFIX + '/gnupg' LOCAL_DB_PATH = PREFIX + '/soledad.u1db' # other configs @@ -47,7 +48,8 @@ class Soledad(object): def _has_secret(self): """ - Verify if secret for symmetric encryption exists on local encrypted file. + Verify if secret for symmetric encryption exists on local encrypted + file. """ # TODO: verify if file is a GPG-encrypted file and if we have the # corresponding private key for decryption. @@ -61,16 +63,20 @@ class Soledad(object): """ try: with open(self.SECRET_PATH) as f: - self._secret = str(self._gpg.decrypt(f.read())) + self._secret = str(self._gpg.decrypt(f.read())) except IOError as e: - raise IOError('Failed to open secret file %s.' % self.SECRET_PATH) + raise IOError('Failed to open secret file %s.' % self.SECRET_PATH) def _gen_secret(self): """ - Generate a secret for symmetric encryption and store in a local encrypted file. + Generate a secret for symmetric encryption and store in a local + encrypted file. """ - self._secret = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(self.SECRET_LENGTH)) - ciphertext = self._gpg.encrypt(self._secret, self._fingerprint, self._fingerprint) + self._secret = ''.join(random.choice(string.ascii_uppercase + + string.digits) for x in + range(self.SECRET_LENGTH)) + ciphertext = self._gpg.encrypt(self._secret, self._fingerprint, + self._fingerprint) f = open(self.SECRET_PATH, 'w') f.write(str(ciphertext)) f.close() @@ -95,11 +101,11 @@ class Soledad(object): Generate an OpenPGP keypair for this user. """ params = self._gpg.gen_key_input( - key_type='RSA', - key_length=4096, - name_real=self._user_email, - name_email=self._user_email, - name_comment='Generated by LEAP Soledad.') + key_type='RSA', + key_length=4096, + name_real=self._user_email, + name_email=self._user_email, + name_comment='Generated by LEAP Soledad.') self._gpg.gen_key(params) def _load_openpgp_keypair(self): @@ -124,7 +130,8 @@ class Soledad(object): Encrypt data. """ return str(self._gpg.encrypt(data, self._fingerprint, sign=sign, - passphrase=passphrase, symmetric=symmetric)) + passphrase=passphrase, + symmetric=symmetric)) def encrypt_symmetric(self, doc_id, data, sign=None): """ @@ -203,4 +210,3 @@ class Soledad(object): return self._db.sync(url, creds=None, autocreate=True, soledad=self) __all__ = ['util'] - |