lib/rnp/op/sign.rb in rnp-1.0.4 vs lib/rnp/op/sign.rb in rnp-1.0.5

- old
+ new

@@ -32,41 +32,39 @@ # Add a signer. # # @note The optional (per-signature) options here are not supported by RNP # internally at the time of this writing. # - # @param signer [Key] the signer - # @param hash [String] (see #hash=) - # @param creation_time (see #creation_time=) - # @param expiration_time (see #expiration_time=) + # @param [Hash] opts set several options in one place + # @option opts [Key] :signer the signer + # @option opts [String] :hash (see #hash=) + # @option opts [Time] :creation_time (see #creation_time=) + # @option opts [Time] :expiration_time (see #expiration_time=) # @return [self] - def add_signer(signer, hash: nil, creation_time: nil, expiration_time: nil) + def add_signer(signer, opts = {}) pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_op_sign_add_signature, @ptr, signer.ptr, pptr) psig = pptr.read_pointer self.class.set_signature_options( psig, - hash: hash, - creation_time: creation_time, - expiration_time: expiration_time + **opts, ) end # Set a group of options. # - # @param armored see {#armored=} - # @param compression see {#compression=} - # @param hash see {#hash=} - # @param creation_time see {#creation_time=} - # @param expiration_time see {#expiration_time=} - def options=(armored: nil, compression: nil, hash: nil, - creation_time: nil, expiration_time: nil) - self.armored = armored unless armored.nil? - self.compression = compression unless compression.nil? - self.hash = hash unless hash.nil? - self.creation_time = creation_time unless creation_time.nil? - self.expiration_time = expiration_time unless expiration_time.nil? + # @param [Hash] opts set several options in one place + # @option opts [String] :armored see {#armored=} + # @option opts [String] :compression see {#compression=} + # @option opts [String] :hash see {#hash=} + # @option opts [String] :creation_time see {#creation_time=} + # @option opts [String] :expiration_time see {#expiration_time=} + def options=(opts) + %i{armored compression hash creation_time expiration_time}.each do |prop| + value = opts[prop] + send("#{prop}=", value) unless value.nil? + end end # Set whether the output will be ASCII-armored. # # @param armored [Boolean] true if the output should be @@ -125,15 +123,17 @@ def execute Rnp.call_ffi(:rnp_op_sign_execute, @ptr) end # @api private - def self.set_signature_options(psig, hash:, creation_time:, - expiration_time:) - Rnp.call_ffi(:rnp_op_sign_signature_set_hash, psig, value) unless hash.nil? + def self.set_signature_options(psig, hash: nil, creation_time: nil, + expiration_time: nil) + Rnp.call_ffi(:rnp_op_sign_signature_set_hash, psig, hash) unless hash.nil? creation_time = creation_time.to_i if creation_time.is_a?(::Time) - Rnp.call_ffi(:rnp_op_sign_signature_set_creation_time, psig, value) unless creation_time.nil? - Rnp.call_ffi(:rnp_op_sign_signature_set_expiration_time, psig, value) unless expiration_time.nil? + Rnp.call_ffi(:rnp_op_sign_signature_set_creation_time, psig, + creation_time) unless creation_time.nil? + Rnp.call_ffi(:rnp_op_sign_signature_set_expiration_time, psig, + expiration_time) unless expiration_time.nil? end end # class end # class