hexapdf 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTERS +1 -1
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/hexapdf +1 -1
- data/examples/text_layouter_styling.rb +1 -2
- data/lib/hexapdf.rb +2 -2
- data/lib/hexapdf/cli.rb +3 -3
- data/lib/hexapdf/cli/batch.rb +5 -5
- data/lib/hexapdf/cli/command.rb +15 -17
- data/lib/hexapdf/cli/files.rb +3 -3
- data/lib/hexapdf/cli/images.rb +3 -4
- data/lib/hexapdf/cli/info.rb +5 -5
- data/lib/hexapdf/cli/inspect.rb +6 -6
- data/lib/hexapdf/cli/merge.rb +6 -6
- data/lib/hexapdf/cli/modify.rb +4 -4
- data/lib/hexapdf/cli/optimize.rb +3 -3
- data/lib/hexapdf/configuration.rb +4 -5
- data/lib/hexapdf/content.rb +2 -2
- data/lib/hexapdf/content/canvas.rb +35 -36
- data/lib/hexapdf/content/color_space.rb +9 -14
- data/lib/hexapdf/content/graphic_object.rb +2 -2
- data/lib/hexapdf/content/graphic_object/arc.rb +3 -3
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +2 -2
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +4 -8
- data/lib/hexapdf/content/graphics_state.rb +4 -13
- data/lib/hexapdf/content/operator.rb +33 -35
- data/lib/hexapdf/content/parser.rb +28 -18
- data/lib/hexapdf/content/processor.rb +4 -5
- data/lib/hexapdf/content/transformation_matrix.rb +2 -2
- data/lib/hexapdf/data_dir.rb +2 -2
- data/lib/hexapdf/dictionary.rb +8 -9
- data/lib/hexapdf/dictionary_fields.rb +7 -10
- data/lib/hexapdf/document.rb +18 -18
- data/lib/hexapdf/document/files.rb +12 -10
- data/lib/hexapdf/document/fonts.rb +2 -2
- data/lib/hexapdf/document/images.rb +3 -3
- data/lib/hexapdf/document/pages.rb +4 -4
- data/lib/hexapdf/encryption.rb +2 -2
- data/lib/hexapdf/encryption/aes.rb +2 -2
- data/lib/hexapdf/encryption/arc4.rb +4 -4
- data/lib/hexapdf/encryption/fast_aes.rb +2 -2
- data/lib/hexapdf/encryption/fast_arc4.rb +4 -4
- data/lib/hexapdf/encryption/identity.rb +5 -4
- data/lib/hexapdf/encryption/ruby_aes.rb +147 -139
- data/lib/hexapdf/encryption/ruby_arc4.rb +4 -4
- data/lib/hexapdf/encryption/security_handler.rb +11 -12
- data/lib/hexapdf/encryption/standard_security_handler.rb +6 -9
- data/lib/hexapdf/error.rb +7 -9
- data/lib/hexapdf/filter.rb +2 -3
- data/lib/hexapdf/filter/ascii85_decode.rb +3 -3
- data/lib/hexapdf/filter/ascii_hex_decode.rb +2 -2
- data/lib/hexapdf/filter/dct_decode.rb +2 -2
- data/lib/hexapdf/filter/encryption.rb +2 -2
- data/lib/hexapdf/filter/flate_decode.rb +16 -33
- data/lib/hexapdf/filter/jpx_decode.rb +2 -2
- data/lib/hexapdf/filter/lzw_decode.rb +4 -4
- data/lib/hexapdf/filter/predictor.rb +2 -6
- data/lib/hexapdf/filter/run_length_decode.rb +2 -2
- data/lib/hexapdf/font/cmap.rb +2 -3
- data/lib/hexapdf/font/cmap/parser.rb +11 -11
- data/lib/hexapdf/font/cmap/writer.rb +25 -25
- data/lib/hexapdf/font/encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/base.rb +2 -2
- data/lib/hexapdf/font/encoding/difference_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/glyph_list.rb +6 -6
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/standard_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +2 -2
- data/lib/hexapdf/font/invalid_glyph.rb +7 -7
- data/lib/hexapdf/font/true_type.rb +2 -2
- data/lib/hexapdf/font/true_type/builder.rb +13 -7
- data/lib/hexapdf/font/true_type/font.rb +2 -3
- data/lib/hexapdf/font/true_type/optimizer.rb +2 -2
- data/lib/hexapdf/font/true_type/subsetter.rb +4 -4
- data/lib/hexapdf/font/true_type/table.rb +3 -5
- data/lib/hexapdf/font/true_type/table/cmap.rb +2 -2
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +9 -16
- data/lib/hexapdf/font/true_type/table/directory.rb +4 -4
- data/lib/hexapdf/font/true_type/table/glyf.rb +2 -2
- data/lib/hexapdf/font/true_type/table/head.rb +3 -2
- data/lib/hexapdf/font/true_type/table/hhea.rb +2 -2
- data/lib/hexapdf/font/true_type/table/hmtx.rb +2 -2
- data/lib/hexapdf/font/true_type/table/kern.rb +3 -3
- data/lib/hexapdf/font/true_type/table/loca.rb +3 -3
- data/lib/hexapdf/font/true_type/table/maxp.rb +2 -2
- data/lib/hexapdf/font/true_type/table/name.rb +3 -5
- data/lib/hexapdf/font/true_type/table/os2.rb +4 -3
- data/lib/hexapdf/font/true_type/table/post.rb +3 -7
- data/lib/hexapdf/font/true_type_wrapper.rb +20 -22
- data/lib/hexapdf/font/type1.rb +2 -2
- data/lib/hexapdf/font/type1/afm_parser.rb +7 -7
- data/lib/hexapdf/font/type1/character_metrics.rb +2 -2
- data/lib/hexapdf/font/type1/font.rb +3 -3
- data/lib/hexapdf/font/type1/font_metrics.rb +2 -4
- data/lib/hexapdf/font/type1/pfb_parser.rb +2 -2
- data/lib/hexapdf/font/type1_wrapper.rb +8 -9
- data/lib/hexapdf/font_loader.rb +2 -2
- data/lib/hexapdf/font_loader/from_configuration.rb +2 -2
- data/lib/hexapdf/font_loader/from_file.rb +2 -2
- data/lib/hexapdf/font_loader/standard14.rb +2 -2
- data/lib/hexapdf/image_loader.rb +2 -2
- data/lib/hexapdf/image_loader/jpeg.rb +6 -4
- data/lib/hexapdf/image_loader/pdf.rb +2 -2
- data/lib/hexapdf/image_loader/png.rb +6 -6
- data/lib/hexapdf/importer.rb +6 -4
- data/lib/hexapdf/layout.rb +2 -2
- data/lib/hexapdf/layout/box.rb +4 -4
- data/lib/hexapdf/layout/inline_box.rb +2 -2
- data/lib/hexapdf/layout/line.rb +6 -6
- data/lib/hexapdf/layout/numeric_refinements.rb +2 -2
- data/lib/hexapdf/layout/style.rb +17 -8
- data/lib/hexapdf/layout/text_fragment.rb +86 -48
- data/lib/hexapdf/layout/text_layouter.rb +40 -21
- data/lib/hexapdf/layout/text_shaper.rb +2 -2
- data/lib/hexapdf/name_tree_node.rb +2 -2
- data/lib/hexapdf/number_tree_node.rb +2 -2
- data/lib/hexapdf/object.rb +6 -8
- data/lib/hexapdf/parser.rb +10 -10
- data/lib/hexapdf/rectangle.rb +4 -4
- data/lib/hexapdf/reference.rb +2 -2
- data/lib/hexapdf/revision.rb +4 -4
- data/lib/hexapdf/revisions.rb +5 -5
- data/lib/hexapdf/serializer.rb +27 -24
- data/lib/hexapdf/stream.rb +4 -4
- data/lib/hexapdf/task.rb +2 -2
- data/lib/hexapdf/task/dereference.rb +4 -4
- data/lib/hexapdf/task/optimize.rb +5 -4
- data/lib/hexapdf/tokenizer.rb +12 -14
- data/lib/hexapdf/type.rb +2 -2
- data/lib/hexapdf/type/action.rb +3 -3
- data/lib/hexapdf/type/actions.rb +2 -2
- data/lib/hexapdf/type/actions/go_to.rb +2 -2
- data/lib/hexapdf/type/actions/go_to_r.rb +2 -2
- data/lib/hexapdf/type/actions/launch.rb +2 -2
- data/lib/hexapdf/type/actions/uri.rb +3 -3
- data/lib/hexapdf/type/annotation.rb +3 -3
- data/lib/hexapdf/type/annotations.rb +2 -2
- data/lib/hexapdf/type/annotations/link.rb +2 -2
- data/lib/hexapdf/type/annotations/markup_annotation.rb +2 -2
- data/lib/hexapdf/type/annotations/text.rb +2 -2
- data/lib/hexapdf/type/catalog.rb +4 -4
- data/lib/hexapdf/type/cid_font.rb +4 -5
- data/lib/hexapdf/type/embedded_file.rb +3 -3
- data/lib/hexapdf/type/file_specification.rb +6 -7
- data/lib/hexapdf/type/font.rb +4 -4
- data/lib/hexapdf/type/font_descriptor.rb +3 -4
- data/lib/hexapdf/type/font_simple.rb +12 -16
- data/lib/hexapdf/type/font_true_type.rb +2 -2
- data/lib/hexapdf/type/font_type0.rb +5 -5
- data/lib/hexapdf/type/font_type1.rb +4 -4
- data/lib/hexapdf/type/form.rb +3 -3
- data/lib/hexapdf/type/graphics_state_parameter.rb +3 -3
- data/lib/hexapdf/type/image.rb +13 -14
- data/lib/hexapdf/type/info.rb +2 -2
- data/lib/hexapdf/type/names.rb +2 -2
- data/lib/hexapdf/type/object_stream.rb +5 -5
- data/lib/hexapdf/type/page.rb +9 -10
- data/lib/hexapdf/type/page_tree_node.rb +5 -6
- data/lib/hexapdf/type/resources.rb +11 -11
- data/lib/hexapdf/type/trailer.rb +3 -3
- data/lib/hexapdf/type/viewer_preferences.rb +2 -2
- data/lib/hexapdf/type/xref_stream.rb +8 -4
- data/lib/hexapdf/utils/bit_field.rb +4 -4
- data/lib/hexapdf/utils/bit_stream.rb +4 -4
- data/lib/hexapdf/utils/graphics_helpers.rb +2 -2
- data/lib/hexapdf/utils/lru_cache.rb +2 -2
- data/lib/hexapdf/utils/math_helpers.rb +2 -2
- data/lib/hexapdf/utils/object_hash.rb +3 -3
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +3 -3
- data/lib/hexapdf/utils/sorted_tree_node.rb +12 -11
- data/lib/hexapdf/version.rb +3 -3
- data/lib/hexapdf/writer.rb +8 -8
- data/lib/hexapdf/xref_section.rb +3 -3
- data/test/hexapdf/common_tokenizer_tests.rb +6 -7
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +0 -1
- data/test/hexapdf/content/test_canvas.rb +28 -36
- data/test/hexapdf/content/test_color_space.rb +4 -0
- data/test/hexapdf/content/test_graphics_state.rb +2 -0
- data/test/hexapdf/content/test_operator.rb +6 -7
- data/test/hexapdf/content/test_parser.rb +2 -2
- data/test/hexapdf/content/test_processor.rb +1 -1
- data/test/hexapdf/document/test_files.rb +1 -0
- data/test/hexapdf/document/test_images.rb +1 -1
- data/test/hexapdf/encryption/common.rb +3 -3
- data/test/hexapdf/encryption/test_aes.rb +10 -4
- data/test/hexapdf/encryption/test_identity.rb +1 -1
- data/test/hexapdf/encryption/test_security_handler.rb +13 -17
- data/test/hexapdf/encryption/test_standard_security_handler.rb +12 -12
- data/test/hexapdf/filter/test_ascii85_decode.rb +2 -3
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +6 -1
- data/test/hexapdf/filter/test_flate_decode.rb +2 -2
- data/test/hexapdf/filter/test_lzw_decode.rb +10 -10
- data/test/hexapdf/filter/test_predictor.rb +10 -2
- data/test/hexapdf/filter/test_run_length_decode.rb +1 -1
- data/test/hexapdf/font/cmap/test_parser.rb +40 -40
- data/test/hexapdf/font/cmap/test_writer.rb +29 -29
- data/test/hexapdf/font/test_true_type_wrapper.rb +3 -2
- data/test/hexapdf/font/true_type/common.rb +2 -0
- data/test/hexapdf/font/true_type/table/test_cmap.rb +1 -1
- data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +5 -4
- data/test/hexapdf/font/true_type/table/test_glyf.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_head.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_name.rb +9 -6
- data/test/hexapdf/font/true_type/test_builder.rb +8 -3
- data/test/hexapdf/font/true_type/test_optimizer.rb +1 -2
- data/test/hexapdf/font/type1/test_afm_parser.rb +2 -2
- data/test/hexapdf/image_loader/test_jpeg.rb +1 -1
- data/test/hexapdf/image_loader/test_pdf.rb +1 -1
- data/test/hexapdf/image_loader/test_png.rb +3 -3
- data/test/hexapdf/layout/test_inline_box.rb +10 -1
- data/test/hexapdf/layout/test_line.rb +4 -4
- data/test/hexapdf/layout/test_style.rb +19 -7
- data/test/hexapdf/layout/test_text_fragment.rb +73 -27
- data/test/hexapdf/layout/test_text_layouter.rb +84 -68
- data/test/hexapdf/layout/test_text_shaper.rb +4 -6
- data/test/hexapdf/task/test_dereference.rb +2 -2
- data/test/hexapdf/task/test_optimize.rb +16 -7
- data/test/hexapdf/test_configuration.rb +1 -1
- data/test/hexapdf/test_data_dir.rb +2 -2
- data/test/hexapdf/test_dictionary.rb +6 -3
- data/test/hexapdf/test_dictionary_fields.rb +15 -14
- data/test/hexapdf/test_document.rb +47 -48
- data/test/hexapdf/test_filter.rb +30 -26
- data/test/hexapdf/test_importer.rb +14 -0
- data/test/hexapdf/test_object.rb +16 -4
- data/test/hexapdf/test_parser.rb +36 -36
- data/test/hexapdf/test_reference.rb +7 -5
- data/test/hexapdf/test_revision.rb +1 -1
- data/test/hexapdf/test_revisions.rb +90 -90
- data/test/hexapdf/test_serializer.rb +3 -2
- data/test/hexapdf/test_stream.rb +2 -4
- data/test/hexapdf/test_tokenizer.rb +2 -2
- data/test/hexapdf/test_writer.rb +80 -80
- data/test/hexapdf/test_xref_section.rb +1 -1
- data/test/hexapdf/type/annotations/test_link.rb +1 -1
- data/test/hexapdf/type/annotations/test_text.rb +3 -3
- data/test/hexapdf/type/test_font_descriptor.rb +1 -1
- data/test/hexapdf/type/test_font_simple.rb +2 -2
- data/test/hexapdf/type/test_font_type0.rb +0 -1
- data/test/hexapdf/type/test_image.rb +0 -3
- data/test/hexapdf/type/test_object_stream.rb +2 -1
- data/test/hexapdf/type/test_page.rb +5 -1
- data/test/hexapdf/type/test_page_tree_node.rb +4 -4
- data/test/hexapdf/type/test_trailer.rb +1 -1
- data/test/hexapdf/type/test_xref_stream.rb +4 -0
- data/test/hexapdf/utils/test_bit_field.rb +2 -0
- data/test/hexapdf/utils/test_bit_stream.rb +1 -1
- data/test/hexapdf/utils/test_lru_cache.rb +1 -1
- data/test/hexapdf/utils/test_sorted_tree_node.rb +10 -4
- data/test/test_helper.rb +3 -6
- metadata +3 -3
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -70,8 +70,8 @@ module HexaPDF
|
|
70
70
|
end
|
71
71
|
result
|
72
72
|
end
|
73
|
-
alias
|
74
|
-
alias
|
73
|
+
alias decrypt process
|
74
|
+
alias encrypt process
|
75
75
|
|
76
76
|
private
|
77
77
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -144,12 +144,12 @@ module HexaPDF
|
|
144
144
|
# Creates a new encrypted stream data object by utilizing the given stream data object as
|
145
145
|
# template. The arguments +key+ and +algorithm+ are used for decrypting purposes.
|
146
146
|
def initialize(obj, key, algorithm)
|
147
|
-
obj.instance_variables.each {|v| instance_variable_set(v, obj.instance_variable_get(v))}
|
147
|
+
obj.instance_variables.each {|v| instance_variable_set(v, obj.instance_variable_get(v)) }
|
148
148
|
@key = key
|
149
149
|
@algorithm = algorithm
|
150
150
|
end
|
151
151
|
|
152
|
-
alias
|
152
|
+
alias undecrypted_fiber fiber
|
153
153
|
|
154
154
|
# Returns a fiber like HexaPDF::StreamData#fiber, but one wrapped in a decrypting fiber.
|
155
155
|
def fiber(*args)
|
@@ -215,7 +215,6 @@ module HexaPDF
|
|
215
215
|
handler.freeze
|
216
216
|
end
|
217
217
|
|
218
|
-
|
219
218
|
# A hash containing information about the used encryption. This information is only
|
220
219
|
# available once the security handler has been set up for decryption or encryption.
|
221
220
|
#
|
@@ -310,11 +309,11 @@ module HexaPDF
|
|
310
309
|
# The encryption algorithm. Possible values are :arc4 for ARC4 encryption with key lengths
|
311
310
|
# of 40 to 128 bit or :aes for AES encryption with key lengths of 128 or 256 bit.
|
312
311
|
#
|
313
|
-
#
|
312
|
+
# force_v4::
|
314
313
|
# Forces the use of protocol version 4 when key_length=128 and algorithm=:arc4.
|
315
314
|
#
|
316
315
|
# See: PDF1.7 s7.6.1, PDF2.0 s7.6.1
|
317
|
-
def set_up_encryption(key_length: 128, algorithm: :aes,
|
316
|
+
def set_up_encryption(key_length: 128, algorithm: :aes, force_v4: false, **options)
|
318
317
|
@dict = document.wrap({}, type: encryption_dictionary_class)
|
319
318
|
|
320
319
|
dict[:V] =
|
@@ -324,7 +323,7 @@ module HexaPDF
|
|
324
323
|
when 48, 56, 64, 72, 80, 88, 96, 104, 112, 120
|
325
324
|
2
|
326
325
|
when 128
|
327
|
-
(algorithm == :aes ||
|
326
|
+
(algorithm == :aes || force_v4 ? 4 : 2)
|
328
327
|
when 256
|
329
328
|
5
|
330
329
|
else
|
@@ -473,8 +472,8 @@ module HexaPDF
|
|
473
472
|
key = encryption_key
|
474
473
|
return key if dict[:V] == 5
|
475
474
|
|
476
|
-
key += [oid, gen].pack('VXv'
|
477
|
-
key << "sAlT"
|
475
|
+
key += [oid, gen].pack('VXv')
|
476
|
+
key << "sAlT" if algorithm.ancestors.include?(AES)
|
478
477
|
n_plus_5 = key_length + 5
|
479
478
|
Digest::MD5.digest(key)[0, (n_plus_5 > 16 ? 16 : n_plus_5)]
|
480
479
|
end
|
@@ -508,9 +507,9 @@ module HexaPDF
|
|
508
507
|
def each_string_in_object(obj, &block) # :yields: str
|
509
508
|
case obj
|
510
509
|
when Hash
|
511
|
-
obj.each_value {|val| each_string_in_object(val, &block)}
|
510
|
+
obj.each_value {|val| each_string_in_object(val, &block) }
|
512
511
|
when Array
|
513
|
-
obj.each {|inner_o| each_string_in_object(inner_o, &block)}
|
512
|
+
obj.each {|inner_o| each_string_in_object(inner_o, &block) }
|
514
513
|
when String
|
515
514
|
yield(obj)
|
516
515
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -78,7 +78,6 @@ module HexaPDF
|
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
81
|
# The password-based standard security handler of the PDF specification, identified by a
|
83
82
|
# /Filter value of /Standard.
|
84
83
|
#
|
@@ -99,7 +98,6 @@ module HexaPDF
|
|
99
98
|
# See: PDF1.7 s7.6.3, PDF2.0 s7.6.3
|
100
99
|
class StandardSecurityHandler < SecurityHandler
|
101
100
|
|
102
|
-
|
103
101
|
# Defines all available permissions.
|
104
102
|
#
|
105
103
|
# It is possible to use an array of permission symbols instead of an integer to describe the
|
@@ -168,7 +166,6 @@ module HexaPDF
|
|
168
166
|
|
169
167
|
end
|
170
168
|
|
171
|
-
|
172
169
|
# Defines all possible options that can be passed to a StandardSecurityHandler when setting
|
173
170
|
# up encryption.
|
174
171
|
class EncryptionOptions
|
@@ -202,7 +199,7 @@ module HexaPDF
|
|
202
199
|
@permissions = process_permissions(data.delete(:permissions) { Permissions::ALL })
|
203
200
|
@algorithm = data.delete(:algorithm) { :arc4 }
|
204
201
|
@encrypt_metadata = data.delete(:encrypt_metadata) { true }
|
205
|
-
|
202
|
+
unless data.empty?
|
206
203
|
raise ArgumentError, "Invalid encryption options: #{data.keys.join(', ')}"
|
207
204
|
end
|
208
205
|
end
|
@@ -420,7 +417,7 @@ module HexaPDF
|
|
420
417
|
|
421
418
|
data = arc4_algorithm.encrypt(key, user_password)
|
422
419
|
if dict[:R] >= 3
|
423
|
-
19.times {|i| data = arc4_algorithm.encrypt(xor_key(key, i + 1), data)}
|
420
|
+
19.times {|i| data = arc4_algorithm.encrypt(xor_key(key, i + 1), data) }
|
424
421
|
end
|
425
422
|
|
426
423
|
data
|
@@ -459,7 +456,7 @@ module HexaPDF
|
|
459
456
|
key = compute_user_encryption_key(password)
|
460
457
|
data = Digest::MD5.digest(PASSWORD_PADDING + document.trailer[:ID][0])
|
461
458
|
data = arc4_algorithm.encrypt(key, data)
|
462
|
-
19.times {|i| data = arc4_algorithm.encrypt(xor_key(key, i + 1), data)}
|
459
|
+
19.times {|i| data = arc4_algorithm.encrypt(xor_key(key, i + 1), data) }
|
463
460
|
data << "hexapdfhexapdfhe"
|
464
461
|
elsif dict[:R] == 6
|
465
462
|
validation_salt = random_bytes(8)
|
@@ -548,7 +545,7 @@ module HexaPDF
|
|
548
545
|
userpwd = arc4_algorithm.decrypt(key, dict[:O])
|
549
546
|
else
|
550
547
|
userpwd = dict[:O]
|
551
|
-
20.times {|i| userpwd = arc4_algorithm.decrypt(xor_key(key, 19 - i), userpwd)}
|
548
|
+
20.times {|i| userpwd = arc4_algorithm.decrypt(xor_key(key, 19 - i), userpwd) }
|
552
549
|
end
|
553
550
|
|
554
551
|
userpwd
|
data/lib/hexapdf/error.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -42,18 +42,16 @@ module HexaPDF
|
|
42
42
|
# The byte position in the PDF file where the error occured.
|
43
43
|
attr_reader :pos
|
44
44
|
|
45
|
-
# Creates a new malformed PDF error object for the given exception
|
45
|
+
# Creates a new malformed PDF error object for the given exception message.
|
46
46
|
#
|
47
|
-
# The byte position where the error occured
|
48
|
-
def initialize(
|
49
|
-
super(
|
50
|
-
set_backtrace(msg_or_error.backtrace) if msg_or_error.kind_of?(Exception)
|
47
|
+
# The byte position where the error occured has to be given via the +pos+ argument.
|
48
|
+
def initialize(message, pos:)
|
49
|
+
super(message)
|
51
50
|
@pos = pos
|
52
51
|
end
|
53
52
|
|
54
53
|
def message # :nodoc:
|
55
|
-
|
56
|
-
"PDF malformed#{pos_msg}: #{super}"
|
54
|
+
"PDF malformed around position #{pos}: #{super}"
|
57
55
|
end
|
58
56
|
|
59
57
|
end
|
data/lib/hexapdf/filter.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -52,7 +52,6 @@ module HexaPDF
|
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
55
|
# == Overview
|
57
56
|
#
|
58
57
|
# A stream filter is used to compress a stream or to encode it in an ASCII compatible way; or
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -149,7 +149,7 @@ module HexaPDF
|
|
149
149
|
VALUE_TO_CHAR[num / POW85_2 % 85] << VALUE_TO_CHAR[num / POW85_1 % 85] <<
|
150
150
|
VALUE_TO_CHAR[num % 85])[0, rlen + 1] << "~>").force_encoding(Encoding::BINARY)
|
151
151
|
else
|
152
|
-
"~>".
|
152
|
+
"~>".b
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -45,45 +45,24 @@ module HexaPDF
|
|
45
45
|
# See: HexaPDF::Filter, PDF1.7 s7.4.4
|
46
46
|
module FlateDecode
|
47
47
|
|
48
|
-
class Pool #:nodoc:
|
49
|
-
|
50
|
-
# Creates a new Zlib::Stream pool. A block must be given that returns a new Zlib::Stream
|
51
|
-
# instance.
|
52
|
-
def initialize(&block)
|
53
|
-
@creator = block
|
54
|
-
@pool = []
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns the next available stream of the pool, already reset to its initial state.
|
58
|
-
def next_available
|
59
|
-
@pool.find(-> { e = @creator.call; @pool << e; e }, &:finished?).tap(&:reset)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
@inflate_pool = Pool.new { Zlib::Inflate.new }
|
65
|
-
@deflate_pool = Pool.new do
|
66
|
-
Zlib::Deflate.new(HexaPDF::GlobalConfiguration['filter.flate_compression'],
|
67
|
-
Zlib::MAX_WBITS,
|
68
|
-
HexaPDF::GlobalConfiguration['filter.flate_memory'])
|
69
|
-
end
|
70
|
-
|
71
48
|
# See HexaPDF::Filter
|
72
49
|
def self.decoder(source, options = nil)
|
73
50
|
fib = Fiber.new do
|
74
|
-
inflater =
|
51
|
+
inflater = Zlib::Inflate.new
|
75
52
|
while source.alive? && (data = source.resume)
|
76
53
|
begin
|
77
54
|
data = inflater.inflate(data)
|
78
|
-
rescue
|
79
|
-
raise FilterError, "Problem while decoding Flate encoded stream: #{
|
55
|
+
rescue StandardError => e
|
56
|
+
raise FilterError, "Problem while decoding Flate encoded stream: #{e}"
|
80
57
|
end
|
81
58
|
Fiber.yield(data)
|
82
59
|
end
|
83
60
|
begin
|
84
|
-
(data = inflater.finish).empty? ? nil : data
|
85
|
-
|
86
|
-
|
61
|
+
data = (data = inflater.finish).empty? ? nil : data
|
62
|
+
inflater.close
|
63
|
+
data
|
64
|
+
rescue StandardError => e
|
65
|
+
raise FilterError, "Problem while decoding Flate encoded stream: #{e}"
|
87
66
|
end
|
88
67
|
end
|
89
68
|
|
@@ -101,12 +80,16 @@ module HexaPDF
|
|
101
80
|
end
|
102
81
|
|
103
82
|
Fiber.new do
|
104
|
-
deflater =
|
83
|
+
deflater = Zlib::Deflate.new(HexaPDF::GlobalConfiguration['filter.flate_compression'],
|
84
|
+
Zlib::MAX_WBITS,
|
85
|
+
HexaPDF::GlobalConfiguration['filter.flate_memory'])
|
105
86
|
while source.alive? && (data = source.resume)
|
106
87
|
data = deflater.deflate(data)
|
107
88
|
Fiber.yield(data)
|
108
89
|
end
|
109
|
-
deflater.finish
|
90
|
+
data = deflater.finish
|
91
|
+
deflater.close
|
92
|
+
data
|
110
93
|
end
|
111
94
|
end
|
112
95
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -52,12 +52,12 @@ module HexaPDF
|
|
52
52
|
EOD = 257 # :nodoc:
|
53
53
|
|
54
54
|
INITIAL_ENCODER_TABLE = {} #:nodoc:
|
55
|
-
0.upto(255) {|i| INITIAL_ENCODER_TABLE[i.chr.freeze] = i}
|
55
|
+
0.upto(255) {|i| INITIAL_ENCODER_TABLE[i.chr.freeze] = i }
|
56
56
|
INITIAL_ENCODER_TABLE[CLEAR_TABLE] = CLEAR_TABLE
|
57
57
|
INITIAL_ENCODER_TABLE[EOD] = EOD
|
58
58
|
|
59
59
|
INITIAL_DECODER_TABLE = {} #:nodoc:
|
60
|
-
0.upto(255) {|i| INITIAL_DECODER_TABLE[i] = i.chr}
|
60
|
+
0.upto(255) {|i| INITIAL_DECODER_TABLE[i] = i.chr }
|
61
61
|
INITIAL_DECODER_TABLE[CLEAR_TABLE] = CLEAR_TABLE
|
62
62
|
INITIAL_DECODER_TABLE[EOD] = EOD
|
63
63
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -161,8 +161,6 @@ module HexaPDF
|
|
161
161
|
line = data[pos + 1, bytes_per_row - 1]
|
162
162
|
|
163
163
|
case data.getbyte(pos)
|
164
|
-
when PREDICTOR_PNG_NONE
|
165
|
-
# nothing to do
|
166
164
|
when PREDICTOR_PNG_SUB
|
167
165
|
bytes_per_pixel.upto(bytes_per_row - 2) do |i|
|
168
166
|
line.setbyte(i, line.getbyte(i) + line.getbyte(i - bytes_per_pixel))
|
@@ -202,8 +200,6 @@ module HexaPDF
|
|
202
200
|
next_last_line = line.dup
|
203
201
|
|
204
202
|
case predictor
|
205
|
-
when PREDICTOR_PNG_NONE
|
206
|
-
# nothing to do
|
207
203
|
when PREDICTOR_PNG_SUB
|
208
204
|
bytes_per_row.downto(bytes_per_pixel + 1) do |i|
|
209
205
|
line.setbyte(i, line.getbyte(i) - line.getbyte(i - bytes_per_pixel))
|