origami 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING.LESSER +165 -0
 - data/README +77 -0
 - data/VERSION +1 -0
 - data/bin/config/pdfcop.conf.yml +237 -0
 - data/bin/gui/about.rb +46 -0
 - data/bin/gui/config.rb +132 -0
 - data/bin/gui/file.rb +385 -0
 - data/bin/gui/hexdump.rb +74 -0
 - data/bin/gui/hexview.rb +91 -0
 - data/bin/gui/imgview.rb +72 -0
 - data/bin/gui/menu.rb +392 -0
 - data/bin/gui/properties.rb +132 -0
 - data/bin/gui/signing.rb +635 -0
 - data/bin/gui/textview.rb +107 -0
 - data/bin/gui/treeview.rb +409 -0
 - data/bin/gui/walker.rb +282 -0
 - data/bin/gui/xrefs.rb +79 -0
 - data/bin/pdf2graph +121 -0
 - data/bin/pdf2ruby +353 -0
 - data/bin/pdfcocoon +104 -0
 - data/bin/pdfcop +455 -0
 - data/bin/pdfdecompress +104 -0
 - data/bin/pdfdecrypt +95 -0
 - data/bin/pdfencrypt +112 -0
 - data/bin/pdfextract +221 -0
 - data/bin/pdfmetadata +123 -0
 - data/bin/pdfsh +13 -0
 - data/bin/pdfwalker +7 -0
 - data/bin/shell/.irbrc +104 -0
 - data/bin/shell/console.rb +136 -0
 - data/bin/shell/hexdump.rb +83 -0
 - data/origami.rb +36 -0
 - data/origami/3d.rb +239 -0
 - data/origami/acroform.rb +321 -0
 - data/origami/actions.rb +299 -0
 - data/origami/adobe/fdf.rb +259 -0
 - data/origami/adobe/ppklite.rb +489 -0
 - data/origami/annotations.rb +775 -0
 - data/origami/array.rb +187 -0
 - data/origami/boolean.rb +101 -0
 - data/origami/catalog.rb +486 -0
 - data/origami/destinations.rb +213 -0
 - data/origami/dictionary.rb +188 -0
 - data/origami/docmdp.rb +96 -0
 - data/origami/encryption.rb +1293 -0
 - data/origami/export.rb +283 -0
 - data/origami/file.rb +222 -0
 - data/origami/filters.rb +250 -0
 - data/origami/filters/ascii.rb +189 -0
 - data/origami/filters/ccitt.rb +515 -0
 - data/origami/filters/crypt.rb +47 -0
 - data/origami/filters/dct.rb +61 -0
 - data/origami/filters/flate.rb +112 -0
 - data/origami/filters/jbig2.rb +63 -0
 - data/origami/filters/jpx.rb +53 -0
 - data/origami/filters/lzw.rb +195 -0
 - data/origami/filters/predictors.rb +276 -0
 - data/origami/filters/runlength.rb +117 -0
 - data/origami/font.rb +209 -0
 - data/origami/functions.rb +93 -0
 - data/origami/graphics.rb +33 -0
 - data/origami/graphics/colors.rb +191 -0
 - data/origami/graphics/instruction.rb +126 -0
 - data/origami/graphics/path.rb +154 -0
 - data/origami/graphics/patterns.rb +180 -0
 - data/origami/graphics/state.rb +164 -0
 - data/origami/graphics/text.rb +224 -0
 - data/origami/graphics/xobject.rb +493 -0
 - data/origami/header.rb +90 -0
 - data/origami/linearization.rb +318 -0
 - data/origami/metadata.rb +114 -0
 - data/origami/name.rb +170 -0
 - data/origami/null.rb +75 -0
 - data/origami/numeric.rb +188 -0
 - data/origami/obfuscation.rb +233 -0
 - data/origami/object.rb +527 -0
 - data/origami/outline.rb +59 -0
 - data/origami/page.rb +559 -0
 - data/origami/parser.rb +268 -0
 - data/origami/parsers/fdf.rb +45 -0
 - data/origami/parsers/pdf.rb +27 -0
 - data/origami/parsers/pdf/linear.rb +113 -0
 - data/origami/parsers/ppklite.rb +86 -0
 - data/origami/pdf.rb +1144 -0
 - data/origami/reference.rb +113 -0
 - data/origami/signature.rb +474 -0
 - data/origami/stream.rb +575 -0
 - data/origami/string.rb +416 -0
 - data/origami/trailer.rb +173 -0
 - data/origami/webcapture.rb +87 -0
 - data/origami/xfa.rb +3027 -0
 - data/origami/xreftable.rb +447 -0
 - data/templates/patterns.rb +66 -0
 - data/templates/widgets.rb +173 -0
 - data/templates/xdp.rb +92 -0
 - data/tests/dataset/test.dummycrt +28 -0
 - data/tests/dataset/test.dummykey +27 -0
 - data/tests/tc_actions.rb +32 -0
 - data/tests/tc_annotations.rb +85 -0
 - data/tests/tc_pages.rb +37 -0
 - data/tests/tc_pdfattach.rb +24 -0
 - data/tests/tc_pdfencrypt.rb +110 -0
 - data/tests/tc_pdfnew.rb +32 -0
 - data/tests/tc_pdfparse.rb +98 -0
 - data/tests/tc_pdfsig.rb +37 -0
 - data/tests/tc_streams.rb +129 -0
 - data/tests/ts_pdf.rb +45 -0
 - metadata +193 -0
 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              class TC_PdfAttach < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @target = PDF.new
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @attachment = "tests/dataset/test.dummycrt"
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @output = StringIO.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 12 
     | 
    
         
            +
                # end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def test_attachfile
         
     | 
