---
title: "The happy path"
url: https://recursiveai.org/onecrypto/docs/happy-path/
description: "One call for each common task: Cms, Pki, Tsa, Pgp, Crypto.Load, and SignLta and Validate on OnePDF's PdfDocument. Each is a thin wrapper over the layers…"
version: "0.5.0-preview.1"
source: https://github.com/recursive-ai-oss/onecrypto-csharp/blob/d80bcb8eb948150b8c78f357b8b6fa4fe88df7b3/docs/happy-path.md
---

# The happy path

One call for each common task: `Cms`, `Pki`, `Tsa`, `Pgp`, `Crypto.Load`, and `SignLta` and `Validate` on OnePDF's `PdfDocument`. Each is a thin wrapper over the layers below it, with two rules.

1. **No behaviour of its own.** A call builds the options of the layered call it forwards to and passes the arguments through. The tests compare each call with the layered call it forwards to: the same bytes where the algorithm is deterministic, the same report rules where it is not.
2. **No algorithm parameters.** The key, the recipient's certificate and the `CryptoPolicy` decide. A call takes a `CryptoPolicy` (`Standard` when null) and, where it asks a validity question or writes a time, a `TimeProvider` (the system clock when null). Choosing an algorithm, a digest, an attribute or a validity period means calling the layer: `SignedData.Create`, `EnvelopedData.Create`, `CertificateAuthority`, `PgpMessageWriter`, `PadesSigner`. One older overload names a whole OpenPGP key profile (`Pgp.GenerateKey(userId, PgpKeyProfile, ...)`); the policy overload beside it is the happy path.

Under `CryptoPolicy.Standard` new keys are hybrid post-quantum (composite ML-DSA-65 with Ed25519, X25519 with ML-KEM-768); under `CryptoPolicy.Cnsa2` they are ML-DSA-87 and ML-KEM-1024; under `CryptoPolicy.Permissive` they are classical (ECDSA P-256, RSA-3072), which is what to choose for certificates that a browser or a TLS stack must accept today. The same program runs under each.

## `Cms`

| Call | Forwards to | Notes |
|---|---|---|
| `Sign`, `SignDetached` (content, `PkiIdentity`, PFX path or certificate with any `ISigningKey`) | `SignedData.Create` | Signing time from the clock; the signer's certificate and chain are embedded; digest and signature scheme follow the key and policy. A stream overload signs in constant memory. |
| `Verify`, `VerifyDetached` | `SignedData.Verify` | The trust anchors are a required argument: nothing is trusted unless named. The chain is validated at the clock's time with the policy; a chain with no revocation data says so in its report. A malformed message raises `CmsParseException`. |
| `Encrypt` | `AuthEnvelopedData.Create` | AES-256-GCM. Each recipient's key picks the delivery: RSA key transport (OAEP), key agreement for EC, X25519 and X448, ML-KEM key encapsulation (RFC 9629) for ML-KEM and composite ML-KEM keys. |
| `Decrypt` | `AuthEnvelopedData.Decrypt` or `EnvelopedData.Decrypt` by the message's content type | Plaintext is released only after the tag has verified. CBC EnvelopedData from other software decrypts under `Standard` and is refused under `Strict` and `Cnsa2`. The stream overload reads AuthEnvelopedData. |

## `Pki`

| Call | Forwards to | Notes |
|---|---|---|
| `CreateCa` | `CertificateAuthority.CreateRoot` | A self-signed root, ten years. |
| `IssueTlsServer`, `IssueTlsClient`, `IssueSigner`, `IssueEncryption`, `IssueTimeStamping`, `Issue` (from a request) | `CertificateAuthority.Issue` with the matching `CertificateProfile` | A new key by the policy. Validity is what the profile allows at that date, and never past the CA certificate. Names that parse as IP addresses become IP names, names with `@` e-mail names, the rest DNS names. |
| `CreateCsr` | `CertificateSigningRequestBuilder.Create` | Proof of possession by the key; the names go in a subject alternative name request. |
| `Revoke` | `CertificateAuthority.IssueCrl` | A complete CRL for the CA, valid seven days, numbered by the clock's Unix seconds. |
| `Validate` | `PathValidator.Validate` | The full report. Only the anchors you pass are trusted. |

`PkiIdentity` holds a certificate, its key and the chain above it, and reads and writes PFX files (`ToPkcs12`, `FromPkcs12`, `Load`). The key is zeroed on `Dispose`; keys that live in an operating-system store, a token or an agent are used through `ISigningKey` and `IDecryptionKey` directly.

## `Tsa` (package `.Online`)

`StampAsync` hashes the data (SHA-256 under `Standard`, SHA-384 under `Cnsa2`: the first of SHA-256, SHA-384 and SHA-512 that the policy accepts), sends a request with a nonce through a `Fetcher`, and checks the answer against the request and the authority's trust anchors. It is the only call in these entry points that touches the network, takes a `Fetcher` (the guarded transport; pass one built on a recording or in-process transport for tests) and returns an outcome, not an exception, for an unreachable or refusing authority. `Verify` and `VerifyAsync` check a token (or a whole response) against the data: they build the request the token must answer from the data's hash and the nonce the token echoes, and judge the algorithms at the token's own time.

## `Pgp` (package `.OpenPgp`)

`Encrypt`, `EncryptWithPassword`, `Decrypt`, `DecryptWithPassword`, `Sign`, `SignDetached`, `Verify`, `VerifyDetached` forward to `PgpMessageWriter` and `PgpMessageReader`; the container, ciphers and hashes come from the recipients' key preferences, the signing key and the policy, and a recipient with a post-quantum encryption subkey gets it used. `armor` chooses ASCII armor or the binary form and is the only output choice. `GenerateKey(userId, policy)` takes the key profile from the policy: classical v4 Curve25519 under `Standard` and `Strict`, the RFC 9980 high profile under `Cnsa2`. Decrypting reports the signatures it finds against the certificates you pass and never requires one.

## `Crypto.Load`

Loads any key or certificate file by looking at its bytes; see [load.md](https://recursiveai.org/onecrypto/docs/load/). It has no algorithm parameters and no behaviour beyond the loader.

## PDF (package `.Pdf`)

`document.SignLta(output, signer, timestamp, validation, policy, time)` signs at PAdES B-LTA: the signature, a signature time-stamp from the function you pass (`new TsaClient(fetcher, url).GetTimestampAsync` from `.Online`), the validation data from `validation` in the document security store, and a document time-stamp. The digest of the signed attributes and of the time-stamp imprints is the first of SHA-256, SHA-384 and SHA-512 the policy accepts. `document.Validate(trusted, policy, time)` verifies every signature and time-stamp offline.

The report speaks of what the file says and what the validator proves. It does not decide whether a signature is a qualified electronic signature under eIDAS: that needs the EU Trusted Lists and ETSI TS 119 615, which belong to the AdES package, and nothing here claims it.

With post-quantum keys the signing and the bridge's own rules hold, but OnePDF's own `onepdf` rule does not know the algorithm in the version this package builds on and reports failed, so `PadesReport.AllValid` is false until OnePDF takes the algorithms in. Sample 6 therefore defaults to classical keys, which is also what PDF readers accept today.

## What stays in the layers

Choosing digests, signed and unsigned attributes, content types, recipient kinds, the content cipher, validity periods, extensions, certificate profiles, revocation sources, OCSP, PDF fields and appearances; two-phase signing; streams of unknown length through `AuthEnvelopedData`; countersignatures; everything that needs a decision the policy cannot make.
