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

pip install pycdoc

Requirements

Runtime

  • Python 3.9+
  • OpenSSL 3.0+ (usually pre-installed on modern systems)

Building from Source

Building from source requires:

  • Python 3.9+
  • CMake 3.18+
  • SWIG 4.0+
  • OpenSSL 3.0+
  • 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:

pip install 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:
git clone https://github.com/namespace-ee/pycdoc.git
cd pycdoc
  1. Clone libcdoc:
git clone https://github.com/open-eid/libcdoc.git
  1. Build the wheel:
pip install build
python -m build --wheel
  1. Install the wheel:
pip install dist/pycdoc-*.whl

Development

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install build dependencies
pip install build scikit-build-core swig

# Build wheel
python -m build --wheel

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

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.0.tar.gz (27.6 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.0-cp313-cp313-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.13Windows x86-64

pycdoc-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pycdoc-0.1.0-cp313-cp313-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pycdoc-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pycdoc-0.1.0-cp312-cp312-macosx_15_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pycdoc-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 15.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pycdoc-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10macOS 15.0+ ARM64

pycdoc-0.1.0-cp39-cp39-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.9Windows x86-64

pycdoc-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

pycdoc-0.1.0-cp39-cp39-macosx_15_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.9macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: pycdoc-0.1.0.tar.gz
  • Upload date:
  • Size: 27.6 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.0.tar.gz
Algorithm Hash digest
SHA256 1833ce26f0bac46c759b8d8cea537eea8d2ea4fd79e69817890ce36bd492094d
MD5 c91348637ff0e8107112fd1786ca89b3
BLAKE2b-256 9b51e97bf6ffd12fe13e2a546aabe3c4c170ecb8bfa5f841dfbb44f4c50b1e8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0.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.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 56371370e8ae69972102d0c65b6dfeff0ca7d6884dd861324d6b2fad03f3079c
MD5 deb7d361541da81f97fe04f20a094080
BLAKE2b-256 cdc9da4c7a14dc111e9fe25f273f028af8c7a0c291d3657e83fd5982c80ff2df

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 196c3dca6b5aef45165c974f1d53636cc37707a9fa272ef8826558af680e1bea
MD5 07fa9363879bc84a092b2a271d78cf12
BLAKE2b-256 71184baa546f2ad33d0a889c10c434df1e46b57c23fcd1e77b60769e4e69f848

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cb3455018b7051e99ef600dad6d33bc6ae7345aa949cf7c860fb8ad569802fd3
MD5 43b0f7bf25a941635cabb156f91faa4a
BLAKE2b-256 b559687b6de0760d621ea1e38e1930f71ab5a5bf4a375f7410430705e30f65f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ff98fc39b34072d1fbf29a0a9176618734b42892718c5cf72844847b945fda6c
MD5 525695beae3234ab7f459207f1a38f43
BLAKE2b-256 f11d09809a24a05c4eb117a6370003dbe731f8253d9117bce34328dd2d0fca00

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8647fe1c0179a9da12a621491eaa6b8473f3f5ba0c1c908fe8f346b0b0e37840
MD5 982486cac7a0776f3128d8d5585af136
BLAKE2b-256 047ae2715c98c2e97efbabd712a89f4feec65993e7171bf9e3f01103445c527c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7302d7dd2b2f0c3e363690be4c85f822a25056134682613e443e2fe332090ed5
MD5 a1bf1c3e42458970c6def71d5c4d89aa
BLAKE2b-256 b1e2302fe67ddeb29871cfd5ae92f2b6de25558e53f5fd8d128b85014d52c07b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.0-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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6687a186eb22c675709904bf664f996728763f12c5bc93ab4accf058d785168f
MD5 cb306a2192b6abc429e37a05f88cf5e2
BLAKE2b-256 958e9804638c9639ff757407bcf196976a94e7cd5dba2e8db97979bc39d1b1a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18ba3f8bd5e997fc121e3ff1ac20899db4e4d54a6799380a6b06cf28f6c5fc79
MD5 631a946f603f88dc6ad9458fa9074a21
BLAKE2b-256 8c5088cdd6a59ea537e8446f9eaad1eb811444b6bd16d7746ca5bd14e6664972

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d9bef259aa5f766fc7a538b337453fa1ded63c5bd4ec3094f42c0ea16dfdfae8
MD5 818676d3fe610344e6325dceb2e32ddc
BLAKE2b-256 4b479fc3c611eb09ea2a77c09c1e13e980537f4999c3ebdaf6eb081e4a819f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.0-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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 86c8ea732ac65dfb79c7377cce7ec9d51a9148d3d9bf9b4d53a93a05ab8e91bf
MD5 431abbc99a898553631e01f2ee58c327
BLAKE2b-256 ccbb2aa8e36d8a61a3f64913eefe7255abd7f0fdf2be6d2e3ccabd94eb5dcd92

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a744563aeb711f30714ed129b1efd1015290957d2c63d81718153e015f27105d
MD5 48b5ed1bb9c7bb798cbc6b3025ffcdeb
BLAKE2b-256 3c5c8bc8d6935e912d319b78149bca3d77bc22dfd8215e2dee4346cdf286c3b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c7a20395e492ca58f6117e9280741fb10888f59ce9be51afa9d6bd3d1ab181d3
MD5 b120c9609d2380c4442f57152e267d30
BLAKE2b-256 3dcfb4f1ffb8460ec081f56bb2c590a8ed2e1f583e170769256dee51ba39acbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-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.

File details

Details for the file pycdoc-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pycdoc-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.9, 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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 663a448b4e793d9deb3c0c0ffd78d324254d41377675a35a73c26732b9ea4d4f
MD5 97b91aed10d8ecef3e930cb8fd96c563
BLAKE2b-256 6b1b800158ef7b942d2a903af3912056b42bb826412a6cf88cf1844e11f279e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-cp39-cp39-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.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a2f7f1a75e766b13b087597b0abd542e5596fce13e3a842b4df999429a80a386
MD5 7d0626e7ce25866ce53963ad15c2fa12
BLAKE2b-256 39220a098a531a93f072cea5dca9767674ef4318b4817426c722030bcb0eacbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-cp39-cp39-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.0-cp39-cp39-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pycdoc-0.1.0-cp39-cp39-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bb8508228a5f61b8058be3bbbc26f47f576b8317207f247455f856bb35bb5ab6
MD5 0510f3fcb8912d67ed201fe78bdbb9ad
BLAKE2b-256 8c3efe710ec2c2431902b2536fb2efa9e517b5ace747d1a02ec2b2e78bc0e007

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycdoc-0.1.0-cp39-cp39-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