Table of Contents

Struct DataEncryptionPurpose

Namespace
MailFathom.Infrastructure.DataEncryption
Assembly
MailFathom.Infrastructure.dll

Identifies what a key of the ring is being used for, so that one ring can protect several things safely.

[JsonConverter(typeof(DataEncryptionPurposeJsonConverter))]
public readonly record struct DataEncryptionPurpose : IEquatable<DataEncryptionPurpose>
Implements
Inherited Members

Remarks

The type is a closed enumeration rather than a C# enum because a purpose has a published identity in the strongest sense this repository has: the identity is authenticated into every value sealed under it, so it is written into the database and stays there for the life of the row. An enum member's ordinal means nothing outside the assembly and its name changes with an ordinary rename — either would make every value sealed under the previous spelling fail to open, and the failure would appear at the next read rather than at the rename.

Sharing one key ring across several kinds of value is only safe because this identity is bound in. Two values sealed under the same key for different purposes do not open as one another, so a stored refresh token cannot be replayed into a column that means something else, and a future sealed column needs no key of its own.

The same identity does the same job for a key that is derived rather than used directly: it is the HKDF info label, so a subkey for one purpose is unrelated to the subkey for another and to the ring key both came from. That is why a purpose is not only about sealing — AttachmentDownloadLink seals nothing and signs instead, and the separation it buys is exactly the same one.

An identity is allocated once and never reused or respelled. Being a struct, default is reachable and names no purpose; DataEncryptionBinding is where it is rejected, because that is the last point before a value is bound to something meaningless. See ADR 0005.

Properties

All

Gets every supported purpose.

AttachmentDownloadLink

Gets the purpose of the key that signs the short-lived capability an attachment is fetched with.

Identity

Gets the identity authenticated into every value sealed under this purpose.

IsSpecified

Gets whether this value names a supported purpose rather than the unusable struct default.

MailboxRefreshToken

Gets the purpose of the OAuth refresh token MailFathom stores for a mailbox account.

Methods

ToString()

Returns the fully qualified type name of this instance.

TryParse(string?, out DataEncryptionPurpose)

Parses a stored or configured identity.