# frozen_string_literal: true module HexaPDF module DigitalSignature class Signatures private def generate_field_name index = (@document.acro_form.each_field .map { |field| field.full_field_name.to_s.scan(/\ASignature(\d+)/).first&.first.to_i } .max || 0) + 1 "Signature#{index}" end end end module Encryption class SecurityHandler def encrypt_string(str, obj) return str.dup if str.empty? || obj == document.trailer[:Encrypt] || obj.type == :XRef || (obj.type == :Sig && obj[:Contents].equal?(str)) key = object_key(obj.oid, obj.gen, string_algorithm) string_algorithm.encrypt(key, str).dup end end module AES module ClassMethods def unpad(data) padding_length = data.getbyte(-1) if !padding_length || padding_length > BLOCK_SIZE || padding_length.zero? || data[-padding_length, padding_length].each_byte.any? { |byte| byte != padding_length } data else data[0...-padding_length] end end end end end module Type class Page # fix NoMethodError (undefined method `color_space' for an instance of HexaPDF::Type::Page) def color_space(name) GlobalConfiguration.constantize('color_space.map', name).new end def [](name) return super unless value[name].nil? && INHERITABLE_FIELDS.include?(name) seen = Set.new.compare_by_identity seen << value node = self while node.value[name].nil? && (parent = node[:Parent]) && seen.add?(parent.value) node = parent end node == self || node.value[name].nil? ? super : node[name] end end # fix NoMethodError: undefined method `field_value' for #