[migrating]: https://github.com/kixel-ai/rind/blob/main/MIGRATING.md

# Run rcgen on rind

This page describes rind-rcgen as `main` has it, ahead of [rind-rcgen 0.14.3](https://crates.io/crates/rind-rcgen/0.14.3) on crates.io. Until its next release, take it from git at the commit this page describes. Beside the lines below, add this line under the `[patch.crates-io]` table of your workspace's root `Cargo.toml` (add the table if it has none), then run `cargo update -p rind-rcgen`:

```toml
rind-rcgen = { git = "https://github.com/kixel-ai/rind", rev = "80fc7ba544b53a6ca9ab21ba9a946c275eb19a06" }
```

That moves every crate in your tree that depends on rind-rcgen, and `cargo tree -i rind-rcgen` then shows it from `git+https://github.com/kixel-ai/rind`.

This crate provides rcgen's `KeyPair` for [rcgen](https://github.com/rustls/rcgen), backed by [rind](https://github.com/kixel-ai/rind/), a fork of [Graviola](https://github.com/ctz/graviola/).
It generates and loads ECDSA P-256 and P-384 and Ed25519 keys, and loads RSA keys.

Build rcgen with `default-features = false` so it compiles no other crypto backend:

```toml
[dependencies]
rcgen = { version = "0.14", default-features = false }
rind-rcgen = "0.14"
```

Then use `rind_rcgen::KeyPair` where rcgen's `crypto` feature would give `rcgen::KeyPair`.
Without that feature, rcgen needs each certificate's serial number set explicitly,
and leaves its key identifiers empty unless `key_identifier_method` is set.

```rust
use rind_rcgen::KeyPair;

let key = KeyPair::generate()?;

let mut params = rcgen::CertificateParams::new(["localhost".to_string()])?;
params.serial_number = Some(rcgen::SerialNumber::from(1));

let cert = params.self_signed(&key)?;
let key = key.serialize_der();
```

## What rind cannot back

`KeyPair` behaves as rcgen's on its `ring` backend, which is rcgen's default:

- No P-521 or ML-DSA keys, and no `KeyPair::generate_rsa_for` or `RsaKeySize`, which rcgen offers only with `aws_lc_rs`.
- RSA keys load but do not generate: `generate_for` returns `KeyGenerationUnavailable`.
- Only PKCS#8 private keys load, not SEC1 or PKCS#1.
- An unsupported algorithm returns `UnsupportedSignatureAlgorithm` where rcgen panics.

The `pem` feature, on by default as rcgen's is, adds the PEM methods.
Keys and the key pair's PKCS#8 copy are wiped on drop.
The `zeroize` feature, as rcgen's, implements `Zeroize` for `KeyPair`, clearing its PKCS#8 copy.

## WebAssembly

It builds for `wasm32-wasip2` and `wasm32-unknown-unknown`, the browser, where
rind needs its JavaScript random source, `getrandom = { version = "0.4",
features = ["wasm_js"] }`. [PLATFORMS.md](https://github.com/kixel-ai/rind/blob/main/PLATFORMS.md) lists what each adapter's
upstream needs there too, and why rind's constant-time checks do not cover wasm.

## Switch with an agent

Paste this into your coding agent, in your repository:

```text
Move this repository from ring or aws-lc-rs to rind, following
https://raw.githubusercontent.com/kixel-ai/rind/main/MIGRATE.md
```

It migrates on a local branch, reports the build time, binary size,
benchmarks, and tests before and after, and asks before opening a PR or
filing an issue. To migrate by hand, [MIGRATING.md][migrating] maps each
ring and aws-lc-rs item to rind's.

## Other libraries

- [ring](/from/ring)
- [aws-lc-rs](/from/aws-lc-rs)
- [rustls](/from/rustls)
- [jsonwebtoken](/from/jsonwebtoken)
- [dimpl](/from/dimpl)
- [str0m](/from/str0m)
- [object_store](/from/object_store)
- [openmls](/from/openmls)
- [Crates with their own crypto backend](/from)
