Skip to main content

Crate opentdf

Crate opentdf 

Source
Expand description

OpenTDF - Trusted Data Format for Rust

This crate provides a Rust implementation of the OpenTDF (Trusted Data Format) standard, supporting:

  • Standard TDF (TDF3, ZTDF) with segment-based encryption
  • Attribute-Based Access Control (ABAC) policies
  • Key Access Service (KAS) integration
  • JSON-RPC format (ZTDF-JSON)
  • Security hardening (zeroizing keys, constant-time verification)

§Architecture

  • opentdf-protocol: Protocol types and structures (no crypto)
  • opentdf-crypto: Cryptographic operations with security hardening
  • opentdf: High-level TDF API and integration

§Getting Started

For the best experience, import the prelude to get all commonly used types and traits:

use opentdf::prelude::*;

// Create a policy with the new builder
let policy = PolicyBuilder::new()
    .id_auto()
    .dissemination(["user@example.com"])
    .build()?;

// Encrypt data to a TDF file
Tdf::encrypt(b"sensitive data")
    .kas_url("https://kas.example.com")
    .policy(policy.clone())
    .to_file("output.tdf")?;

// Extension trait methods work automatically with prelude!
let mut manifest = TdfManifest::new("payload".to_string(), "https://kas.example.com".to_string());
manifest.set_policy(&policy)?; // No need to import TdfManifestExt

Re-exports§

pub use fqn::AttributeFqn;
pub use fqn::FqnValidationRules;
pub use fqn::NamespaceRegistry;
pub use kas::CallerKey;
pub use kas::KasClient;
pub use kas::KeyType;
pub use kas_key::KasEcPublicKeyResponse;
pub use kas_key::KasKeyError;
pub use kas_key::KasPublicKeyResponse;
pub use kas_key::fetch_kas_ec_public_key;Deprecated
pub use kas_key::fetch_kas_ec_public_key_connect;
pub use kas_key::fetch_kas_public_key;Deprecated
pub use kas_key::fetch_kas_public_key_connect;
pub use kas_key::validate_ec_public_key_pem;
pub use kas_key::validate_rsa_public_key_pem;
pub use jsonrpc::JsonPayload;
pub use jsonrpc::TdfJson;
pub use jsonrpc::TdfJsonManifest;
pub use jsonrpc::TdfJsonBuilder;
pub use jsonrpc::InlinePayload;Deprecated
pub use jsonrpc::TdfJsonRpc;Deprecated
pub use jsonrpc::TdfJsonRpcBuilder;Deprecated
pub use jsonrpc::TdfManifestInline;Deprecated
pub use hkdf;
pub use p256;
pub use pkcs8;
pub use sha1;
pub use sha2;
pub use ed25519_dalek;

Modules§

fqn
Fully Qualified Name (FQN) support for OpenTDF attributes
jsonrpc
TDF-JSON format implementation (per TDF-JSON specification draft-00)
kas
KAS (Key Access Service) client implementation for OpenTDF rewrap protocol
kas_discovery
KAS endpoint discovery via /.well-known/opentdf-configuration
kas_key
KAS public key retrieval and parsing
manifest
TDF Manifest extension methods
pdp
Local Access Policy Decision Point.
prelude
OpenTDF Prelude

Structs§

