Skip to main content

Python bindings for libcdoc - read and write encrypted CDOC containers

Project description

pycdoc

Python bindings for libcdoc - a library for reading and writing encrypted CDOC containers.

CDOC is a file format for encrypting documents, used primarily in Estonia for secure document exchange with the Estonian ID-card ecosystem.

Installation

uv add pycdoc

Requirements

Runtime

  • Python 3.10+
  • OpenSSL 3.5+ (usually pre-installed on modern systems)

Building from Source

Building from source requires:

  • Python 3.10+
  • CMake 3.20+
  • SWIG 4.0+
  • OpenSSL 3.5+
  • libxml2
  • zlib
  • FlatBuffers
  • C++23 compatible compiler

macOS:

brew install cmake swig openssl@3 libxml2 flatbuffers

Ubuntu/Debian:

sudo apt install cmake swig libssl-dev libxml2-dev zlib1g-dev libflatbuffers-dev

Fedora/RHEL:

sudo dnf install cmake swig openssl-devel libxml2-devel zlib-devel flatbuffers-devel

Quick Start

Install with LDAP support for certificate lookup:

uv add "pycdoc[ldap]"

Encrypting Files

import pycdoc

# Encrypt a file for an Estonian ID card holder
pycdoc.encrypt("document.pdf", "38607080247", output="encrypted.cdoc")

# Get CDOC as bytes instead of writing to file
cdoc_bytes = pycdoc.encrypt("document.pdf", "38607080247")

# Encrypt raw bytes
pycdoc.encrypt(b"secret content", "38607080247", filename="secret.txt", output="encrypted.cdoc")

# Encrypt multiple files into one container
pycdoc.encrypt(["file1.pdf", "file2.docx"], "38607080247", output="bundle.cdoc")

The recipient can decrypt with DigiDoc4 Client or cdoc-tool.

API Overview

Core Classes

  • CDocReader - Read and decrypt CDOC containers
  • CDocWriter - Create and encrypt CDOC containers

Configuration

  • Configuration - Base configuration class (can be subclassed)
  • JSONConfiguration - JSON file-based configuration

Backends

  • CryptoBackend - Cryptographic operations backend (can be subclassed)
  • NetworkBackend - Network operations backend for key servers
  • PKCS11Backend - PKCS#11 hardware token backend (smart cards, HSMs)

Data Types

  • Recipient - Encryption recipient information
  • Lock - Decryption lock information
  • FileInfo - File metadata (name, size)
  • DataSource - Abstract data source for streaming
  • DataConsumer - Abstract data consumer for streaming

Result Codes

  • OK - Operation successful
  • WRONG_KEY - Incorrect decryption key
  • DATA_FORMAT_ERROR - Invalid container format
  • CRYPTO_ERROR - Cryptographic operation failed
  • PKCS11_ERROR - PKCS#11/smart card error

Use pycdoc.get_error_str(code) to get human-readable error descriptions.

Building from Source

  1. Clone the repository with submodules:
git clone --recurse-submodules https://github.com/namespace-ee/pycdoc.git
cd pycdoc
  1. Build the wheel:
uv build --wheel
  1. Install the wheel:
uv pip install dist/pycdoc-*.whl

Development

# Build wheel
uv build --wheel

# Install in development mode (rebuild required after changes)
uv pip install --force-reinstall dist/pycdoc-*.whl

# Run tests
uv run pytest tests/ -v

License

This library is licensed under the GNU Lesser General Public License v2.1 or later (LGPL-2.1-or-later).