| 
      
 15 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    fspec = @target.attach_file(@attachment, :EmbeddedName => "foo.bar")
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @target.save(@output)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,110 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              class TC_PdfEncrypt < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @target = PDF.read("tests/dataset/calc.pdf", :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @output = StringIO.new
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                # end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def test_encrypt_rc4_40b
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 15 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @target.encrypt(:cipher => 'rc4', :key_size => 40).save(@output);
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def test_encrypt_rc4_128b
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @target.encrypt(:cipher => 'rc4').save(@output);
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def test_encrypt_aes_128b
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 29 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @target.encrypt(:cipher => 'aes').save(@output);
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def test_decrypt_rc4_40b
         
     | 
| 
      
 35 
     | 
    
         
            +
                  pdf = nil
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 37 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 38 
     | 
    
         
            +
                    pdf = PDF.new.encrypt(:cipher => 'rc4', :key_size => 40)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    pdf.Catalog[:Test] = "test"
         
     | 
| 
      
 40 
     | 
    
         
            +
                    pdf.save(@output)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  assert_not_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 46 
     | 
    
         
            +
                    @output = @output.reopen(@output.string, "r")
         
     | 
| 
      
 47 
     | 
    
         
            +
                    pdf = PDF.read(@output, :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  assert_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                def test_decrypt_rc4_128b
         
     | 
| 
      
 54 
     | 
    
         
            +
                  pdf = nil
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 56 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 57 
     | 
    
         
            +
                    pdf = PDF.new.encrypt(:cipher => 'rc4')
         
     | 
| 
      
 58 
     | 
    
         
            +
                    pdf.Catalog[:Test] = "test"
         
     | 
| 
      
 59 
     | 
    
         
            +
                    pdf.save(@output)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  assert_not_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 65 
     | 
    
         
            +
                    @output.reopen(@output.string, "r")
         
     | 
| 
      
 66 
     | 
    
         
            +
                    pdf = PDF.read(@output, :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  assert_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                def test_decrypt_aes_128b
         
     | 
| 
      
 73 
     | 
    
         
            +
                  pdf = nil
         
     | 
| 
      
 74 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 75 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 76 
     | 
    
         
            +
                    pdf = PDF.new.encrypt(:cipher => 'aes')
         
     | 
| 
      
 77 
     | 
    
         
            +
                    pdf.Catalog[:Test] = "test"
         
     | 
| 
      
 78 
     | 
    
         
            +
                    pdf.save(@output)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  assert_not_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 84 
     | 
    
         
            +
                    @output = @output.reopen(@output.string, "r")
         
     | 
| 
      
 85 
     | 
    
         
            +
                    pdf = PDF.read(@output, :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  assert_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                def test_decrypt_aes_256b
         
     | 
| 
      
 92 
     | 
    
         
            +
                  pdf = nil
         
     | 
| 
      
 93 
     | 
    
         
            +
                  @output.string = ""
         
     | 
| 
      
 94 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 95 
     | 
    
         
            +
                    pdf = PDF.new.encrypt(:cipher => 'aes', :key_size => 256)
         
     | 
| 
      
 96 
     | 
    
         
            +
                    pdf.Catalog[:Test] = "test"
         
     | 
| 
      
 97 
     | 
    
         
            +
                    pdf.save(@output)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                  assert_not_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 103 
     | 
    
         
            +
                    @output = @output.reopen(@output.string, "r")
         
     | 
| 
      
 104 
     | 
    
         
            +
                    pdf = PDF.read(@output, :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  assert_equal pdf.Catalog[:Test], "test"
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            end
         
     | 
    
        data/tests/tc_pdfnew.rb
    ADDED
    
    | 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              class TC_PdfNew < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @output = StringIO.new
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                # end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def test_pdf_struct
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  pdf = PDF.new
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  null = Null.new
         
     | 
| 
      
 18 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 19 
     | 
    
         
            +
                    pdf << null
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    pdf.save(@output)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  assert null.is_indirect?
         
     | 
| 
      
 27 
     | 
    
         
            +
                  assert pdf.objects.include?(null)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  assert_equal pdf.revisions.first.body[null.reference], null
         
     | 
| 
      
 29 
     | 
    
         
            +
                  assert_equal null.reference.solve, null
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,98 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              class TC_PdfParse < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                  @data = 
         
     | 
| 
      
 6 
     | 
    
         
            +
                    %w{ 
         
     | 
| 
      
 7 
     | 
    
         
            +
                      tests/dataset/empty.pdf
         
     | 
| 
      
 8 
     | 
    
         
            +
                      tests/dataset/calc.pdf 
         
     | 
| 
      
 9 
     | 
    
         
            +
                      tests/dataset/crypto.pdf
         
     | 
| 
      
 10 
     | 
    
         
            +
                      }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  @dict = StringScanner.new "<</N 2 0 R/x1 null/Pi 3.14 /a <<>>>>"
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  @bytestring = StringScanner.new "(\\122\\125by\\n)"
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @hexastring = StringScanner.new "<52  55  62 79 0A>"
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @true = StringScanner.new "true"
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @false = StringScanner.new "false"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @real = StringScanner.new "-3.141592653"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @int = StringScanner.new "00000000002000000000000"
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @name = StringScanner.new "/#52#55#62#79#0A"
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 24 
     | 
    
         
            +
                # end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def test_parsepdf
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @data.each { |file|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    assert_nothing_raised do
         
     | 
| 
      
 29 
     | 
    
         
            +
                      PDF.read(file, :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  }
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def test_parsedictionary
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  dict = nil
         
     | 
| 
      
 37 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 38 
     | 
    
         
            +
                    dict = Dictionary.parse(@dict)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  assert dict[:Pi] == 3.14
         
     | 
| 
      
 42 
     | 
    
         
            +
                  assert dict[:a].is_a?(Dictionary)
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                def test_parsestring
         
     | 
| 
      
 47 
     | 
    
         
            +
                  str = nil
         
     | 
| 
      
 48 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    str = ByteString.parse(@bytestring)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  assert str.value == "RUby\n"
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    str = HexaString.parse(@hexastring)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  assert str.value == "RUby\n"
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                def test_parsebool
         
     | 
| 
      
 62 
     | 
    
         
            +
                  _true, _false = nil
         
     | 
| 
      
 63 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    _true = Boolean.parse(@true)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    _false = Boolean.parse(@false)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                  assert _false.false?
         
     | 
| 
      
 69 
     | 
    
         
            +
                  assert (not _true.false?)
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                def test_parsereal
         
     | 
| 
      
 73 
     | 
    
         
            +
                  real = nil
         
     | 
| 
      
 74 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 75 
     | 
    
         
            +
                    real = Real.parse(@real)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                  assert_equal real, -3.141592653
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                def test_parseint
         
     | 
| 
      
 82 
     | 
    
         
            +
                  int = nil
         
     | 
| 
      
 83 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 84 
     | 
    
         
            +
                    int = Origami::Integer.parse(@int)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                  assert_equal int, 2000000000000
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                def test_parsename
         
     | 
| 
      
 91 
     | 
    
         
            +
                  name = nil
         
     | 
| 
      
 92 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 93 
     | 
    
         
            +
                    name = Name.parse(@name)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  assert_equal name.value, :"RUby\n"
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
            end
         
     | 
    
        data/tests/tc_pdfsig.rb
    ADDED
    
    | 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              class TC_PdfSig < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @target = PDF.read("tests/dataset/calc.pdf", :ignore_errors => false, :verbosity => Parser::VERBOSE_QUIET)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @output = StringIO.new
         
     | 
| 
      
 9 
     | 
    
         
            +
             
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @cert = OpenSSL::X509::Certificate.new(File.open("tests/dataset/test.dummycrt").read)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @key = OpenSSL::PKey::RSA.new(File.open("tests/dataset/test.dummykey").read)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 15 
     | 
    
         
            +
                # end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def test_sig
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  sigannot = Annotation::Widget::Signature.new.set_indirect(true)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  sigannot.Rect = Rectangle[:llx => 89.0, :lly => 386.0, :urx => 190.0, :ury => 353.0]
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @target.append_page(page = Page.new)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    page.add_annot(sigannot)
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    @target.sign(@cert, @key, [], sigannot, "France", "fred@security-labs.org", "Proof of Concept (owned)")
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  assert @target.frozen?
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @target.save(@output)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
    
        data/tests/tc_streams.rb
    ADDED
    
    | 
         @@ -0,0 +1,129 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              class TC_Streams < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @target = PDF.new
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @output = StringIO.new
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @data = "0123456789" * 1024
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                # def teardown
         
     | 
| 
      
 12 
     | 
    
         
            +
                # end
         
     | 
| 
      
 13 
     | 
    
         
            +
                
         
     | 
| 
      
 14 
     | 
    
         
            +
                def test_predictors
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  stm.set_predictor(Filter::Predictor::TIFF)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 19 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 20 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_equal @data, stm.data
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  stm.set_predictor(Filter::Predictor::PNG_SUB)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 27 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 28 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  assert_equal @data, stm.data
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  stm.set_predictor(Filter::Predictor::PNG_UP)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 35 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 36 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  stm.set_predictor(Filter::Predictor::PNG_AVERAGE)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 43 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 44 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  stm.set_predictor(Filter::Predictor::PNG_PAETH)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 51 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 52 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
               end
         
     | 
| 
      
 57 
     | 
    
         
            +
               
         
     | 
| 
      
 58 
     | 
    
         
            +
                def test_filter_flate
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :FlateDecode)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 62 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 63 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                def test_filter_asciihex
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :ASCIIHexDecode)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 72 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 73 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                def test_filter_ascii85
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :ASCII85Decode)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 82 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 83 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                def test_filter_rle
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :RunLengthDecode)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 92 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 93 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                def test_filter_lzw
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :LZWDecode)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 102 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 103 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  assert_equal stm.data, @data
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                def test_filter_ccittfax
         
     | 
| 
      
 109 
     | 
    
         
            +
                  
         
     | 
| 
      
 110 
     | 
    
         
            +
                  stm = Stream.new(@data[0, 216], :Filter => :CCITTFaxDecode)
         
     | 
| 
      
 111 
     | 
    
         
            +
                  
         
     | 
| 
      
 112 
     | 
    
         
            +
                  raw = stm.rawdata
         
     | 
| 
      
 113 
     | 
    
         
            +
                  stm.data = nil
         
     | 
| 
      
 114 
     | 
    
         
            +
                  stm.rawdata = raw
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  assert_equal stm.data, @data[0, 216]
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                def test_stream
         
     | 
| 
      
 120 
     | 
    
         
            +
                  stm = Stream.new(@data, :Filter => :ASCIIHexDecode )
         
     | 
| 
      
 121 
     | 
    
         
            +
                  @target << stm
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                  stm.pre_build
         
     | 
| 
      
 124 
     | 
    
         
            +
                  assert stm.Length == stm.rawdata.length
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                  @target.save(@output)
         
     | 
| 
      
 127 
     | 
    
         
            +
                end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
            end
         
     | 
    
        data/tests/ts_pdf.rb
    ADDED
    
    | 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test/unit/testsuite'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'tc_pdfparse.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'tc_streams.rb'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tc_pdfencrypt.rb'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'tc_pdfsig.rb'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'tc_pdfattach.rb'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'tc_pages.rb'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'tc_actions.rb'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'tc_annotations.rb'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'tc_pdfnew.rb'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            begin
         
     | 
| 
      
 13 
     | 
    
         
            +
              require 'origami'
         
     | 
| 
      
 14 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 15 
     | 
    
         
            +
              ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
         
     | 
| 
      
 16 
     | 
    
         
            +
              $: << ORIGAMIDIR
         
     | 
| 
      
 17 
     | 
    
         
            +
              require 'origami'
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
| 
      
 19 
     | 
    
         
            +
            include Origami
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
             class TS_PdfTests
         
     | 
| 
      
 22 
     | 
    
         
            +
               def self.suite
         
     | 
| 
      
 23 
     | 
    
         
            +
                 suite = Test::Unit::TestSuite.new "PDF test suite"
         
     | 
| 
      
 24 
     | 
    
         
            +
                 suite << TC_PdfParse.suite
         
     | 
| 
      
 25 
     | 
    
         
            +
                 suite << TC_PdfNew.suite
         
     | 
| 
      
 26 
     | 
    
         
            +
                 suite << TC_Streams.suite
         
     | 
| 
      
 27 
     | 
    
         
            +
                 suite << TC_Pages.suite
         
     | 
| 
      
 28 
     | 
    
         
            +
                 suite << TC_PdfEncrypt.suite
         
     | 
| 
      
 29 
     | 
    
         
            +
                 suite << TC_PdfSig.suite
         
     | 
| 
      
 30 
     | 
    
         
            +
                 suite << TC_PdfAttach.suite
         
     | 
| 
      
 31 
     | 
    
         
            +
                 suite << TC_Actions.suite
         
     | 
| 
      
 32 
     | 
    
         
            +
                 suite << TC_Annotations.suite
         
     | 
| 
      
 33 
     | 
    
         
            +
                 suite
         
     | 
| 
      
 34 
     | 
    
         
            +
               end
         
     | 
| 
      
 35 
     | 
    
         
            +
             end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
         
     | 
| 
      
 37 
     | 
    
         
            +
            if ARGV.size > 0 and ARGV[0] == "gtk"
         
     | 
| 
      
 38 
     | 
    
         
            +
              require 'test/unit/ui/gtk2/testrunner'
         
     | 
| 
      
 39 
     | 
    
         
            +
              Test::Unit::UI::GTK2::TestRunner.run(TS_PdfTests)
         
     | 
| 
      
 40 
     | 
    
         
            +
            else
         
     | 
| 
      
 41 
     | 
    
         
            +
              require 'test/unit/ui/console/testrunner'
         
     | 
| 
      
 42 
     | 
    
         
            +
              Test::Unit::UI::Console::TestRunner.run(TS_PdfTests)
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            exit 0
         
     |