Skip to content

Commit 6a7b00e

Browse files
committed
Initial release
0 parents  commit 6a7b00e

11 files changed

Lines changed: 558 additions & 0 deletions

File tree

.gitignore

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
4+
5+
### Python ###
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
.DS_Store
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
*.py,cover
55+
.hypothesis/
56+
.pytest_cache/
57+
cover/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
.pybuilder/
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# IPython
87+
profile_default/
88+
ipython_config.py
89+
90+
# pyenv
91+
# For a library or package, you might want to ignore these files since the code is
92+
# intended to run in multiple environments; otherwise, check them in:
93+
# .python-version
94+
95+
# pipenv
96+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
98+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
99+
# install all needed dependencies.
100+
#Pipfile.lock
101+
102+
# poetry
103+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104+
# This is especially recommended for binary packages to ensure reproducibility, and is more
105+
# commonly ignored for libraries.
106+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107+
#poetry.lock
108+
109+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
110+
__pypackages__/
111+
112+
# Celery stuff
113+
celerybeat-schedule
114+
celerybeat.pid
115+
116+
# SageMath parsed files
117+
*.sage.py
118+
119+
# Environments
120+
.env
121+
.venv
122+
env/
123+
venv/
124+
ENV/
125+
env.bak/
126+
venv.bak/
127+
128+
# Spyder project settings
129+
.spyderproject
130+
.spyproject
131+
132+
# Rope project settings
133+
.ropeproject
134+
135+
# mkdocs documentation
136+
/site
137+
138+
# mypy
139+
.mypy_cache/
140+
.dmypy.json
141+
dmypy.json
142+
143+
# Pyre type checker
144+
.pyre/
145+
146+
# pytype static type analyzer
147+
.pytype/
148+
149+
# Cython debug symbols
150+
cython_debug/
151+
152+
# PyCharm
153+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
154+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
155+
# and can be added to the global gitignore or merged into this file. For a more nuclear
156+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
157+
.idea/
158+
159+
# End of https://www.toptal.com/developers/gitignore/api/python

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.0.1
4+
5+
* Initial release.

