-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kushaldas/cleaning_up_api
Cleaning up api
- Loading branch information
Showing
7 changed files
with
262 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
API Documentation | ||
================== | ||
|
||
For the rest of the documentation we assume that you imported the module as following. | ||
|
||
:: | ||
|
||
|
||
>>> import johnnycanencrypt as jce | ||
|
||
|
||
.. function:: newkey(password, userid) | ||
|
||
Use the `newkey` function in the module to create a new keypair. It takes two arguments as str, a password, and userid. | ||
By default it creates the key with RSA4096, and returns a tuple of public,secret key as str. Raises `FileNotFound` error | ||
if the key file can not be accessed. | ||
|
||
:: | ||
|
||
>>> public, secret = jce.newkey("my super secret password using diceware", "test <[email protected]>") | ||
|
||
|
||
.. note:: Remember to save both the public and serect keys in a file to use in future. | ||
|
||
|
||
.. class:: Johnny(filepath) | ||
|
||
It creates an object of type `Johnny`, you can provide path to the either public key, or the private key based on the operation | ||
you want to do. | ||
|
||
.. method:: encrypt_bytes(data: bytes, armor=False) | ||
|
||
This method encrypts the given bytes and returns the encrypted bytes. If you pass `armor=True` to the method, then the | ||
returned value will be ascii armored bytes. | ||
|
||
:: | ||
|
||
>>> j = jce.Johnny("tests/files/public.asc") | ||
>>> enc = j.encrypt_bytes(b"mysecret", armor=True) | ||
|
||
|
||
.. method:: encrypt_file(inputfile: bytes, output: bytes, armor=False) | ||
|
||
This method encrypts the given inputfile and writes the raw encrypted bytes to the output path. If you pass `armor=True` to the method, then the | ||
output file will be written as ascii armored. | ||
|
||
:: | ||
|
||
>>> j = jce.Johnny("tests/files/public.asc") | ||
>>> enc = j.encrypt_file(b"blueleaks.tar.gz", b"notblueleaks.tar.gz.pgp", armor=True) | ||
|
||
|
||
.. method:: decrypt_bytes(data: bytes, password: str) | ||
|
||
Decrypts the given bytes based on the secret key and given password. If you try to decrypt while just using the public key, | ||
then it will raise `AttributeError`. | ||
|
||
:: | ||
|
||
>>> jp = jce.Johnny("tests/files/secret.asc") | ||
>>> result = jp.decrypt_bytes(enc, "redhat") | ||
|
||
|
||
.. method:: decrypt_file(inputfile: bytes, output: bytes, password: str) | ||
|
||
Decrypts the inputfile path (in bytes) and wrties the decrypted data to the `output` file. Both the filepaths to be given as bytes. | ||
|
||
:: | ||
|
||
>>> jp = jce.Johnny("tests/files/secret.asc") | ||
>>> result = jp.decrypt_file(b"notblueleaks.tar.gz.pgp", "blueleaks.tar.gz", "redhat") | ||
|
||
|
||
.. method:: sign_bytes_detached(data: bytes, pasword: str) | ||
|
||
Signs the given bytes and returns the detached ascii armored signature as bytes. | ||
|
||
:: | ||
|
||
>>> j = jce.Johnny("tests/files/secret.asc") | ||
>>> signature = j.sign_bytes_detached(b"mysecret", "redhat") | ||
|
||
.. note:: Remember to save the signature somewhere on disk. | ||
|
||
.. method:: verify_bytes(data: bytes, signature: bytes) | ||
|
||
Verifies if the signature is correct for the given data (as bytes). Returns `True` or `False`. | ||
|
||
:: | ||
|
||
>>> j = jce.Johnny("tests/files/secret.asc") | ||
>>> j.verify_bytes(encrypted_bytes, signature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Building Johnny Can Encrypt | ||
============================ | ||
|
||
Building this module requires Rust's nightly toolchain. You can install it following | ||
the instructions from `rustup.rs <https://rustup.rs>`_. | ||
|
||
You will need `libnettle` and `libnettle-dev` & `clang` (on Debian/Ubuntu) and `nettle` & `nettle-dev` & `clang` packages in Fedora. | ||
|
||
Then you can follow the steps below to build a wheel. | ||
|
||
:: | ||
|
||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
python3 -m pip install requirements-dev.txt | ||
maturin build | ||
|
||
Only to build and test locally, you should execute | ||
|
||
:: | ||
|
||
maturin develop | ||
|
||
## How to run the tests? | ||
|
||
After you did the `maturin develop` as mentioned above, execute the following command. | ||
|
||
:: | ||
|
||
python3 -m pytest -vvv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.