agentleFS
MongoDBKnown publishermongodb/mongo-csharp-driver/src/MongoDB.Driver/Encryption/AGENTS.md

mongo-csharp-driver / Encryption

AGENTS.md3.2k starsChanged 4 months agoApache-2.0View on GitHub

The hooks the driver itself needs in order to delegate auto-encryption to libmongocrypt. The cryptographic engine lives in the sibling project src/MongoDB.Driver.Encryption/ — this directory is the bridge.

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 1 mentionFeb 2026: 0 mentionsMar 2026: 1 mentionApr 2026: 1 mentionMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 1 mentionSep 2026: 2 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the mongodb/mongo-csharp-driver repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about mongodb/mongo-csharp-driver

The biggest 5 of 40 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 40

Talked about on GitHub (40 times).

On GitHub · 40

35 more on GitHub

The file

We split this AGENTS.md into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Registry not initialized: If the encryption assembly isn't loaded (e.g., trimmed away in AOT), the registry has no factory.

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Driver Encryption Glue — AGENTS.md

The hooks the driver itself needs in order to delegate auto-encryption to libmongocrypt. The cryptographic engine lives in the sibling project src/MongoDB.Driver.Encryption/ — this directory is the bridge.

Files

  • AutoEncryptionProviderRegistry / IAutoEncryptionProviderRegistry — service locator for the auto-encryption factory. AutoEncryptionProviderRegistry is an internal sealed class whose default instance is built by CreateDefaultInstance() and held by the driver's extension manager (MongoClientSettings.Extensions); it is not exposed as a public static Instance field. The encryption project registers a factory at startup; the driver looks it up to construct an IAutoEncryptionLibMongoCryptController per client. Registration is idempotent for the same factory reference; only re-registration with a different factory throws. Missing registration throws (MongoConfigurationException) when AutoEncryptionOptions is set on a MongoClient.
  • IAutoEncryptionLibMongoCryptController — minimal contract used by the wire layer. Inherits IBinaryCommandFieldEncryptor, IBinaryDocumentFieldDecryptor, and IDisposable, so the surface is EncryptFields / EncryptFieldsAsync, DecryptFields / DecryptFieldsAsync, CryptSharedLibraryVersion, and Dispose. Implementation lives in src/MongoDB.Driver.Encryption/AutoEncryptionLibMongoController.cs (the file name omits "Crypt" even though the class inside is AutoEncryptionLibMongoCryptController).
  • KmsProviderRegistry / IKmsProviderRegistry / IKmsProvider — name-keyed factory registry. Register(string kmsProviderName, Func<IKmsProvider> factory) adds a provider factory; TryCreate(string providerName, out IKmsProvider provider) resolves one by name when libmongocrypt asks for fresh credentials. IKmsProvider is the per-provider credential-refresh abstraction.
  • AzureKmsProvider, GcpKmsProvider — cloud-specific credential refresh logic. Azure renews bearer tokens via IMDS; GCP validates and refreshes service-account JSON. AWS credential refresh happens inside libmongocrypt.
  • KmsProvidersHelper, KmsProvidersEqualityHelper — convert/inspect the loosely-typed IDictionary<string, IDictionary<string, object>> form used in AutoEncryptionOptions and ClientEncryptionOptions.
  • EncryptionExtraOptionsHelper — parses and validates the extraOptions dictionary on AutoEncryptionOptions (e.g. mongocryptdURI, mongocryptdSpawnArgs, cryptSharedLibPath, cryptSharedRequired) into typed values before they flow into the libmongocrypt wrapper.
  • EncryptedCollectionHelper — utilities for QE collection setup. Validates that SchemaMap and EncryptedFieldsMap don't both name the same collection. Derives helper-collection names from the internal HelperCollectionForEncryption enum, whose two members are Esc and Ecos. Esc maps to the on-disk esc collection (the straightforward case — C# Esc ↔ on-disk esc). Ecos is the historical-artifact case: the member name dates from when ECOS/ECOC/ECC were three separate QE state collections; after ECC was removed from QE, Ecos was repurposed and now resolves to the on-disk ecoc collection (look at GetAdditionalCollectionName: HelperCollectionForEncryption.Ecos reads ecocCollection from encryptedFields and defaults to enxcol_.<coll>.ecoc). So the C# enum value Ecos ↔ on-disk collection ecoc is intentional, not a typo — the asymmetry is only on the Ecos member, not on Esc. TryGetEffectiveEncryptedFields merges per-context schema with EncryptedFieldsMap.
  • NoopBinaryDocumentFieldCryptor — pass-through implementation kept as a test/scaffolding hook. It is not wired into the production registration path: AutoEncryptionProviderRegistry.CreateAutoCryptClientController throws MongoConfigurationException("No AutoEncryption provider has been registered.") when no factory is present, so an unregistered driver never silently falls back to this no-op. Treat the class as available for tests and future hooks; do not enable it on production paths — it bypasses all encryption.

How encryption is wired in

  1. User configures MongoClientSettings.AutoEncryptionOptions (the user-facing options type lives at the driver root, not under this directory).
  2. MongoClient constructor checks for AutoEncryptionOptions; if present, calls into AutoEncryptionProviderRegistry.CreateAutoCryptClientController(...).
  3. The registry returns an IAutoEncryptionLibMongoCryptController, which the wire layer (in Core/WireProtocol) calls before sending each command and after receiving each reply.

Common pitfalls

  • Registry not initialized. If the encryption assembly isn't loaded (e.g., trimmed away in AOT), the registry has no factory; MongoClient construction throws MongoConfigurationException when auto-encryption is requested. Reference the encryption assembly explicitly to defeat trimming.
  • SchemaMap and EncryptedFieldsMap collisions. Per EncryptedCollectionHelper.EnsureCollectionsValid, the same collection must not appear in both. Tooling that builds these from generated code can hit this.
  • Cloud credential refresh races. Concurrent operations may both try to refresh expired Azure/GCP credentials. The provider implementations are responsible for coordinating; check them before adding new providers.

How to test

CRYPT_SHARED_LIB_PATH=<…> KMS_MOCK_SERVERS_ENABLED=true \
  dotnet test tests/MongoDB.Driver.Tests/MongoDB.Driver.Tests.csproj -f net10.0 \
  --filter "FullyQualifiedName~Encryption"

Cross-cutting tests that exercise auto-encryption end-to-end live in tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/. See the env-var table in the root AGENTS.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.