See LICENSE for the full license text.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycdoc-0.1.1.tar.gz (460.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycdoc-0.1.1-cp314-cp314-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.14Windows x86-64

pycdoc-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

pycdoc-0.1.1-cp314-cp314-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

pycdoc-0.1.1-cp313-cp313-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.13Windows x86-64

pycdoc-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pycdoc-0.1.1-cp313-cp313-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pycdoc-0.1.1-cp312-cp312-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.12Windows x86-64

pycdoc-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pycdoc-0.1.1-cp312-cp312-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pycdoc-0.1.1-cp311-cp311-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.11Windows x86-64

pycdoc-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pycdoc-0.1.1-cp311-cp311-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pycdoc-0.1.1-cp310-cp310-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10Windows x86-64

pycdoc-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pycdoc-0.1.1-cp310-cp310-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pycdoc-0.1.1.tar.gz.

File metadata

  • Download URL: pycdoc-0.1.1.tar.gz
  • Upload date:
  • Size: 460.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e729af42daf77dcd2190dd087d403286aabd29edcdf44a460c3afacc08683571
MD5 ccaee636b5131795acf7bc3ccaeabcc3
BLAKE2b-256 5a63ea242b44bbcd48bc332df84434d398a4dc59043aefb1b7ba329d3308e9a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1.tar.gz:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c12fda215a9ebcd65befc790e6fc9109780dff65a31462a7bb142640ff624a2e
MD5 118321eb55de3893e93fcd186af4c2c5
BLAKE2b-256 cabd5dea68ad8e06a8347eaa5219358fadbc24113da519e356026b0d42806f11

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp314-cp314-win_amd64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcb6f847d94380285aa2f2ad219bf613561ae03416e749cd2a1ec48cd09735bd
MD5 369cb54ee0c32a3aab26fbc66c1bd2f6
BLAKE2b-256 dcb8b0acca7ed5e771141e6a84f75c00febf3f4d6fcdeb2e5bbc67016846b577

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7db3885eebe4684672f49a924b2b0615004d9c893d6bffe706264366ecb0330d
MD5 f792f1bfe785ff3b52dfb6213a4fb43c
BLAKE2b-256 6741866f2f19dee9e04bec330f70f9cf8c8f0d3e2ac17110e1ca96df74f309ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp314-cp314-macosx_15_0_arm64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c6a860c3da976dbf04402d6a9ba10318ff37b2662e7aeb9822c54dbe38cd7cbc
MD5 85111f4cb1e66c4a1aec2a36424ea48b
BLAKE2b-256 8756e463bcc1a5f373f3ece33ca5f5406830bc3b3b02e64ab01305c083a736ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp313-cp313-win_amd64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 36c8716b5ea2207922450adc66c1abb0f14ccffdd2220791fd7214a2cb0323bf
MD5 ee2bec250451728ca60da38b1f1ae7a4
BLAKE2b-256 f0013a5bcf97b829b35a34b4a273a6a069690d81dbf0e7627aee7c7ed594e67d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3ef121f2314c25d0045b5604bc1c73161f1ca287808edc8e1d4e5a09269197bd
MD5 4ab0cb2d275e80efeaadc44b6b8757b2
BLAKE2b-256 8baf9aca2bd7551f12e3fe45aea5b75630107e2d60a4a4100a50480e086b8e60

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 89c8a186159758a3e3771d440e522a2dac6e870cbc5f73249efecc371626e273
MD5 a07db8c2b7bc6aec85ef2b1bf4e81728
BLAKE2b-256 5840d491ecf3a214d05c534bdd209eb0ce670e3799de7820217e6f0840ab76dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp312-cp312-win_amd64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7603163a8efbe32321263d116195ed7effee64f1df0685dde892083109b390a8
MD5 978b19f96ca034230ed578c95dbdc8d4
BLAKE2b-256 11d74d7f7036e577658c535d6d95195fb4c3b36ecad4e21eea1929d8a6a2fe1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fd9bb3f958d1a55f255eb4da6e7325c6e8e9f4d337eefafb0db9cc399b3487c7
MD5 c242b068b11f0fe780de92f6dfdc230a
BLAKE2b-256 d81adb970515958ded36e77c4618994caa4f509b9d14260ee8b39cecf168c267

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fbebd4acf969c2c682665f3515afbc1a8c8f2bf297071f7a7712c23f5908ae97
MD5 abf966ab4937f5e5bdbbdddcfc1cb917
BLAKE2b-256 1826fbcdf4817abef7fb769a901f1580679b51a28bf2c67433ea36cacf34b0ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp311-cp311-win_amd64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 405de6ea0d5dcd773b82071ec6836ca430dbc6687d1bbe5107b4ea33920004d9
MD5 6f395e99be5fc983256fa093f6baba93
BLAKE2b-256 a921ab5c56eea59efb298b920a47605c3903fa7b3bd3f128facf43ba6cd0dee6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5e53b443722175fa3a0faf546b5ced343157bc4d711975672b248c0c09e78c58
MD5 0e7303cbbc4228ef33a3b073f17d0c33
BLAKE2b-256 bd4704172fdfdd4e294a9da0780560b4453ac05a3dceb56b2dd4b9d44e957882

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycdoc-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 376adbf0eb35c2b5d628065a6615305d0a1b918e1778bfc9e1fadb20ef57afca
MD5 d9e98bbd5f599dc1c58149dfd41e1d43
BLAKE2b-256 05b8b7729e9c8b700e9a540ea5858414e25d7801c2963c54f73d72d1624197a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp310-cp310-win_amd64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1271916c2ebdd44111688d878d68757f1f6cb312f1dc9f50c884c7924b4aa93b
MD5 da8d20e38c657aefc9b2e299736836a8
BLAKE2b-256 f3d2bfcc7131e5a8032ac06010bb2b9cac090dc87141e18c479eff224666ec24

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycdoc-0.1.1-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 11fe109dce8921a4f9e8b9bf6d1055dc9729ebd62e1ccf10f5f5228b5839e5d8
MD5 60ac71da1e8b51cd8dfa33d11fc8b46c
BLAKE2b-256 720934ed391bcf9d9c46e7b0d67ac6ac2d019a1dd3d506a3196c09c8ca6f83bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.1-cp310-cp310-macosx_15_0_arm64.whl:

Publisher: build.yml on namespace-ee/pycdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page