123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Crypt::Status Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/crypt/status.rb

Overview

A wrapper around mongocrypt_status_t, representing the status of a mongocrypt_t handle.

Class Method Summary

Instance Attribute Summary

  • #ok? ⇒ Boolean readonly Internal use only

    Checks whether the status is labeled :ok.

Instance Method Summary

Class Method Details

.from_pointer(pointer) ⇒ Status

Initialize a Status object from an existing pointer to a mongocrypt_status_t object.

Parameters:

  • pointer (FFI::Pointer)

    A pointer to an existing mongocrypt_status_t object

Returns:

  • (Status)

    A new Status object

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 54

def self.from_pointer(pointer)
  self.new(pointer: pointer)
end

Instance Attribute Details

#ok?Boolean (readonly)

Checks whether the status is labeled :ok

Returns:

  • (Boolean)

    Whether the status is :ok

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 105

def ok?
  Binding.mongocrypt_status_ok(@status)
end

Instance Method Details

#codeInteger

Return the integer code associated with the status

Returns:

  • (Integer)

    The status code, defaults to 0

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 90

def code
  Binding.mongocrypt_status_code(@status)
end

#labelSymbol

Return the label of the status

Returns:

  • (Symbol)

    The status label, either :ok, :error_kms, or :error_client, defaults to :ok

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 83

def label
  Binding.mongocrypt_status_type(@status)
end

#messageString

Return the status message

Returns:

  • (String)

    The status message, defaults to empty string

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 97

def message
  message = Binding.mongocrypt_status_message(@status, nil)
  message || ''
end

#raise_crypt_error(kms: false)

Note:

If kms parameter is false, the error may still have come from a KMS. The kms parameter simply forces all errors to be treated as KMS errors.

Raises a Mongo::Error:CryptError corresponding to the information stored in this status

Does nothing if self.ok? is true

Parameters:

  • kms (true | false)

    Whether the operation was against the KMS.

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 127

def raise_crypt_error(kms: false)
  return if ok?

  if kms || label == :error_kms
    error = Error::KmsError.new(message, code: code)
  else
    error = Error::CryptError.new(message, code: code)
  end

  raise error
end

#refFFI::Pointer

Returns the reference to the underlying mongocrypt_status_t object

Returns:

  • (FFI::Pointer)

    Pointer to the underlying mongocrypt_status_t oject

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 113

def ref
  @status
end

#update(label, code, message) ⇒ Status

Set a label, code, and message on the Status

Parameters:

  • label (Symbol)

    One of :ok, :error_client, or :error_kms

  • code (Integer)
  • message (String)

Returns:

  • (Status)

    returns self

[ GitHub ]

  
# File 'lib/mongo/crypt/status.rb', line 65

def update(label, code, message)
  unless [:ok, :error_client, :error_kms].include?(label)
    raise ArgumentError.new(
      "#{label} is an invalid value for a Mongo::Crypt::Status label. " +
      "Label must have one of the following values: :ok, :error_client, :error_kms"
    )
  end

  message_length = message ? message.bytesize + 1 : 0
  Binding.mongocrypt_status_set(@status, label, code, message, message_length)

  self
end