lib/mongo/crypt/context.rb
def run_state_machine
        while true
          case state
          when :error
            Binding.check_ctx_status(self)
          when :ready
            # Finalize the state machine and return the result as a BSON::Document
            return Binding.ctx_finalize(self)
          when :done
            return nil
          when :need_mongo_keys
            filter = Binding.ctx_mongo_op(self)

            @encryption_io.find_keys(filter).each do |key|
              mongocrypt_feed(key) if key
            end

            mongocrypt_done
          when :need_mongo_collinfo
            filter = Binding.ctx_mongo_op(self)

            result = @encryption_io.collection_info(@db_name, filter)
            mongocrypt_feed(result) if result

            mongocrypt_done
          when :need_mongo_markings
            cmd = Binding.ctx_mongo_op(self)

            result = @encryption_io.mark_command(cmd)
            mongocrypt_feed(result)

            mongocrypt_done
          when :need_kms
            while kms_context = Binding.ctx_next_kms_ctx(self) do
              @encryption_io.feed_kms(kms_context)
            end

            Binding.ctx_kms_done(self)
          else
            raise Error::CryptError.new(
              # TODO: fix CryptError to improve this API -- the first argument
              # in the initializer should not be optional
              nil,
              "State #{state} is not supported by Mongo::Crypt::Context"
            )
          end
        end
      end
# Runs the mongocrypt_ctx_t state machine and handles
# all I/O on behalf of libmongocrypt
#
# @return [ BSON::Document ] A BSON document representing the outcome
#   of the state machine. Contents can differ depending on how the
#   context was initialized..
#
# @raise [ Error::CryptError ] If the state machine enters the
#   :error state
#
# This method is not currently unit tested. It is integration tested
# in spec/integration/explicit_encryption_spec.rb
Runs the mongocrypt_ctx_t state machine and handles
all I/O on behalf of libmongocrypt
Runs the mongocrypt_ctx_t state machine and handles all I / O on behalf of libmongocrypt
def run_state_machine
        while true
          case state
          when :error
            Binding.check_ctx_status(self)
          when :ready
            return Binding.ctx_finalize(self)
          when :done
            return nil
          when :need_mongo_keys
            filter = Binding.ctx_mongo_op(self)
            @encryption_io.find_keys(filter).each do |key|
              mongocrypt_feed(key) if key
            end
            mongocrypt_done
          when :need_mongo_collinfo
            filter = Binding.ctx_mongo_op(self)
            result = @encryption_io.collection_info(@db_name, filter)
            mongocrypt_feed(result) if result
            mongocrypt_done
          when :need_mongo_markings
            cmd = Binding.ctx_mongo_op(self)
            result = @encryption_io.mark_command(cmd)
            mongocrypt_feed(result)
            mongocrypt_done
          when :need_kms
            while kms_context = Binding.ctx_next_kms_ctx(self) do
              @encryption_io.feed_kms(kms_context)
            end
            Binding.ctx_kms_done(self)
          else
            raise Error::CryptError.new(
              nil,
              "State #{state} is not supported by Mongo::Crypt::Context"
            )
          end
        end
      end
def run_state_machine while true case state when :error Binding . check_ctx_status ( self ) when :ready return Binding . ctx_finalize ( self ) when :done return nil when :need_mongo_keys filter = Binding . ctx_mongo_op ( self ) @encryption_io . find_keys ( filter ) . each do | key | mongocrypt_feed ( key ) if key end mongocrypt_done when :need_mongo_collinfo filter = Binding . ctx_mongo_op ( self ) result = @encryption_io . collection_info ( @db_name , filter ) mongocrypt_feed ( result ) if result mongocrypt_done when :need_mongo_markings cmd = Binding . ctx_mongo_op ( self ) result = @encryption_io . mark_command ( cmd ) mongocrypt_feed ( result ) mongocrypt_done when :need_kms while kms_context = Binding . ctx_next_kms_ctx ( self ) do @encryption_io . feed_kms ( kms_context ) end Binding . ctx_kms_done ( self ) else raise Error :: CryptError . new ( nil , "State #{state} is not supported by Mongo::Crypt::Context" ) end end end
Runs the mongocrypt_ctx_t state machine and handles
all I/O on behalf of libmongocrypt
Runs the mongocrypt_ctx_t state machine and handles all I / O on behalf of libmongocrypt
# Finalize the state machine and return the result as a BSON::Document # TODO: fix CryptError to improve this API -- the first argument # in the initializer should not be optional
A BSON document representing the outcome of the state machine. Contents can differ depending on how the context was initialized
A BSON document representing the outcome of the state machine . Contents can differ depending on how the context was initialized
 BSON::Document 
[ Error::CryptError ] If the state machine enters the :error state This method is not currently unit tested. It is integration tested in spec/integration/explicit_encryption_spec.rb
[ Error :: CryptError ] If the state machine enters the : error state This method is not currently unit tested . It is integration tested in spec / integration / explicit_encryption_spec . rb