Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webtechnicom API #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@

# coverage
.coverage

.fake
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
838 changes: 838 additions & 0 deletions =3.6

Large diffs are not rendered by default.

Empty file added =42
Empty file.
4 changes: 4 additions & 0 deletions Encrypt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for: cannot open `for' (No such file or directory)
DIDWW: cannot open `DIDWW' (No such file or directory)
API: cannot open `API' (No such file or directory)
3: cannot open `3' (No such file or directory)
134 changes: 2 additions & 132 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,2 @@
# DIDWW Encrypt Python 3 SDK

[![github_actions](https://github.com/didww/didww_encrypt_python/actions/workflows/tests.yml/badge.svg)](https://github.com/didww/didww_encrypt_python/actions)
[![codecov](https://codecov.io/gh/didww/didww_encrypt_python/branch/main/graph/badge.svg)](https://codecov.io/gh/didww/didww_encrypt_python)

This is Python 3 module and CLI to encrypt file for DIDWW API 3.

File encrypted with mode `sandbox` could be uploaded to `POST https://sandbox-api.didww.com/v3/encrypted_files`.

File encrypted with mode `production` could be uploaded to `POST https://api.didww.com/v3/encrypted_files`.

see [DIDWW Documentation](https://doc.didww.com) for details.

## Requirements

Python `>=3.6`

## Dependencies

[PyCryptodomex](https://pypi.org/project/pycryptodomex/)

## Install

```shell
pip install didww_encrypt
```

## Usage

### Inside python
```python
from didww_encrypt import Encrypt, MODE_PRODUCTION


with open("doc.pdf", mode="rb") as f:
data = f.read()

enc = Encrypt.new(MODE_PRODUCTION)
enc_data = enc.encrypt(data)
enc_filename = "doc.pdf.enc"
with open(enc_filename, mode="wb") as f:
f.write(enc_data)

print(f"encrypted file saved: {enc_filename}")
print(f"fingerprint: {enc.fingerprint}")
```

### Shell

```
usage: didww_encrypt [-h] [-i [INPUT]] [-o [OUTPUT]] [-f] (-m [{sandbox,production}] | -u [URI])

Encrypt file for DIDWW API 3

optional arguments:
-h, --help show this help message and exit
-i [INPUT], --input [INPUT]
use input pipe when not passed
-o [OUTPUT], --output [OUTPUT]
use output pipe when not passed
-f, --fingerprint return fingerprint for public keys
-m [{sandbox,production}], --mode [{sandbox,production}]
which DIDWW server use for public keys fetching
-u [URI], --uri [URI]
custom URI for public keys fetching
```

You can pass input and output files as params
```shell
$ didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m sandbox
```

Or using pipe
```shell
$ cat ./doc.pdf | didww_encrypt -m production > ./doc.pdf.enc
```

Also script could be run via `python -m`
```shell
$ python -m didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m production
$ cat ./doc.pdf | python -m didww_encrypt -m sandbox > ./doc.pdf.enc
```

To print fingerprint use `-f` option instead of `-i`
```shell
$ didww_encrypt -f -m sandbox
c74684d7863639169c21c4d04747f8d6fa05cfe3:::7c56fd5d2e1f2ada18765d936e74712037aea7eb
```

Or you can save it to a file
```shell
$ didww_encrypt -f -m sandbox -o fingerprint.txt
```

**Keep in mind** that shell script returns fingerprint with newline which should be omitted when send it to `/v3/encrypted_files`.

## Additional information

both shell script and module function `Encrypt.new` respects `http_proxy` env variable when fetching public keys.

```shell
http_proxy="http://myproxy.example.com:1234" didww_encrypt -m sandbox
```

## Development

### Install dependencies

```shell
pip install -r requirements.txt
pip install -r tests/requirements.txt
```

### Run tests
```shell
python -m unittest -v
```

### Run tests with coverage
```shell
coverage run -m unittest -v
```

### Lint with flake8
```shell
flake8 . --count --show-source --statistics
```

### Fix code format with Black
```shell
black .
```
# didww_encrypt_python
File encryption for DIDWW API 3
Binary file added doc.pdf.enc
Binary file not shown.
1 change: 1 addition & 0 deletions fingerprint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
66b91934f62a92153c2e86d87e6599703aa82051:::9c82ff6d35e15691c8d8f5a9d297ef5f5b4c1ba5