Class ResolvedSecret
- Namespace
- MailFathom.Infrastructure.Secrets.Resolution
- Assembly
- MailFathom.Infrastructure.dll
Secret material owned by the operation that resolved it and erased when that operation ends.
public sealed class ResolvedSecret : IDisposable
- Inheritance
-
ResolvedSecret
- Implements
- Inherited Members
Remarks
Material is held in a byte buffer rather than in a string: a string is immutable, cannot be scheduled
for deletion, and — because its memory is not pinned — is copied again whenever the garbage collector compacts, so
erasing one is not well defined. The buffer is allocated pinned so the collector cannot relocate it and leave an
un-erased copy behind, and it is erased with ZeroMemory(Span<byte>), which is specified to
survive runtime optimizations that could drop a write no read follows. Pooled buffers are never used, because a
buffer returned uncleared hands the material to the next unrelated caller. SecureString is deliberately not
used: Microsoft recommends against it for new development and it does not encrypt its storage on non-Windows
platforms, which is every environment MailFathom targets.
The instance is owned by whoever resolved it. Dispose it as soon as the operation that needed the material finishes, so the window in which a process dump could contain the secret is bounded by an operation rather than by uptime.
Properties
- TextLength
Gets the number of characters RevealTextInto(Span<char>) writes.
Methods
- Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- FromBytes(ReadOnlySpan<byte>)
Copies binary material into an owned pinned buffer.
- FromText(string)
Encodes text material as UTF-8 into an owned pinned buffer.
- RevealAsString()
Reveals the material as its UTF-8 text view, with one trailing newline removed.
- RevealBytes()
Reveals the material unchanged.
- RevealTextInto(Span<char>)
Decodes the material as UTF-8 text into a caller-owned buffer, with one trailing newline removed.
- ToString()
Returns a string that represents the current object.