Dependencies.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# External Dependencies
2+
3+
This file lists the dependencies used in this repository.
4+
5+
| Dependency | License |
6+
| --------------------- | ---------- |
7+
|PyNaCl@1.5.0 | Apache 2 |

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
Copyright 2022 Optomate Technologies Private Limited.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
![](https://img.shields.io/badge/Licence-MIT-green.svg)![](https://shields.io/badge/python-+3.6-blue)
2+
3+
# Databridges Python NaCl Wrapper Library
4+
5+
Databridges NACL wrapper gives you a simple write and read function using implementation of the secretbox encryption standard defined in NaCl.
6+
7+
Databridges NACL wrapper is available for
8+
9+
- [JavaScript](https://github.com/databridges-io/lib.javascript.nacl.wrapper.git)
10+
- [NodeJS](https://github.com/databridges-io/lib.nodejs.nacl.wrapper.git)
11+
- [C#](https://github.com/databridges-io/lib.csharp.nacl.wrapper.git)
12+
- [Python](https://github.com/databridges-io/lib.python.nacl.wrapper.git)
13+
- [Java for Android](https://github.com/databridges-io/lib.android.nacl.wrapper.git)
14+
- [iOS Swift](https://github.com/databridges-io/lib.ios.nacl.wrapper.git)
15+
16+
The above wrappers can be used to send encrypted messages between them.
17+
18+
> The Databridges NACL wrapper for Python Language binding uses `PyNaCl` to deliver implementation of the secretbox encryption standard defined in NaCl.
19+
20+
## Usage Overview
21+
22+
The following topics are covered:
23+
24+
- [Supported platforms](#supported-platforms)
25+
- [Installation.](#installation)
26+
- [Initialization](#initialization)
27+
- [Global Configuration](#global-configuration)
28+
- [How to use with Databridges Python Library](#how-to-use-with-databridges-python-library)
29+
- [Change Log](#change-log)
30+
- [License](#license)
31+
32+
## Supported platforms
33+
34+
Supports Python versions +3.6
35+
36+
## Installation.
37+
38+
You can use pip package manager to install the package.
39+
40+
```bash
41+
pip3 install databridges_nacl_wrapper
42+
```
43+
44+
## Initialization
45+
46+
```python
47+
from databridges_nacl_wrapper import databridges_nacl_wrapper
48+
secretData = databridges_nacl_wrapper()
49+
```
50+
51+
## Global Configuration
52+
53+
### Required
54+
55+
The following is the required properties before using to dataBridges NaCl wrapper.
56+
57+
```python
58+
secretData.secret = '32 char alphanumeric string';
59+
```
60+
61+
| Properties | Description |
62+
| ---------- | ------------------------------------------------------------ |
63+
| `secret` | *(string)* 32 char alpha numeric string. NaCl encryption secret. |
64+
65+
## Encrypt data
66+
67+
To encrypt data using NaCl, databridges wrapper exposes a method named `write`, This will return encrypted data if successful else it will throw error.
68+
69+
#### write()
70+
71+
```python
72+
try:
73+
encData = secretData.write("Your Data..");
74+
print('Encrypted:', encData);
75+
except Exception as err:
76+
print('Errors:', err.source , err.code , err.message);
77+
```
78+
79+
| Parameter | Description |
80+
| --------- | ---------------------------------- |
81+
| `data` | *(string)* *data* to be encrypted. |
82+
83+
| Return Values | Description |
84+
| ------------- | ------------------ |
85+
| `string` | Encrypted string. |
86+
87+
##### Exceptions:
88+
89+
| Source | Code | Description |
90+
| ------------------ | -------------- | ---------------------------------------------- |
91+
| DBLIB_NACL_WRAPPER | INVALID_SECRET | `secret` is not set with the wrapper instance. |
92+
| DBLIB_NACL_WRAPPER | INVALID_DATA | If `data` is not passed to the function. |
93+
| DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
94+
95+
## Decrypt data
96+
97+
To decrypt data using NaCl, databridges wrapper exposes a method named `read`, This will return decrypted data if successful else it will throw error.
98+
99+
#### read()
100+
101+
```python
102+
try:
103+
decData = secretData.read("<Encrypted data.>")
104+
print('Decrypted:', decData);
105+
except Exception as err:
106+
print("Errors:", err.source, err.code, err.message)
107+
```
108+
109+
| Parameter | Description |
110+
| --------- | ---------------------------------- |
111+
| `data` | *(string)* *data* to be encrypted. |
112+
113+
| Return Values | Description |
114+
| ------------- | ------------------ |
115+
| `string` | Encrypted string. |
116+
117+
##### Exceptions:
118+
119+
| Source | Code | Description |
120+
| ------------------ | ------------------- | ------------------------------------------------------------ |
121+
| DBLIB_NACL_WRAPPER | INVALID_SECRET | `secret` is not set with the wrapper instance. |
122+
| DBLIB_NACL_WRAPPER | INVALID_DATA | If `data` is not passed to the function OR `data` is not a valid encrypted string. |
123+
| DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
124+
| DBLIB_NACL_WRAPPER | NACL_DECRYPT_FAILED | If decryption fails due to invalid secret or manipulated data. |
125+
126+
127+
128+
## How to use with Databridges Python Library
129+
130+
Below code shows how to integrate the NaCl wrapper with the Databridges library. After initialize you can use the wrapper library to encrypt and decrypt the data when publishing and receiving events.
131+
132+
```python
133+
# Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
134+
from databridges_sio_client_lib import dBridges
135+
from databridges_sio_client_lib.exceptions import dBError
136+
from databridges_nacl_wrapper import databridges_nacl_wrapper
137+
138+
dbridge = dBridges()
139+
secretData = databridges_nacl_wrapper()
140+
secretData.secret = "Your32 char secret.";
141+
142+
# .... Your databridges code comes here.
143+
144+
# On Subscription success event.
145+
async def on_SubscribeChannel(payload, metadata):
146+
try:
147+
# Encrypt data to publish
148+
encData = secretData.write('Your Data..')
149+
await self.subscribeChannel.publish('eventName', encData, 1)
150+
except Exception as err:
151+
print("Error: ", err.source, err.code, err.message)
152+
153+
self.subscribeChannel.bind("dbridges:subscribe.success", on_SubscribeChannel)
154+
155+
# On payload Received event.
156+
async def on_EventReceived(payload, metadata):
157+
try:
158+
decData = secretData.read(payload)
159+
print('Decrypted:', decData);
160+
except Exception as err:
161+
print("Error: ", err.source, err.code, err.message)
162+
163+
self.subscribeChannel.bind("eventName", on_EventReceived)
164+
```
165+
166+
167+
168+
## Change Log
169+
* [Change log](CHANGELOG.md): Changes in the recent versions
170+
171+
## License
172+
173+
DataBridges NaCl Wrapper is released under the [MIT license](LICENSE).
174+
175+
```
176+
Copyright 2022 Optomate Technologies Private Limited.
177+
178+
Permission is hereby granted, free of charge, to any person obtaining
179+
a copy of this software and associated documentation files (the
180+
"Software"), to deal in the Software without restriction, including
181+
without limitation the rights to use, copy, modify, merge, publish,
182+
distribute, sublicense, and/or sell copies of the Software, and to
183+
permit persons to whom the Software is furnished to do so, subject to
184+
the following conditions:
185+
186+
The above copyright notice and this permission notice shall be
187+
included in all copies or substantial portions of the Software.
188+
189+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
190+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
191+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
192+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
193+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
194+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
195+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
196+
```
197+

0 commit comments

Comments
 (0)