AesKey
AES-256 key (32 bytes) that zeroizes on drop
Assertion
A verifiable statement about the TDF or its payload (spec: assertion.md).
AssertionBinding
The binding object of an assertion (spec: assertion_binding.md).
AssertionStatement
The statement object of an assertion (spec: assertion_statement.md).
AttributeCondition
A condition that must be satisfied for access
AttributeIdentifier
Attribute namespace and name
CollectionItem
Collection item containing an encrypted payload with its IV
EcdhKem
ECDH key encapsulation mechanism (NanoTDF)
EncryptedPayload
Encrypted payload structure
EncryptedSegment
One encrypted OpenTDF segment: IV[12] || ciphertext || tag[16].
EncryptionInformation
Encryption information in TDF manifest
EncryptionMethod
Encryption method configuration
GgufIndex
Top-level gguf object on a gguf-tdf/1 manifest.
GgufSegment
One encrypted zip member and its plaintext length.
GgufTensor
One GGUF tensor located in the virtual file.
IntegrityInformation
Integrity information including segments and root signature
KasPolicyBinding
Policy binding for KAS requests
KeyAccess
Key access object in manifest
KeyAccessObject
Key access object details
KeyAccessObjectWrapper
Key access object wrapper
KeyAccessRewrapResult
Individual key access rewrap result
NanoTdfCollection
NanoTDF Collection for encrypting multiple payloads with a shared DEK
NanoTdfCollectionBuilder
Builder for creating NanoTDF collections
NanoTdfCollectionDecryptor
Decryptor for NanoTDF collection items
Payload
Payload reference in TDF manifest
PayloadKey
Payload key (32 bytes) that zeroizes on drop
Policy
Root policy that includes metadata and effective dates
PolicyBinding
Policy binding structure
PolicyBody
Policy body containing attribute requirements and dissemination list
PolicyBuilder
Builder for creating Policy instances with ergonomic defaults
PolicyKey
Policy key (32 bytes) that zeroizes on drop
PolicyRequest
Individual policy request entry
PolicyRewrapResult
Policy rewrap result
RewrapResponse
Rewrap response structure
RootSignature
Root signature for integrity verification
RsaOaepKem
RSA-OAEP key encapsulation mechanism
Segment
Segment information
SegmentInfo
Information about an encrypted segment
SegmentedPayload
Result of segment-based encryption
SignedRewrapRequest
Signed rewrap request wrapper
Tdf
High-level TDF operations
TdfArchive
Reader for a TDF ZIP archive.
TdfArchiveBuilder
TdfArchiveMemoryBuilder
In-memory TDF archive builder for WASM compatibility
TdfDecryptBuilder
Builder for decrypting TDF data
TdfDecryptFileBuilder
Builder for decrypting TDF files
TdfEncryptBuilder
Builder for encrypting data to TDF format
TdfEncryptFileBuilder
Builder for encrypting files to TDF format
TdfEncryption
TDF encryption engine with zeroizing keys
TdfManifest
TDF manifest structure
TdfMemberIndex
Central-directory map from member name to byte range, built once at open.
TdfMemberLocation
Byte range of a Stored zip member’s data, for read_at-style access.
TdfMultiEntryBuilder
Writes a TDF whose payload is many Stored members rather than one concatenated 0.payload, with the manifest written last.
UnsignedRewrapRequest
Unsigned rewrap request structure (before JWT signing)
ValidationError
Attribute-Based Access Control Policy Error Validation error with structured information

Enums§

AttributePolicy
A policy that can be evaluated against a set of attributes
AttributeValue
Supported attribute value types
EncryptionError
FqnError
FQN (Fully Qualified Name) parsing and validation errors
FqnErrorKind
Error kind for programmatic FQN error handling
GgufSegmentKind
What a segment’s plaintext covers.
KasError
KAS client errors
KeyError
Key-related errors
LogicalOperator
Logical operators for combining conditions
OaepHash
OAEP hash algorithm selection
OpenTdfError
Unified error type for all OpenTDF operations
Operator
Comparison operators for attribute values
PolicyBindingError
Why PolicyBinding::validate rejected a policy binding.
PolicyError
TdfError
ValidationErrorType
Types of validation errors

Constants§

DEFAULT_MAX_MANIFEST_SIZE
Default cap on the size of a manifest member once read into memory: 16 MiB.
DEFAULT_MAX_PAYLOAD_SIZE
Default cap on the size of a payload member once read into memory: 1 GiB.
GGUF_TDF_PROFILE_V1
Profile identifier for the index version defined by draft-00.
LEGACY_TDF_MANIFEST_FILE_NAME
Name every SDK wrote before spec compliance; accepted on read forever.
TDF_MANIFEST_FILE_NAME
Spec (opentdf/spec schema/OpenTDF/README.md): the manifest entry MUST be manifest.json at the archive root.
TDF_PAYLOAD_FILE_NAME
Default payload entry name. Written into manifest.payload.url by callers of TdfManifest::new; on read it is only a fallback for an empty url.

Functions§

wrap_key_with_rsa_oaep
Convenience function to wrap a key with RSA-OAEP (SHA-1 default)