Skip to content

Commit

Permalink
Merge pull request #279 from de-vri-es/clarify-no-pad
Browse files Browse the repository at this point in the history
Clarify the docs of `NO_PAD`, add shorthands for indifferent decoding.
  • Loading branch information
marshallpierce authored Jan 19, 2025
2 parents 87880e4 + f19eafd commit b58dcac
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/engine/general_purpose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,21 @@ pub const URL_SAFE_NO_PAD: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_S

/// Include padding bytes when encoding, and require that they be present when decoding.
///
/// This is the standard per the base64 RFC, but consider using [`NO_PAD`] instead as padding serves
/// This is the standard per the base64 RFC, but consider using [`NO_PAD_INDIFFERENT`] instead as padding serves
/// little purpose in practice.
pub const PAD: GeneralPurposeConfig = GeneralPurposeConfig::new();

/// Don't add padding when encoding, and require no padding when decoding.
/// Include padding bytes when encoding, but allow input with or without padding when decoding.
pub const PAD_INDIFFERENT: GeneralPurposeConfig = GeneralPurposeConfig::new()
.with_encode_padding(true)
.with_decode_padding_mode(DecodePaddingMode::Indifferent);

/// Don't add padding when encoding, and require that there is no padding when decoding.
pub const NO_PAD: GeneralPurposeConfig = GeneralPurposeConfig::new()
.with_encode_padding(false)
.with_decode_padding_mode(DecodePaddingMode::RequireNone);

/// Don't add padding when encoding, and allow input with or without padding when decoding.
pub const NO_PAD_INDIFFERENT: GeneralPurposeConfig = GeneralPurposeConfig::new()
.with_encode_padding(false)
.with_decode_padding_mode(DecodePaddingMode::Indifferent);

0 comments on commit b58dcac

Please sign in to comment.