lib/mongo/crypt/kms/local.rb in mongo-2.18.0.beta1 vs lib/mongo/crypt/kms/local.rb in mongo-2.18.0

- old
+ new

@@ -21,15 +21,19 @@ module Local # Local KMS Credentials object contains credentials for using local KMS provider. # # @api private class Credentials + extend Forwardable include KMS::Validations # @return [ String ] Master key. attr_reader :key + # @api private + def_delegator :@opts, :empty? + FORMAT_HINT = "Local KMS provider options must be in the format: " + "{ key: 'MASTER-KEY' }" # Creates a local KMS credentials object form a parameters hash. # @@ -38,14 +42,18 @@ # @option opts [ String ] :key Master key. # # @raise [ ArgumentError ] If required options are missing or incorrectly # formatted. def initialize(opts) - @key = validate_param(:key, opts, FORMAT_HINT) + @opts = opts + unless empty? + @key = validate_param(:key, opts, FORMAT_HINT) + end end # @return [ BSON::Document ] Local KMS credentials in libmongocrypt format. def to_document + return BSON::Document.new({}) if empty? BSON::Document.new({ key: BSON::Binary.new(@key, :generic), }) end end