lib/hexapdf/document/signatures.rb in hexapdf-0.23.0 vs lib/hexapdf/document/signatures.rb in hexapdf-0.24.0

- old
+ new

@@ -2,11 +2,11 @@ # #-- # This file is part of HexaPDF. # # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby -# Copyright (C) 2014-2021 Thomas Leitner +# Copyright (C) 2014-2022 Thomas Leitner # # HexaPDF is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License version 3 as # published by the Free Software Foundation with the addition of the # following permission added to Section 15 as permitted in Section 7(a): @@ -237,19 +237,20 @@ signature[:ByteRange] = [0, 1_000_000_000_000, 1_000_000_000_000, 1_000_000_000_000] signature[:Contents] = '00' * handler.signature_size # twice the size due to hex encoding signature[:M] = Time.now io = if file_or_io.kind_of?(String) - File.open(file_or_io, 'w+') + File.open(file_or_io, 'wb+') else file_or_io end # Save the current state so that we can determine the correct /ByteRange value and set the # values handler.finalize_objects(signature_field, signature) - section = @document.write(io, incremental: true, **write_options) - data = section.map {|oid, _gen, entry| [entry.pos, oid] if entry.in_use? }.compact.sort + start_xref_position, section = @document.write(io, incremental: true, **write_options) + data = section.map {|oid, _gen, entry| [entry.pos, oid] if entry.in_use? }.compact.sort << + [start_xref_position, nil] index = data.index {|_pos, oid| oid == signature.oid } signature_offset = data[index][0] signature_length = data[index + 1][0] - data[index][0] io.pos = signature_offset signature_data = io.read(signature_length)