类:Mongo::Crypt::Context Private

继承:
对象
  • 对象
显示全部
扩展方式:
可转发
定义于:
lib/ Mongo/crypt/context.rb

Overview

此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。

mongocrypt_ctx_t 的包装器,用于管理加密和解密的状态机。

该类是一个超类,它在为不同目的(例如 数据密钥创建、加密、显式加密等)

实例属性摘要折叠

实例方法摘要折叠

构造函数详情

#initialize (mongocrypt_handle, io) ⇒上下文

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

创建新的 Context对象

参数:

  • mongocrypt_handle ( Mongo::Crypt::Handle )

    用于创建新上下文对象的 libmongocrypt处理。

  • io (ClientEncryption::IO)

    IO 类的实例,用于实现运行状态机所需的驾驶员I/O 方法。



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ Mongo/crypt/context.rb', line 41

def 初始化(mongocrypt_handle, io)
  @mongocrypt_handle = mongocrypt_handle
  # 理想情况下,此级别的API不会传递指针
  # 对象之间的引用,因此此方法签名可能会更改。

  # FFI::AutoPointer 使用自定义发布策略来自动释放
  # 当此对象超出作用域时的指针
  @ctx_p = FFI::AutoPointer.new(
    绑定.mongocrypt_ctx_new(@mongocrypt_handle.ref),
    绑定.方法(:mongocrypt_ctx_destroy)
  )
  @encryption_io = io
  @cached_azure_token = nil
end

实例属性详细信息

# ctx_p对象(只读)

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。



56
57
58
# File 'lib/ Mongo/crypt/context.rb', line 56

def ctx_p
  @ctx_p
end

实例方法详细信息

# run_state_machine (timeout_holder) = "BSON::Document"

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

运行 mongocrypt_ctx_t 状态机并处理所有 I/O

此方法当前未经单元测试。 它在 spec/integration/explicit_encryption_spec.rb 中进行了集成测试

参数:

返回:

  • ( BSON::Document )

    表示状态机结果的 BSON 文档。 内容可能因上下文的初始化方式而异。

引发:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ Mongo/crypt/context.rb', line 80

def run_state_machine(timeout_holder)
  while true
    timeout_ms = timeout_holder.剩余超时毫秒!
    案例 
    when :error
      绑定.check_ctx_status(self)
    when :ready
      # 最终确定状态机并以BSON::Document 形式返回结果
      return 绑定.ctx_finalize(self)
    when :done
      return nil
    when :need_mongo_keys
      Provide_keys(timeout_ms)
    when :need_mongo_collinfo
      Provide_collection_info(timeout_ms)
    when :need_mongo_markings
      Provide_markings(timeout_ms)
    when :need_kms
      feed_kms
    when :need_kms_credentials
      绑定.ctx_provide_kms_providers(
        self,
        retrieve_kms_credentials(timeout_holder).to_document
      )
    else
      提高 错误::CryptError.new(
        " Mongo::Crypt::Context 不支持 状态 #{ state} "
      )
    end
  end
end

#状态符号

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回 mongocrypt_ctx_t 的状态

返回:

  • (符号)

    上下文状态



61
62
63
# File 'lib/ Mongo/crypt/context.rb', line 61

def 
  绑定.mongocrypt_ctx_state(@ctx_p)
end