summaryrefslogtreecommitdiff
path: root/src/leap/soledad/crypto.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-06-03 17:10:15 -0300
committerdrebs <drebs@leap.se>2013-06-05 12:43:06 -0300
commitf4561f3462d8a265f11811d65c4b50db1dd61b45 (patch)
treee2080dfba740eb860b4b079e65a6a63f2d30771b /src/leap/soledad/crypto.py
parent3462abf72b9057855fe7e1b92b12f04bdbd67537 (diff)
Remove strict dependency on leap.common.
* Encapsulate leap_assert and leap_assert_type so Soledad works without them. * Remove dependency on leap.common.files.mkdir_p(). * Encapsulate signaling. * Add changes file.
Diffstat (limited to 'src/leap/soledad/crypto.py')
-rw-r--r--src/leap/soledad/crypto.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/leap/soledad/crypto.py b/src/leap/soledad/crypto.py
index e3d2c30c..be83e4a2 100644
--- a/src/leap/soledad/crypto.py
+++ b/src/leap/soledad/crypto.py
@@ -26,9 +26,15 @@ import binascii
import hmac
import hashlib
+
from Crypto.Cipher import AES
from Crypto.Util import Counter
-from leap.common.check import leap_assert, leap_assert_type
+
+
+from leap.soledad import (
+ soledad_assert,
+ soledad_assert_type,
+)
class EncryptionMethods(object):
@@ -85,13 +91,14 @@ class SoledadCrypto(object):
@return: A tuple with the initial value and the encrypted data.
@rtype: (long, str)
"""
- leap_assert_type(key, str)
+ soledad_assert_type(key, str)
# AES-256 in CTR mode
if method == EncryptionMethods.AES_256_CTR:
- leap_assert(
+ soledad_assert(
len(key) == 32, # 32 x 8 = 256 bits.
- 'Wrong key size: %s bits (must be 256 bits long).' % (len(key)*8))
+ 'Wrong key size: %s bits (must be 256 bits long).' %
+ (len(key) * 8))
iv = os.urandom(8)
ctr = Counter.new(64, prefix=iv)
cipher = AES.new(key=key, mode=AES.MODE_CTR, counter=ctr)
@@ -119,15 +126,15 @@ class SoledadCrypto(object):
@return: The decrypted data.
@rtype: str
"""
- leap_assert_type(key, str)
+ soledad_assert_type(key, str)
# AES-256 in CTR mode
if method == EncryptionMethods.AES_256_CTR:
# assert params
- leap_assert(
+ soledad_assert(
len(key) == 32, # 32 x 8 = 256 bits.
'Wrong key size: %s (must be 256 bits long).' % len(key))
- leap_assert(
+ soledad_assert(
'iv' in kwargs,
'AES-256-CTR needs an initial value given as.')
ctr = Counter.new(64, prefix=binascii.a2b_base64(kwargs['iv']))