lib/hexapdf/encryption/security_handler.rb in hexapdf-0.3.0 vs lib/hexapdf/encryption/security_handler.rb in hexapdf-0.4.0

- old
+ new

@@ -141,17 +141,15 @@ # The +encryption_opts+ can contain any encryption options for the specific security handler # and the common encryption options. # # See: #set_up_encryption (for the common encryption options). def self.set_up_encryption(document, handler_name, **options) - handler = HexaPDF::GlobalConfiguration.constantize('encryption.filter_map', handler_name) - if handler.nil? - handler = HexaPDF::GlobalConfiguration.constantize('encryption.sub_filter_map', handler_name) + handler = GlobalConfiguration.constantize('encryption.filter_map', handler_name) do + GlobalConfiguration.constantize('encryption.sub_filter_map', handler_name) do + raise HexaPDF::EncryptionError, "Could not find the specified security handler" + end end - if handler.nil? - raise HexaPDF::EncryptionError, "Could not find the specified security handler" - end handler = handler.new(document) document.trailer[:Encrypt] = handler.set_up_encryption(**options) handler.freeze end @@ -170,15 +168,13 @@ def self.set_up_decryption(document, **options) dict = document.trailer[:Encrypt] if dict.nil? raise HexaPDF::EncryptionError, "No /Encrypt dictionary found" end - handler = HexaPDF::GlobalConfiguration.constantize('encryption.filter_map', dict[:Filter]) - if handler.nil? - handler = HexaPDF::GlobalConfiguration.constantize('encryption.sub_filter_map', dict[:SubFilter]) - end - if handler.nil? - raise HexaPDF::EncryptionError, "Could not find a suitable security handler" + handler = HexaPDF::GlobalConfiguration.constantize('encryption.filter_map', dict[:Filter]) do + HexaPDF::GlobalConfiguration.constantize('encryption.sub_filter_map', dict[:SubFilter]) do + raise HexaPDF::EncryptionError, "Could not find a suitable security handler" + end end handler = handler.new(document) document.trailer[:Encrypt] = handler.set_up_decryption(dict, **options) document.revisions.each do |r|