diff --git a/Makefile b/Makefile index 3fd7fcd..afd9c6c 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,7 @@ clean-test: ## remove test and coverage artifacts lint: ## check style with flake8 flake8 src tests + pylint src tests/* test: install ## run tests quickly with the default Python py.test tests diff --git a/docs/asymmetric.rst b/docs/asymmetric.rst index a57dcc6..bc1d21c 100644 --- a/docs/asymmetric.rst +++ b/docs/asymmetric.rst @@ -20,8 +20,7 @@ RSA :members: :inherited-members: -Example -~~~~~~~ +**Example:** >>> from wolfcrypt.ciphers import RsaPrivate, RsaPublic >>> from wolfcrypt.utils import h2b diff --git a/docs/symmetric.rst b/docs/symmetric.rst index 9c792a9..e4a9fc1 100644 --- a/docs/symmetric.rst +++ b/docs/symmetric.rst @@ -7,17 +7,25 @@ Symmetric Key Algorithms cryptographic key** for both encryption and decryption of data. This operation is also known as **Symmetric Key Encryption**. -``wolfcrypt`` provides access to the following **Symmetric Key Ciphers**: +Symmetric Key Encryption Classes +-------------------------------- + +Interface +~~~~~~~~~ + +All **Symmetric Key Ciphers** available in this module implements the following +interface: + +.. autoclass:: _Cipher + :members: AES ---- +~~~ .. autoclass:: Aes :members: - :inherited-members: -Example -~~~~~~~ +**Example:** .. doctest:: @@ -31,14 +39,12 @@ Example b'now is the time ' Triple DES ----------- +~~~~~~~~~~ .. autoclass:: Des3 :members: - :inherited-members: -Example -~~~~~~~ +**Example:** .. doctest:: diff --git a/src/wolfcrypt/ciphers.py b/src/wolfcrypt/ciphers.py index 5e5fc9b..e47de1e 100644 --- a/src/wolfcrypt/ciphers.py +++ b/src/wolfcrypt/ciphers.py @@ -67,7 +67,7 @@ class _Cipher(object): raise ValueError("key must be %s in length, not %d" % (self._key_sizes, len(key))) elif not key: # pragma: no cover - raise ValueError("key must not be 0 in length") + raise ValueError("key must not be 0 in length") if IV is not None and len(IV) != self.block_size: raise ValueError("IV must be %d in length, not %d" % @@ -101,10 +101,10 @@ class _Cipher(object): """ Encrypts a non-empty string, using the key-dependent data in the object, and with the appropriate feedback mode. - + The string's length must be an exact multiple of the algorithm's block size or, in CFB mode, of the segment size. - + Returns a string containing the ciphertext. """ string = t2b(string) @@ -130,10 +130,10 @@ class _Cipher(object): """ Decrypts **string**, using the key-dependent data in the object and with the appropriate feedback mode. - + The string's length must be an exact multiple of the algorithm's block size or, in CFB mode, of the segment size. - + Returns a string containing the plaintext. """ string = t2b(string) @@ -436,7 +436,7 @@ class EccPublic(_Ecc): ret = _lib.wc_ecc_export_x963(self.native_object, x963, x963_size) if ret != 0: # pragma: no cover - raise WolfCryptError("x963 export error (%d)" % ret) + raise WolfCryptError("x963 export error (%d)" % ret) return _ffi.buffer(x963, x963_size[0])[:] diff --git a/tests/test_ciphers.py b/tests/test_ciphers.py index d7190bc..48c7572 100644 --- a/tests/test_ciphers.py +++ b/tests/test_ciphers.py @@ -308,7 +308,7 @@ def test_ecc_make_shared_secret(): b_pub = EccPublic() b_pub.import_x963(b.export_x963()) - assert a.shared_secret(b) == \ - b.shared_secret(a) == \ - a.shared_secret(b_pub) == \ - b.shared_secret(a_pub) + assert a.shared_secret(b) \ + == b.shared_secret(a) \ + == a.shared_secret(b_pub) \ + == b.shared_secret(a_pub)