Module: Mongo::Auth::StringPrep

Extended by:
StringPrep
Included in:
StringPrep
Defined in:
lib/mongo/auth/stringprep.rb,
lib/mongo/auth/stringprep/tables.rb,
lib/mongo/auth/stringprep/profiles/sasl.rb

Overview

This namespace contains all behavior related to string preparation (RFC 3454). It's used to implement SCRAM-SHA-256 authentication, which is available in MongoDB server versions 4.0 and up.

Since:

  • 2.6.0

Defined Under Namespace

Modules: Profiles, Tables

Instance Method Summary collapse

Instance Method Details

#prepare(data, mappings, prohibited, options = {}) ⇒ Object

Prepare a string given a set of mappings and prohibited character tables.

Examples:

Prepare a string.

StringPrep.prepare("some string",
                   StringPrep::Profiles::SASL::MAPPINGS,
                   StringPrep::Profiles::SASL::PROHIBITED,
                   normalize: true, bidi: true)

Parameters:

  • data (String)

    The string to prepare.

  • mappings (Array)

    A list of mappings to apply to the data.

  • prohibited (Array)

    A list of prohibited character lists to ensure the data doesn't contain after mapping and normalizing the data.

  • options (Hash) (defaults to: {})

    Optional operations to perform during string preparation.

Options Hash (options):

  • :normalize (Boolean)

    Whether or not to apply Unicode normalization to the data.

  • :bidi (Boolean)

    Whether or not to ensure that the data contains valid bidirectional input.

Raises:

Since:

  • 2.6.0



50
51
52
53
54
55
56
# File 'lib/mongo/auth/stringprep.rb', line 50

def prepare(data, mappings, prohibited, options = {})
  apply_maps(data, mappings).tap do |mapped|
    normalize!(mapped) if options[:normalize]
    check_prohibited!(mapped, prohibited)
    check_bidi!(mapped) if options[:bidi]
  end
end