Table of Contents

BaseFormatStyles Enum

Definition

Namespace
Bodu.Text.Encoding
Assembly
Bodu.Text.Encoding.dll
Package
Bodu.Text.Encoding 1.0.0
Source
BaseFormatStyles.cs

Specifies formatting styles that influence how base-encoded input strings are parsed during decoding.

[Flags]
public enum BaseFormatStyles : byte
Attributes
Extension Methods

Fields

None = 0

Indicates strict parsing mode. The input must contain only valid alphabet characters and must not include any prefix or whitespace decoration.

AllowPrefix = 1

Allows the parser to accept and ignore an optional 0x or 0X prefix at the beginning of the input.

IgnoreWhitespace = 2

Allows the parser to ignore ASCII whitespace characters ( ' ', '\t', '\r', '\n') anywhere in the input.

AllowMissingPadding = 4

Allows the parser to accept encoded input that omits the trailing padding characters mandated by the encoding specification. This flag has no effect on encodings that do not use padding.

RequireCanonicalEncoding = 8

Requires that the input is in canonical form - the unused bits of the final partial symbol must be zero. This prevents encoding ambiguity where multiple distinct input strings would decode to the same byte sequence (for example, RFC 4648 §3.5 explicitly allows decoders to either reject or normalise such inputs).

Applies to Base32 and Base64 only. The flag is a no-op for Base16 (which has no unused bits per character), Base58 (a non-power-of-two radix where canonicity is determined by leading-zero preservation), and Base85 (which uses block-based encoding with a different tail convention).

Remarks

These options control the leniency of the decoder. Multiple flags may be combined using a bitwise OR. The default of None requires strict, decoration-free input.

// Decode styles mirror the formatting options used on encode.
var encoded = Base64.Encode(payload, options: BaseFormattingOptions.InsertLineBreaks);

byte[] decoded = Base64.Decode(encoded, style: BaseFormatStyles.IgnoreWhitespace);

// RequireCanonicalEncoding rejects non-canonical trailing bits lenient decoders accept.
bool strict = Base64.IsValid(encoded, BaseFormatStyles.RequireCanonicalEncoding | BaseFormatStyles.IgnoreWhitespace);

Applies to

ProductVersions
.NET8, 10