secret
A Rune-style type for sensitive values in Python
secret-type provides a convenient type (secret) to indicate that a value is considered sensitive, similar to the secret type in Google's Rune Lang.
Installation
pip install secret-type
Usage
>>> from secret_type import secret
>>> password = secret("a very secret value") # Secrets can be any primitive value
>>> print(password) # Runtime exceptions prevent logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "secret_type/containers/secret.py", line 91, in __str__
raise SecretException()
secret_type.exceptions.SecretException: Secrets cannot be examined
>>> better_password = password + "!" # Operations derive new secrets
>>> >>> type(better_password)
<class 'secret_type.sequence.SecretStr'>
>>> better_password.dangerous_apply(print)
a very secret value!
Features
- When marked as secret, values cannot be printed or logged; attempting to do so will raise an exception.
- Secrets are "viral"; any operation on a secret will also return a secret.
- Comparison operations with a
secretare guaranteed to be constant-time.This helps avoid timing attacks. - A
boolderived from a secret cannot be used for control flow. - Secrets cannot be used as indexes or keys for containers.
- Internally, the underlying value is stored encrypted in memory, and is only decrypted when deriving a new value.
- As soon as secrets are out of scope, the Garbage Collector is encouraged to immediately collect them.
Docs
For complete docs, see the Quickstart.
Comparison to Rune
Rune makes the following guarantees about a secret:
- All operations on secrets occur in constant time, minimizing timing side-channel leakage.
- Secrets cannot be used in conditional branches or memory addressing.
- Even speculative branching and indexing on secrets are caught at compile-time to avoid Specter/Meltdown.
- Secrecy is sticky: any value in part derived from a secret is considered secret until "revealed".
- Secrets are automatically zeroed when no longer used
This projects attempts to do something similar, but with the runtime constraints of Python.
License
secret-type is distributed under the terms of the MIT license.
Metadata
Release files for secret-type 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| secret_type-0.3.0.tar.gz | 15.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| secret_type-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / secret_type-0.3.0.tar.gz
| Download URL | secret_type-0.3.0.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cda5a9d6b47eb963a9a70431165759cbb90d4260b13a0649d6fdffc74c2f7ff
|
|
BLAKE2b-256 checksum How to use checksums |
10f3460f413c1a711282ea751490126cfee13bd1be3ab482557365c85370ada4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.23.1
|
Release files / secret_type-0.3.0-py3-none-any.whl
| Download URL | secret_type-0.3.0-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44aa14b99fd274b7f58d3a3ea7ec42f96833f2e190464e85c2c903805b4f471c
|
|
BLAKE2b-256 checksum How to use checksums |
15b5e9c55a2ec41644bbc1b386e535a7c2dc56fd82015df68f2d1e9c76601419
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.23.1
|
Security for secret-type 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.