redcar 0.3.2dev → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +49 -2
- data/README.md +2 -7
- data/ROADMAP.md +8 -9
- data/Rakefile +29 -44
- data/bin/redcar +11 -2
- data/lib/openssl/History.txt +75 -0
- data/lib/openssl/License.txt +30 -0
- data/lib/openssl/Manifest.txt +99 -0
- data/lib/openssl/README.txt +24 -0
- data/lib/openssl/Rakefile +71 -0
- data/lib/openssl/build.properties.SAMPLE +7 -0
- data/lib/openssl/build.xml +57 -0
- data/lib/openssl/lib/jopenssl/version.rb +5 -0
- data/lib/openssl/lib/openssl.rb +24 -0
- data/lib/openssl/lib/openssl/bn.rb +33 -0
- data/lib/openssl/lib/openssl/buffering.rb +239 -0
- data/lib/openssl/lib/openssl/cipher.rb +56 -0
- data/lib/openssl/lib/openssl/digest.rb +46 -0
- data/lib/openssl/lib/openssl/dummy.rb +34 -0
- data/lib/openssl/lib/openssl/dummyssl.rb +13 -0
- data/lib/openssl/lib/openssl/ssl.rb +135 -0
- data/lib/openssl/lib/openssl/x509.rb +154 -0
- data/lib/openssl/mocha/COPYING +3 -0
- data/lib/openssl/mocha/MIT-LICENSE +7 -0
- data/lib/openssl/mocha/README +35 -0
- data/lib/openssl/mocha/RELEASE +171 -0
- data/lib/openssl/mocha/Rakefile +147 -0
- data/lib/openssl/mocha/TODO +48 -0
- data/lib/openssl/mocha/examples/misc.rb +36 -0
- data/lib/openssl/mocha/examples/mocha.rb +26 -0
- data/lib/openssl/mocha/examples/stubba.rb +65 -0
- data/lib/openssl/mocha/init.rb +3 -0
- data/lib/openssl/mocha/lib/mocha.rb +19 -0
- data/lib/openssl/mocha/lib/mocha/any_instance_method.rb +35 -0
- data/lib/openssl/mocha/lib/mocha/auto_verify.rb +111 -0
- data/lib/openssl/mocha/lib/mocha/central.rb +35 -0
- data/lib/openssl/mocha/lib/mocha/class_method.rb +62 -0
- data/lib/openssl/mocha/lib/mocha/deprecation.rb +22 -0
- data/lib/openssl/mocha/lib/mocha/exception_raiser.rb +17 -0
- data/lib/openssl/mocha/lib/mocha/expectation.rb +382 -0
- data/lib/openssl/mocha/lib/mocha/expectation_error.rb +6 -0
- data/lib/openssl/mocha/lib/mocha/expectation_list.rb +45 -0
- data/lib/openssl/mocha/lib/mocha/infinite_range.rb +25 -0
- data/lib/openssl/mocha/lib/mocha/inspect.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/instance_method.rb +8 -0
- data/lib/openssl/mocha/lib/mocha/is_a.rb +9 -0
- data/lib/openssl/mocha/lib/mocha/metaclass.rb +7 -0
- data/lib/openssl/mocha/lib/mocha/missing_expectation.rb +27 -0
- data/lib/openssl/mocha/lib/mocha/mock.rb +200 -0
- data/lib/openssl/mocha/lib/mocha/multiple_yields.rb +20 -0
- data/lib/openssl/mocha/lib/mocha/no_yields.rb +11 -0
- data/lib/openssl/mocha/lib/mocha/object.rb +110 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers.rb +9 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/all_of.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/any_of.rb +44 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/anything.rb +30 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/has_key.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/has_value.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/includes.rb +37 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/instance_of.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/parameter_matchers/kind_of.rb +39 -0
- data/lib/openssl/mocha/lib/mocha/pretty_parameters.rb +28 -0
- data/lib/openssl/mocha/lib/mocha/return_values.rb +31 -0
- data/lib/openssl/mocha/lib/mocha/setup_and_teardown.rb +23 -0
- data/lib/openssl/mocha/lib/mocha/single_return_value.rb +24 -0
- data/lib/openssl/mocha/lib/mocha/single_yield.rb +18 -0
- data/lib/openssl/mocha/lib/mocha/standalone.rb +32 -0
- data/lib/openssl/mocha/lib/mocha/stub.rb +18 -0
- data/lib/openssl/mocha/lib/mocha/test_case_adapter.rb +49 -0
- data/lib/openssl/mocha/lib/mocha/yield_parameters.rb +31 -0
- data/lib/openssl/mocha/lib/mocha_standalone.rb +2 -0
- data/lib/openssl/mocha/lib/stubba.rb +2 -0
- data/lib/openssl/mocha/templates/html_with_google_analytics.rb +742 -0
- data/lib/openssl/mocha/test/acceptance/expected_invocation_count_acceptance_test.rb +187 -0
- data/lib/openssl/mocha/test/acceptance/mocha_acceptance_test.rb +98 -0
- data/lib/openssl/mocha/test/acceptance/mocked_methods_dispatch_acceptance_test.rb +71 -0
- data/lib/openssl/mocha/test/acceptance/parameter_matcher_acceptance_test.rb +63 -0
- data/lib/openssl/mocha/test/acceptance/standalone_acceptance_test.rb +131 -0
- data/lib/openssl/mocha/test/acceptance/stubba_acceptance_test.rb +102 -0
- data/lib/openssl/mocha/test/active_record_test_case.rb +36 -0
- data/lib/openssl/mocha/test/deprecation_disabler.rb +15 -0
- data/lib/openssl/mocha/test/execution_point.rb +34 -0
- data/lib/openssl/mocha/test/integration/mocha_test_result_integration_test.rb +105 -0
- data/lib/openssl/mocha/test/integration/stubba_integration_test.rb +89 -0
- data/lib/openssl/mocha/test/integration/stubba_test_result_integration_test.rb +85 -0
- data/lib/openssl/mocha/test/method_definer.rb +18 -0
- data/lib/openssl/mocha/test/test_helper.rb +12 -0
- data/lib/openssl/mocha/test/test_runner.rb +31 -0
- data/lib/openssl/mocha/test/unit/any_instance_method_test.rb +124 -0
- data/lib/openssl/mocha/test/unit/array_inspect_test.rb +16 -0
- data/lib/openssl/mocha/test/unit/auto_verify_test.rb +122 -0
- data/lib/openssl/mocha/test/unit/central_test.rb +124 -0
- data/lib/openssl/mocha/test/unit/class_method_test.rb +196 -0
- data/lib/openssl/mocha/test/unit/date_time_inspect_test.rb +21 -0
- data/lib/openssl/mocha/test/unit/expectation_list_test.rb +69 -0
- data/lib/openssl/mocha/test/unit/expectation_raiser_test.rb +28 -0
- data/lib/openssl/mocha/test/unit/expectation_test.rb +399 -0
- data/lib/openssl/mocha/test/unit/hash_inspect_test.rb +16 -0
- data/lib/openssl/mocha/test/unit/infinite_range_test.rb +53 -0
- data/lib/openssl/mocha/test/unit/metaclass_test.rb +22 -0
- data/lib/openssl/mocha/test/unit/missing_expectation_test.rb +45 -0
- data/lib/openssl/mocha/test/unit/mock_test.rb +316 -0
- data/lib/openssl/mocha/test/unit/multiple_yields_test.rb +18 -0
- data/lib/openssl/mocha/test/unit/no_yield_test.rb +18 -0
- data/lib/openssl/mocha/test/unit/object_inspect_test.rb +35 -0
- data/lib/openssl/mocha/test/unit/object_test.rb +165 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/all_of_test.rb +26 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/any_of_test.rb +26 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/anything_test.rb +21 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/has_entry_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/has_key_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/has_value_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/includes_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/instance_of_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/kind_of_test.rb +25 -0
- data/lib/openssl/mocha/test/unit/parameter_matchers/stub_matcher.rb +22 -0
- data/lib/openssl/mocha/test/unit/pretty_parameters_test.rb +32 -0
- data/lib/openssl/mocha/test/unit/return_values_test.rb +63 -0
- data/lib/openssl/mocha/test/unit/setup_and_teardown_test.rb +76 -0
- data/lib/openssl/mocha/test/unit/single_return_value_test.rb +33 -0
- data/lib/openssl/mocha/test/unit/single_yield_test.rb +18 -0
- data/lib/openssl/mocha/test/unit/string_inspect_test.rb +11 -0
- data/lib/openssl/mocha/test/unit/stub_test.rb +24 -0
- data/lib/openssl/mocha/test/unit/yield_parameters_test.rb +93 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/FOLDERS +53 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/LICENSE +340 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/README +117 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/bin/coderay +77 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/bin/coderay_stylesheet +4 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay.rb +319 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/duo.rb +29 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoder.rb +173 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/_map.rb +8 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/count.rb +21 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/debug.rb +46 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/div.rb +20 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/html.rb +260 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/classes.rb +77 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/css.rb +65 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/numerization.rb +122 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/html/output.rb +195 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/null.rb +26 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/page.rb +21 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/span.rb +20 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/statistic.rb +81 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/text.rb +33 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/tokens.rb +44 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/xml.rb +71 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/encoders/yaml.rb +22 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/helpers/file_type.rb +182 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/helpers/gzip_simple.rb +122 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/helpers/plugin.rb +326 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/helpers/word_list.rb +119 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanner.rb +238 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/_map.rb +15 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/c.rb +163 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/debug.rb +60 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/delphi.rb +149 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/html.rb +177 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/nitro_xhtml.rb +133 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/plaintext.rb +16 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/rhtml.rb +73 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby.rb +367 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/ruby/patterns.rb +230 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/scanners/xml.rb +18 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/style.rb +20 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/styles/_map.rb +7 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/styles/cycnus.rb +125 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/styles/murphy.rb +119 -0
- data/lib/openssl/mocha/vendor/coderay-0.7.4.215/lib/coderay/tokens.rb +368 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/CHANGES +295 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/MIT-LICENSE +21 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/README +129 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/Rakefile +152 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project.rb +19 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/core_ext/open_uri.rb +22 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/core_ext/pathname.rb +36 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/core_ext/string.rb +5 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/http/multipart.rb +32 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/patois.rb +1 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/patois/parser.rb +99 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project.rb +4 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/base.rb +9 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus.rb +1 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/codehaus/codehaus_project_svn.rb +31 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/trac.rb +1 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/trac/trac_project.rb +54 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge.rb +5 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/ruby_forge.rb +47 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/session.rb +177 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/source_forge.rb +50 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xfile.rb +45 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project/xforge/xforge_base.rb +85 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/project_analyzer.rb +36 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/release/freshmeat.rb +267 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/release/raa.rb +572 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/scm_web.rb +2 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/scm_web/browser.rb +112 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/scm_web/pathname.rb +89 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker.rb +6 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/base.rb +24 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/digit_issues.rb +34 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/issue.rb +57 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira.rb +2 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_issues.rb +35 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/jira/jira_tracker.rb +149 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac.rb +1 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/trac/trac_tracker.rb +33 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge.rb +3 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/ruby_forge_tracker.rb +17 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/source_forge_tracker.rb +17 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/tracker/xforge/xforge_tracker.rb +191 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/meta_project/version_parser.rb +52 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/rake/contrib/xforge.rb +3 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/base.rb +64 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/news_publisher.rb +97 -0
- data/lib/openssl/mocha/vendor/meta_project-0.4.15/lib/rake/contrib/xforge/release.rb +134 -0
- data/lib/openssl/nbproject/genfiles.properties +5 -0
- data/lib/openssl/nbproject/jdk.xml +157 -0
- data/lib/openssl/nbproject/nbjdk.properties +1 -0
- data/lib/openssl/nbproject/nbjdk.xml +16 -0
- data/lib/openssl/nbproject/project.xml +117 -0
- data/lib/openssl/src/java/JopensslService.java +41 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/ASN1.java +930 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Attribute.java +132 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/BN.java +769 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/BouncyCastlePEMHandler.java +69 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Callable.java +10 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Cipher.java +661 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/CipherStrings.java +1827 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Config.java +49 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/DefaultPEMHandler.java +44 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Digest.java +207 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/HMAC.java +183 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/NetscapeSPKI.java +212 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/OpenSSLImpl.java +341 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java +113 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PEMHandler.java +40 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKCS10CertificationRequestExt.java +159 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKCS7.java +642 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKey.java +154 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKeyDH.java +401 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKeyDSA.java +419 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/PKeyRSA.java +762 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Random.java +103 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Request.java +336 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/SSL.java +71 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/SSLContext.java +358 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/SSLSocket.java +561 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/SimpleSecretKey.java +53 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/Utils.java +60 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509.java +108 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509CRL.java +446 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509Cert.java +520 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509Extensions.java +751 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509Name.java +405 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509Revoked.java +111 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509Store.java +282 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/X509StoreCtx.java +206 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/ASN1Registry.java +5135 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Attribute.java +79 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/BIO.java +345 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/BIOFilter.java +38 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Base64BIOFilter.java +84 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/CipherBIOFilter.java +157 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Digest.java +126 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/EVP.java +136 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/EncContent.java +178 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Encrypt.java +77 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Envelope.java +169 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/IssuerAndSerial.java +35 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/MemBIO.java +117 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/MessageDigestBIOFilter.java +76 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Mime.java +245 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/MimeHeader.java +103 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/MimeParam.java +69 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/NotVerifiedPKCS7Exception.java +38 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/NullSinkBIO.java +52 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7.java +1276 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7Data.java +168 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataData.java +88 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataDigest.java +64 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataEncrypted.java +61 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataEnveloped.java +85 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataSigned.java +127 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7DataSignedAndEnveloped.java +91 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/PKCS7Exception.java +68 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/RecipInfo.java +244 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/SMIME.java +281 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/SignEnvelope.java +202 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/Signed.java +345 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/SignerInfoWithPkey.java +365 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/TypeDiscriminating.java +34 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/impl/utils/Base64.java +1809 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/util/Base64Coder.java +103 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/CRL.java +59 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Certificate.java +57 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/CertificateFile.java +46 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/CertificateHashDir.java +46 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function0.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function1.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function2.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function3.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function4.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Function5.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Lookup.java +560 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/LookupMethod.java +84 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Name.java +85 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/PEMInputOutput.java +1210 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/PKey.java +41 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/PolicyTree.java +36 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Purpose.java +475 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Store.java +377 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/StoreContext.java +1356 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/Trust.java +279 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/VerifyParameter.java +324 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/X509Aux.java +43 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/X509AuxCertificate.java +170 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/X509Error.java +70 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/X509Object.java +88 -0
- data/lib/openssl/src/java/org/jruby/ext/openssl/x509store/X509Utils.java +541 -0
- data/lib/openssl/test/cert_with_ec_pk.cer +27 -0
- data/lib/openssl/test/fixture/ca_path/72fa7371.0 +19 -0
- data/lib/openssl/test/fixture/ca_path/verisign.pem +19 -0
- data/lib/openssl/test/fixture/cacert.pem +23 -0
- data/lib/openssl/test/fixture/cert_localhost.pem +19 -0
- data/lib/openssl/test/fixture/common.pem +48 -0
- data/lib/openssl/test/fixture/localhost_keypair.pem +18 -0
- data/lib/openssl/test/fixture/max.pem +29 -0
- data/lib/openssl/test/fixture/purpose/b70a5bc1.0 +24 -0
- data/lib/openssl/test/fixture/purpose/ca/PASSWD_OF_CA_KEY_IS_1234 +0 -0
- data/lib/openssl/test/fixture/purpose/ca/ca_config.rb +37 -0
- data/lib/openssl/test/fixture/purpose/ca/cacert.pem +24 -0
- data/lib/openssl/test/fixture/purpose/ca/newcerts/2_cert.pem +19 -0
- data/lib/openssl/test/fixture/purpose/ca/newcerts/3_cert.pem +19 -0
- data/lib/openssl/test/fixture/purpose/ca/private/cakeypair.pem +30 -0
- data/lib/openssl/test/fixture/purpose/ca/serial +1 -0
- data/lib/openssl/test/fixture/purpose/cacert.pem +24 -0
- data/lib/openssl/test/fixture/purpose/scripts/gen_cert.rb +127 -0
- data/lib/openssl/test/fixture/purpose/scripts/gen_csr.rb +50 -0
- data/lib/openssl/test/fixture/purpose/scripts/init_ca.rb +66 -0
- data/lib/openssl/test/fixture/purpose/sslclient.pem +19 -0
- data/lib/openssl/test/fixture/purpose/sslclient/csr.pem +10 -0
- data/lib/openssl/test/fixture/purpose/sslclient/keypair.pem +15 -0
- data/lib/openssl/test/fixture/purpose/sslclient/sslclient.pem +19 -0
- data/lib/openssl/test/fixture/purpose/sslserver.pem +19 -0
- data/lib/openssl/test/fixture/purpose/sslserver/csr.pem +10 -0
- data/lib/openssl/test/fixture/purpose/sslserver/keypair.pem +15 -0
- data/lib/openssl/test/fixture/purpose/sslserver/sslserver.pem +19 -0
- data/lib/openssl/test/fixture/verisign.pem +19 -0
- data/lib/openssl/test/fixture/verisign_c3.pem +14 -0
- data/lib/openssl/test/openssl/ssl_server.rb +99 -0
- data/lib/openssl/test/openssl/test_asn1.rb +199 -0
- data/lib/openssl/test/openssl/test_cipher.rb +196 -0
- data/lib/openssl/test/openssl/test_digest.rb +88 -0
- data/lib/openssl/test/openssl/test_hmac.rb +44 -0
- data/lib/openssl/test/openssl/test_ns_spki.rb +69 -0
- data/lib/openssl/test/openssl/test_pair.rb +149 -0
- data/lib/openssl/test/openssl/test_pkcs7.rb +160 -0
- data/lib/openssl/test/openssl/test_pkey_rsa.rb +49 -0
- data/lib/openssl/test/openssl/test_ssl.rb +413 -0
- data/lib/openssl/test/openssl/test_x509cert.rb +236 -0
- data/lib/openssl/test/openssl/test_x509crl.rb +234 -0
- data/lib/openssl/test/openssl/test_x509ext.rb +95 -0
- data/lib/openssl/test/openssl/test_x509name.rb +281 -0
- data/lib/openssl/test/openssl/test_x509req.rb +178 -0
- data/lib/openssl/test/openssl/test_x509store.rb +245 -0
- data/lib/openssl/test/openssl/utils.rb +135 -0
- data/lib/openssl/test/pkcs7_mime_enveloped.message +19 -0
- data/lib/openssl/test/pkcs7_mime_signed.message +30 -0
- data/lib/openssl/test/pkcs7_multipart_signed.message +45 -0
- data/lib/openssl/test/ref/compile.rb +8 -0
- data/lib/openssl/test/ref/pkcs1 +0 -0
- data/lib/openssl/test/ref/pkcs1.c +21 -0
- data/lib/openssl/test/test_cipher.rb +95 -0
- data/lib/openssl/test/test_integration.rb +139 -0
- data/lib/openssl/test/test_java.rb +98 -0
- data/lib/openssl/test/test_java_attribute.rb +25 -0
- data/lib/openssl/test/test_java_bio.rb +42 -0
- data/lib/openssl/test/test_java_mime.rb +173 -0
- data/lib/openssl/test/test_java_pkcs7.rb +769 -0
- data/lib/openssl/test/test_java_smime.rb +177 -0
- data/lib/openssl/test/test_openssl.rb +34 -0
- data/lib/openssl/test/test_openssl_x509.rb +34 -0
- data/lib/openssl/test/test_parse_certificate.rb +20 -0
- data/lib/openssl/test/test_pkey.rb +46 -0
- data/lib/openssl/test/test_x509store.rb +155 -0
- data/lib/openssl/test/ut_eof.rb +128 -0
- data/lib/redcar.rb +134 -8
- data/lib/redcar/installer.rb +46 -11
- data/lib/redcar/runner.rb +2 -1
- data/lib/redcar/usage.rb +12 -5
- data/lib/redcar_quick_start.rb +37 -0
- data/plugins/application/features/support/env.rb +9 -1
- data/plugins/application/icons/redcar_icon_beta.png +0 -0
- data/plugins/application/lib/application.rb +113 -43
- data/plugins/application/lib/application/clipboard.rb +28 -4
- data/plugins/application/lib/application/command.rb +4 -12
- data/plugins/application/lib/application/command/executor.rb +2 -2
- data/plugins/application/lib/application/keymap.rb +39 -0
- data/plugins/application/lib/application/keymap/builder.rb +19 -0
- data/plugins/application/lib/application/speedbar.rb +33 -24
- data/plugins/application/lib/application/tab.rb +15 -0
- data/plugins/application/lib/application/window.rb +28 -5
- data/plugins/application/spec/application/clipboard_spec.rb +20 -1
- data/plugins/application/spec/application/command/executor_spec.rb +7 -2
- data/plugins/application/spec/application/command_spec.rb +0 -5
- data/plugins/application/spec/application/keymap/builder_spec.rb +17 -0
- data/plugins/application/spec/application/menu_spec.rb +30 -0
- data/plugins/application/spec/application/speedbar_spec.rb +30 -6
- data/plugins/application/spec/application/window_spec.rb +2 -2
- data/plugins/application/spec/spec_helper.rb +1 -1
- data/plugins/application_swt/lib/application_swt.rb +3 -0
- data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +10 -1
- data/plugins/application_swt/lib/application_swt/html_tab.rb +1 -0
- data/plugins/application_swt/lib/application_swt/menu.rb +4 -3
- data/plugins/application_swt/lib/application_swt/menu/binding_translator.rb +12 -4
- data/plugins/application_swt/lib/application_swt/speedbar.rb +105 -19
- data/plugins/application_swt/lib/application_swt/swt_wrapper.rb +2 -0
- data/plugins/application_swt/lib/application_swt/window.rb +55 -23
- data/plugins/application_swt/spec/spec_helper.rb +0 -1
- data/plugins/auto_completer/lib/auto_completer.rb +57 -3
- data/plugins/auto_indenter/lib/auto_indenter.rb +1 -1
- data/plugins/core/lib/core.rb +5 -3
- data/plugins/core/lib/core/interface.rb +73 -0
- data/plugins/core/lib/core/model.rb +2 -0
- data/plugins/core/lib/core/observable.rb +12 -1
- data/plugins/core/lib/core/observable_struct.rb +34 -0
- data/plugins/core/lib/core/plugin/storage.rb +16 -3
- data/plugins/core/lib/core/reentry_helpers.rb +13 -0
- data/plugins/core/spec/core/observable_spec.rb +13 -0
- data/plugins/core/spec/core/storage_spec.rb +18 -0
- data/plugins/core/spec/spec_helper.rb +1 -0
- data/plugins/edit_view/features/cut_and_paste.feature +4 -2
- data/plugins/edit_view/features/soft_tabs.feature +243 -0
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +91 -2
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
- data/plugins/edit_view/features/tabs.feature +146 -0
- data/plugins/edit_view/lib/edit_view.rb +197 -8
- data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +121 -0
- data/plugins/edit_view/lib/edit_view/actions/deletion.rb +30 -0
- data/plugins/edit_view/lib/edit_view/actions/tab.rb +66 -0
- data/plugins/edit_view/lib/edit_view/command.rb +0 -2
- data/plugins/edit_view/lib/edit_view/document.rb +62 -27
- data/plugins/edit_view/lib/edit_view/document/command.rb +11 -0
- data/plugins/edit_view/lib/edit_view/edit_tab.rb +2 -1
- data/plugins/edit_view/lib/edit_view/info_speedbar.rb +69 -0
- data/plugins/edit_view/lib/edit_view/tab_settings.rb +40 -0
- data/plugins/edit_view/spec/edit_view/document_spec.rb +26 -0
- data/plugins/edit_view/spec/spec_helper.rb +0 -1
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +57 -69
- data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +24 -3
- data/plugins/edit_view_swt/lib/edit_view_swt/edit_tab.rb +23 -6
- data/plugins/edit_view_swt/spec/spec_helper.rb +0 -1
- data/plugins/edit_view_swt/vendor/java-mateview.rb +19 -2
- data/plugins/encryption/encryption.rb +38 -0
- data/plugins/encryption/ezcrypto.rb +652 -0
- data/plugins/encryption/jarmor-1.1.jar +0 -0
- data/plugins/encryption/plugin.rb +9 -0
- data/plugins/execute_current_tab/lib/execute_current_tab.rb +56 -0
- data/plugins/execute_current_tab/plugin.rb +8 -0
- data/plugins/html_view/lib/html_view.rb +16 -11
- data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +2 -1
- data/plugins/plugin_manager_ui/views/index.html.erb +22 -4
- data/plugins/project/lib/project.rb +140 -26
- data/plugins/project/lib/project/drb_service.rb +75 -0
- data/plugins/project/lib/project/file_mirror.rb +5 -5
- data/plugins/project/lib/project/find_file_dialog.rb +123 -32
- data/plugins/project/spec/project/file_mirror_spec.rb +10 -1
- data/plugins/project/spec/spec_helper.rb +0 -1
- data/plugins/redcar/plugin.rb +1 -1
- data/plugins/redcar/redcar.rb +204 -109
- data/plugins/redcar/spec/redcar/redcar_spec.rb +70 -0
- data/plugins/redcar/spec/spec_helper.rb +4 -0
- data/plugins/repl/lib/repl.rb +14 -7
- data/plugins/repl/lib/repl/internal_mirror.rb +43 -22
- data/plugins/repl/spec/repl/internal_mirror_spec.rb +34 -7
- data/plugins/repl/spec/spec_helper.rb +0 -1
- data/plugins/tree/spec/spec_helper.rb +0 -1
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +1 -1
- data/textmate/Bundles/RedcarRepl.tmbundle/Syntaxes/InternalRuby.plist +2 -18
- data/textmate/Bundles/asciidoc.tmbundle/Syntaxes/AsciiDoc.tmLanguage +428 -0
- metadata +790 -371
- data/lib/redcar/boot.rb +0 -108
@@ -0,0 +1,132 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Version: CPL 1.0/GPL 2.0/LGPL 2.1
|
3
|
+
*
|
4
|
+
* The contents of this file are subject to the Common Public
|
5
|
+
* License Version 1.0 (the "License"); you may not use this file
|
6
|
+
* except in compliance with the License. You may obtain a copy of
|
7
|
+
* the License at http://www.eclipse.org/legal/cpl-v10.html
|
8
|
+
*
|
9
|
+
* Software distributed under the License is distributed on an "AS
|
10
|
+
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
11
|
+
* implied. See the License for the specific language governing
|
12
|
+
* rights and limitations under the License.
|
13
|
+
*
|
14
|
+
* Copyright (C) 2006 Ola Bini <ola@ologix.com>
|
15
|
+
*
|
16
|
+
* Alternatively, the contents of this file may be used under the terms of
|
17
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
18
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
19
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
20
|
+
* of those above. If you wish to allow use of your version of this file only
|
21
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
22
|
+
* use your version of this file under the terms of the CPL, indicate your
|
23
|
+
* decision by deleting the provisions above and replace them with the notice
|
24
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
25
|
+
* the provisions above, a recipient may use your version of this file under
|
26
|
+
* the terms of any one of the CPL, the GPL or the LGPL.
|
27
|
+
***** END LICENSE BLOCK *****/
|
28
|
+
package org.jruby.ext.openssl;
|
29
|
+
|
30
|
+
import org.bouncycastle.asn1.ASN1EncodableVector;
|
31
|
+
import org.bouncycastle.asn1.DERObject;
|
32
|
+
import org.bouncycastle.asn1.DERObjectIdentifier;
|
33
|
+
import org.bouncycastle.asn1.DERSequence;
|
34
|
+
import org.bouncycastle.asn1.DERSet;
|
35
|
+
import org.jruby.Ruby;
|
36
|
+
import org.jruby.RubyClass;
|
37
|
+
import org.jruby.RubyModule;
|
38
|
+
import org.jruby.RubyObject;
|
39
|
+
import org.jruby.anno.JRubyMethod;
|
40
|
+
import org.jruby.runtime.Block;
|
41
|
+
import org.jruby.runtime.ObjectAllocator;
|
42
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
|
46
|
+
*/
|
47
|
+
public class Attribute extends RubyObject {
|
48
|
+
private static ObjectAllocator ATTRIBUTE_ALLOCATOR = new ObjectAllocator() {
|
49
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
50
|
+
return new Attribute(runtime, klass);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
public static void createAttribute(Ruby runtime, RubyModule mX509) {
|
55
|
+
RubyClass cAttribute = mX509.defineClassUnder("Attribute",runtime.getObject(), ATTRIBUTE_ALLOCATOR);
|
56
|
+
|
57
|
+
RubyClass openSSLError = runtime.getModule("OpenSSL").getClass("OpenSSLError");
|
58
|
+
mX509.defineClassUnder("AttributeError",openSSLError, openSSLError.getAllocator());
|
59
|
+
|
60
|
+
cAttribute.defineAnnotatedMethods(Attribute.class);
|
61
|
+
}
|
62
|
+
|
63
|
+
public Attribute(Ruby runtime, RubyClass type) {
|
64
|
+
super(runtime,type);
|
65
|
+
}
|
66
|
+
|
67
|
+
private IRubyObject oid;
|
68
|
+
private IRubyObject value;
|
69
|
+
|
70
|
+
private DERObjectIdentifier getObjectIdentifier(String nameOrOid) {
|
71
|
+
Object val1 = ASN1.getOIDLookup(getRuntime()).get(nameOrOid.toLowerCase());
|
72
|
+
if(null != val1) {
|
73
|
+
return (DERObjectIdentifier)val1;
|
74
|
+
}
|
75
|
+
DERObjectIdentifier val2 = new DERObjectIdentifier(nameOrOid);
|
76
|
+
return val2;
|
77
|
+
}
|
78
|
+
|
79
|
+
DERObject toASN1() throws Exception {
|
80
|
+
ASN1EncodableVector v1 = new ASN1EncodableVector();
|
81
|
+
v1.add(getObjectIdentifier(oid.toString()));
|
82
|
+
if(value instanceof ASN1.ASN1Constructive) {
|
83
|
+
v1.add(((ASN1.ASN1Constructive)value).toASN1());
|
84
|
+
} else {
|
85
|
+
ASN1EncodableVector v2 = new ASN1EncodableVector();
|
86
|
+
v2.add(((ASN1.ASN1Data)value).toASN1());
|
87
|
+
v1.add(new DERSet(v2));
|
88
|
+
}
|
89
|
+
return new DERSequence(v1);
|
90
|
+
}
|
91
|
+
|
92
|
+
@JRubyMethod(name="initialize", required=1, optional=1)
|
93
|
+
public IRubyObject _initialize(IRubyObject[] str) throws Exception {
|
94
|
+
if(org.jruby.runtime.Arity.checkArgumentCount(getRuntime(),str,1,2) == 1) {
|
95
|
+
IRubyObject _oid = OpenSSLImpl.to_der_if_possible(str[0]);
|
96
|
+
set_oid(_oid);
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
set_oid(str[0]);
|
100
|
+
set_value(str[1]);
|
101
|
+
return this;
|
102
|
+
}
|
103
|
+
|
104
|
+
@JRubyMethod
|
105
|
+
public IRubyObject to_der() {
|
106
|
+
System.err.println("WARNING: unimplemented method called: attr#to_der");
|
107
|
+
return getRuntime().getNil();
|
108
|
+
}
|
109
|
+
|
110
|
+
@JRubyMethod
|
111
|
+
public IRubyObject oid() {
|
112
|
+
return oid;
|
113
|
+
}
|
114
|
+
|
115
|
+
@JRubyMethod(name="oid=")
|
116
|
+
public IRubyObject set_oid(IRubyObject val) {
|
117
|
+
this.oid = val;
|
118
|
+
return val;
|
119
|
+
}
|
120
|
+
|
121
|
+
@JRubyMethod
|
122
|
+
public IRubyObject value() {
|
123
|
+
return value;
|
124
|
+
}
|
125
|
+
|
126
|
+
@JRubyMethod(name="value=")
|
127
|
+
public IRubyObject set_value(IRubyObject val) throws Exception {
|
128
|
+
IRubyObject tmp = OpenSSLImpl.to_der_if_possible(val);
|
129
|
+
this.value = ASN1.decode(getRuntime().getModule("OpenSSL").getConstant("ASN1"),tmp);
|
130
|
+
return val;
|
131
|
+
}
|
132
|
+
}// Attribute
|
@@ -0,0 +1,769 @@
|
|
1
|
+
/***** BEGIN LICENSE BLOCK *****
|
2
|
+
* Version: CPL 1.0/GPL 2.0/LGPL 2.1
|
3
|
+
*
|
4
|
+
* The contents of this file are subject to the Common Public
|
5
|
+
* License Version 1.0 (the "License"); you may not use this file
|
6
|
+
* except in compliance with the License. You may obtain a copy of
|
7
|
+
* the License at http://www.eclipse.org/legal/cpl-v10.html
|
8
|
+
*
|
9
|
+
* Software distributed under the License is distributed on an "AS
|
10
|
+
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
11
|
+
* implied. See the License for the specific language governing
|
12
|
+
* rights and limitations under the License.
|
13
|
+
*
|
14
|
+
* Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
15
|
+
*
|
16
|
+
* Alternatively, the contents of this file may be used under the terms of
|
17
|
+
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
18
|
+
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
19
|
+
* in which case the provisions of the GPL or the LGPL are applicable instead
|
20
|
+
* of those above. If you wish to allow use of your version of this file only
|
21
|
+
* under the terms of either the GPL or the LGPL, and not to allow others to
|
22
|
+
* use your version of this file under the terms of the CPL, indicate your
|
23
|
+
* decision by deleting the provisions above and replace them with the notice
|
24
|
+
* and other provisions required by the GPL or the LGPL. If you do not delete
|
25
|
+
* the provisions above, a recipient may use your version of this file under
|
26
|
+
* the terms of any one of the CPL, the GPL or the LGPL.
|
27
|
+
***** END LICENSE BLOCK *****/
|
28
|
+
package org.jruby.ext.openssl;
|
29
|
+
|
30
|
+
import java.math.BigInteger;
|
31
|
+
import java.security.SecureRandom;
|
32
|
+
import java.util.Random;
|
33
|
+
|
34
|
+
import org.jruby.Ruby;
|
35
|
+
import org.jruby.RubyClass;
|
36
|
+
import org.jruby.RubyFixnum;
|
37
|
+
import org.jruby.RubyKernel;
|
38
|
+
import org.jruby.RubyModule;
|
39
|
+
import org.jruby.RubyNumeric;
|
40
|
+
import org.jruby.RubyObject;
|
41
|
+
import org.jruby.RubyString;
|
42
|
+
import org.jruby.anno.JRubyMethod;
|
43
|
+
import org.jruby.exceptions.RaiseException;
|
44
|
+
import org.jruby.runtime.Arity;
|
45
|
+
import org.jruby.runtime.Block;
|
46
|
+
import org.jruby.runtime.ClassIndex;
|
47
|
+
import org.jruby.runtime.ObjectAllocator;
|
48
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
49
|
+
import org.jruby.util.ByteList;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* OpenSSL::BN implementation. Wraps java.math.BigInteger, which provides
|
53
|
+
* most functionality directly; the rest is easily derived.
|
54
|
+
*
|
55
|
+
* Beware that BN's are mutable -- I don't agree with this approach, but
|
56
|
+
* must conform for compatibility with MRI's implementation. The offending methods
|
57
|
+
* are set_bit!, clear_bit!, mask_bits! and copy.<p>
|
58
|
+
*
|
59
|
+
* I've included a few operations (& | ^ ~) that aren't defined by MRI/OpenSSL.
|
60
|
+
* These are non-portable (i.e., won't work in C-Ruby), so use at your own risk.<p>
|
61
|
+
*
|
62
|
+
* @author <a href="mailto:bill.dortch@gmail.com">Bill Dortch</a>
|
63
|
+
*/
|
64
|
+
public class BN extends RubyObject {
|
65
|
+
private static final long serialVersionUID = -5660938062191525498L;
|
66
|
+
|
67
|
+
private static final BigInteger MAX_INT = BigInteger.valueOf(Integer.MAX_VALUE);
|
68
|
+
private static final BigInteger TWO = BigInteger.valueOf(2);
|
69
|
+
private static final int DEFAULT_CERTAINTY = 100;
|
70
|
+
private static Random _random;
|
71
|
+
private static SecureRandom _secureRandom;
|
72
|
+
|
73
|
+
private static ObjectAllocator BN_ALLOCATOR = new ObjectAllocator() {
|
74
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
75
|
+
return new BN(runtime, klass, BigInteger.ZERO);
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
public static BN newBN(Ruby runtime, BigInteger value) {
|
80
|
+
return new BN(runtime, value != null ? value : BigInteger.ZERO);
|
81
|
+
}
|
82
|
+
|
83
|
+
public static void createBN(Ruby runtime, RubyModule ossl) {
|
84
|
+
RubyClass openSSLError = ossl.getClass("OpenSSLError");
|
85
|
+
ossl.defineClassUnder("BNError", openSSLError, openSSLError.getAllocator());
|
86
|
+
|
87
|
+
RubyClass bn = ossl.defineClassUnder("BN", runtime.getObject(), BN_ALLOCATOR);
|
88
|
+
|
89
|
+
bn.defineAnnotatedMethods(BN.class);
|
90
|
+
}
|
91
|
+
|
92
|
+
private volatile BigInteger value;
|
93
|
+
|
94
|
+
private BN(Ruby runtime, RubyClass clazz, BigInteger value) {
|
95
|
+
super(runtime, clazz);
|
96
|
+
this.value = value;
|
97
|
+
}
|
98
|
+
|
99
|
+
private BN(Ruby runtime, BigInteger value) {
|
100
|
+
super(runtime, runtime.getModule("OpenSSL").getClass("BN"));
|
101
|
+
this.value = value;
|
102
|
+
}
|
103
|
+
|
104
|
+
public BigInteger getValue() {
|
105
|
+
return value;
|
106
|
+
}
|
107
|
+
|
108
|
+
// TODO: check whether this is really needed for JRuby 1.0x (not used in 1.1x)
|
109
|
+
public IRubyObject doClone() {
|
110
|
+
return newBN(getRuntime(), this.value);
|
111
|
+
}
|
112
|
+
|
113
|
+
public IRubyObject initialize_copy(IRubyObject original) {
|
114
|
+
super.initialize_copy(original);
|
115
|
+
if (this != original) {
|
116
|
+
this.value = ((BN)original).value;
|
117
|
+
}
|
118
|
+
return this;
|
119
|
+
}
|
120
|
+
|
121
|
+
@JRubyMethod(name="initialize", required=1, optional=1)
|
122
|
+
public synchronized IRubyObject bn_initialize(IRubyObject[] args) {
|
123
|
+
Ruby runtime = getRuntime();
|
124
|
+
if (this.value != BigInteger.ZERO) { // already initialized
|
125
|
+
throw newBNError(runtime, "illegal initialization");
|
126
|
+
}
|
127
|
+
int argc = Arity.checkArgumentCount(runtime, args, 1, 2);
|
128
|
+
int base = argc == 2 ? RubyNumeric.num2int(args[1]) : 10;
|
129
|
+
RubyString str = RubyString.stringValue(args[0]);
|
130
|
+
switch (base) {
|
131
|
+
case 2:
|
132
|
+
// this seems wrong to me, but is the behavior of the
|
133
|
+
// MRI implementation. rather than interpreting the string
|
134
|
+
// as ASCII-encoded binary digits, the raw binary value of
|
135
|
+
// the string is used instead. the value is always interpreted
|
136
|
+
// as positive, hence the use of the signum version of the BI
|
137
|
+
// constructor here:
|
138
|
+
this.value = new BigInteger(1, str.getBytes());
|
139
|
+
break;
|
140
|
+
case 10:
|
141
|
+
case 16:
|
142
|
+
// here, the ASCII-encoded decimal or hex string is used
|
143
|
+
try {
|
144
|
+
this.value = new BigInteger(str.toString(), base);
|
145
|
+
break;
|
146
|
+
} catch (NumberFormatException e) {
|
147
|
+
throw runtime.newArgumentError("value " + str + " is not legal for radix " + base);
|
148
|
+
}
|
149
|
+
case 0: // FIXME: not currently supporting BN_mpi2bn
|
150
|
+
throw runtime.newArgumentError("unsupported radix: " + base);
|
151
|
+
default:
|
152
|
+
throw runtime.newArgumentError("illegal radix: " + base);
|
153
|
+
}
|
154
|
+
return this;
|
155
|
+
}
|
156
|
+
|
157
|
+
@JRubyMethod(name="copy")
|
158
|
+
public synchronized IRubyObject bn_copy(IRubyObject other) {
|
159
|
+
if (this != other) {
|
160
|
+
this.value = getBigInteger(other);
|
161
|
+
}
|
162
|
+
return this;
|
163
|
+
}
|
164
|
+
|
165
|
+
@JRubyMethod(name="to_s", rest=true)
|
166
|
+
public IRubyObject bn_to_s(IRubyObject[] args) {
|
167
|
+
Ruby runtime = getRuntime();
|
168
|
+
int argc = Arity.checkArgumentCount(runtime, args, 0, 1);
|
169
|
+
int base = argc == 1 ? RubyNumeric.num2int(args[0]) : 10;
|
170
|
+
switch (base) {
|
171
|
+
case 2:
|
172
|
+
// again, following MRI implementation, wherein base 2 deals
|
173
|
+
// with strings as byte arrays rather than ASCII-encoded binary
|
174
|
+
// digits. note that negative values are returned as though positive:
|
175
|
+
|
176
|
+
byte[] bytes = this.value.abs().toByteArray();
|
177
|
+
|
178
|
+
// suppress leading 0 byte to conform to MRI behavior
|
179
|
+
if (bytes[0] == 0) {
|
180
|
+
return runtime.newString(new ByteList(bytes, 1, bytes.length - 1));
|
181
|
+
}
|
182
|
+
return runtime.newString(new ByteList(bytes, false));
|
183
|
+
case 10:
|
184
|
+
case 16:
|
185
|
+
return runtime.newString(value.toString(base).toUpperCase());
|
186
|
+
case 0: // FIXME: not currently supporting BN_mpi2bn
|
187
|
+
throw runtime.newArgumentError("unsupported radix: " + base);
|
188
|
+
default:
|
189
|
+
throw runtime.newArgumentError("illegal radix: " + base);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
@JRubyMethod(name="to_i")
|
194
|
+
public IRubyObject bn_to_i() {
|
195
|
+
Ruby runtime = getRuntime();
|
196
|
+
// FIXME: s/b faster way to convert than going through RubyString
|
197
|
+
return RubyNumeric.str2inum(runtime, runtime.newString(value.toString()), 10, true);
|
198
|
+
}
|
199
|
+
|
200
|
+
@JRubyMethod(name="to_bn")
|
201
|
+
public IRubyObject bn_to_bn() {
|
202
|
+
return this;
|
203
|
+
}
|
204
|
+
|
205
|
+
@JRubyMethod(name="coerce")
|
206
|
+
// FIXME: is this right? don't see how it would be useful...
|
207
|
+
public IRubyObject bn_coerce(IRubyObject other) {
|
208
|
+
Ruby runtime = getRuntime();
|
209
|
+
IRubyObject self;
|
210
|
+
switch (other.getMetaClass().index) {
|
211
|
+
case ClassIndex.STRING:
|
212
|
+
self = runtime.newString(value.toString());
|
213
|
+
break;
|
214
|
+
case ClassIndex.FIXNUM:
|
215
|
+
case ClassIndex.BIGNUM:
|
216
|
+
// FIXME: s/b faster way to convert than going through RubyString
|
217
|
+
self = RubyNumeric.str2inum(runtime, runtime.newString(value.toString()), 10, true);
|
218
|
+
break;
|
219
|
+
default:
|
220
|
+
if (other instanceof BN) {
|
221
|
+
self = this;
|
222
|
+
} else {
|
223
|
+
throw runtime.newTypeError("Don't know how to coerce");
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return runtime.newArray(other, self);
|
227
|
+
}
|
228
|
+
|
229
|
+
@JRubyMethod(name="zero?")
|
230
|
+
public IRubyObject bn_is_zero() {
|
231
|
+
return getRuntime().newBoolean(value.equals(BigInteger.ZERO));
|
232
|
+
}
|
233
|
+
|
234
|
+
@JRubyMethod(name="one?")
|
235
|
+
public IRubyObject bn_is_one() {
|
236
|
+
return getRuntime().newBoolean(value.equals(BigInteger.ONE));
|
237
|
+
}
|
238
|
+
|
239
|
+
@JRubyMethod(name="odd?")
|
240
|
+
public IRubyObject bn_is_odd() {
|
241
|
+
return getRuntime().newBoolean(value.testBit(0));
|
242
|
+
}
|
243
|
+
|
244
|
+
@JRubyMethod(name={"cmp", "<=>"})
|
245
|
+
public IRubyObject bn_cmp(IRubyObject other) {
|
246
|
+
return getRuntime().newFixnum(value.compareTo(getBigInteger(other)));
|
247
|
+
}
|
248
|
+
|
249
|
+
@JRubyMethod(name="ucmp")
|
250
|
+
public IRubyObject bn_ucmp(IRubyObject other) {
|
251
|
+
return getRuntime().newFixnum(value.abs().compareTo(getBigInteger(other).abs()));
|
252
|
+
}
|
253
|
+
|
254
|
+
@JRubyMethod(name={"eql?", "==", "==="})
|
255
|
+
public IRubyObject bn_eql(IRubyObject other) {
|
256
|
+
return getRuntime().newBoolean(value.equals(getBigInteger(other)));
|
257
|
+
}
|
258
|
+
|
259
|
+
@JRubyMethod(name="sqr")
|
260
|
+
public IRubyObject bn_sqr() {
|
261
|
+
// TODO: check whether mult n * n is faster
|
262
|
+
return newBN(getRuntime(), value.pow(2));
|
263
|
+
}
|
264
|
+
|
265
|
+
@JRubyMethod(name="~")
|
266
|
+
public IRubyObject bn_not() {
|
267
|
+
return newBN(getRuntime(), value.not());
|
268
|
+
}
|
269
|
+
|
270
|
+
@JRubyMethod(name="+")
|
271
|
+
public IRubyObject bn_add(IRubyObject other) {
|
272
|
+
return newBN(getRuntime(), value.add(getBigInteger(other)));
|
273
|
+
}
|
274
|
+
|
275
|
+
@JRubyMethod(name="-")
|
276
|
+
public IRubyObject bn_sub(IRubyObject other) {
|
277
|
+
return newBN(getRuntime(), value.subtract(getBigInteger(other)));
|
278
|
+
}
|
279
|
+
|
280
|
+
@JRubyMethod(name="*")
|
281
|
+
public IRubyObject bn_mul(IRubyObject other) {
|
282
|
+
return newBN(getRuntime(), value.multiply(getBigInteger(other)));
|
283
|
+
}
|
284
|
+
|
285
|
+
@JRubyMethod(name="%")
|
286
|
+
public IRubyObject bn_mod(IRubyObject other) {
|
287
|
+
try {
|
288
|
+
return newBN(getRuntime(), value.mod(getBigInteger(other)));
|
289
|
+
} catch (ArithmeticException e) {
|
290
|
+
throw getRuntime().newZeroDivisionError();
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
@JRubyMethod(name="/")
|
295
|
+
public IRubyObject bn_div(IRubyObject other) {
|
296
|
+
Ruby runtime = getRuntime();
|
297
|
+
try {
|
298
|
+
BigInteger[] result = value.divideAndRemainder(getBigInteger(other));
|
299
|
+
return runtime.newArray(newBN(runtime, result[0]), newBN(runtime, result[1]));
|
300
|
+
} catch (ArithmeticException e) {
|
301
|
+
throw runtime.newZeroDivisionError();
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
@JRubyMethod(name="&")
|
306
|
+
public IRubyObject bn_and(IRubyObject other) {
|
307
|
+
return newBN(getRuntime(), value.and(getBigInteger(other)));
|
308
|
+
}
|
309
|
+
|
310
|
+
@JRubyMethod(name="|")
|
311
|
+
public IRubyObject bn_or(IRubyObject other) {
|
312
|
+
return newBN(getRuntime(), value.or(getBigInteger(other)));
|
313
|
+
}
|
314
|
+
|
315
|
+
@JRubyMethod(name="^")
|
316
|
+
public IRubyObject bn_xor(IRubyObject other) {
|
317
|
+
return newBN(getRuntime(), value.xor(getBigInteger(other)));
|
318
|
+
}
|
319
|
+
|
320
|
+
@JRubyMethod(name="**")
|
321
|
+
public IRubyObject bn_exp(IRubyObject other) {
|
322
|
+
// somewhat strangely, BigInteger takes int rather than BigInteger
|
323
|
+
// as the argument to pow. so we'll have to narrow the value, and
|
324
|
+
// raise an exception if data would be lost. (on the other hand, an
|
325
|
+
// exponent even approaching Integer.MAX_VALUE would be silly big, and
|
326
|
+
// the value would take a very, very long time to calculate.)
|
327
|
+
// we'll check for values < 0 (illegal) while we're at it
|
328
|
+
int exp;
|
329
|
+
switch(other.getMetaClass().index) {
|
330
|
+
case ClassIndex.FIXNUM: {
|
331
|
+
long val = ((RubyFixnum)other).getLongValue();
|
332
|
+
if (val >= 0 && val <= Integer.MAX_VALUE) {
|
333
|
+
exp = (int)val;
|
334
|
+
break;
|
335
|
+
}
|
336
|
+
// drop through for error
|
337
|
+
}
|
338
|
+
case ClassIndex.BIGNUM:
|
339
|
+
// Bignum is inherently too big
|
340
|
+
throw newBNError(getRuntime(), "invalid exponent");
|
341
|
+
default: {
|
342
|
+
if (!(other instanceof BN)) {
|
343
|
+
throw getRuntime().newTypeError("Cannot convert into OpenSSL::BN");
|
344
|
+
}
|
345
|
+
BigInteger val = ((BN)other).value;
|
346
|
+
if (val.compareTo(BigInteger.ZERO) < 0 || val.compareTo(MAX_INT) > 0) {
|
347
|
+
throw newBNError(getRuntime(), "invalid exponent");
|
348
|
+
}
|
349
|
+
exp = val.intValue();
|
350
|
+
break;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
try {
|
354
|
+
return newBN(getRuntime(), value.pow(exp));
|
355
|
+
} catch (ArithmeticException e) {
|
356
|
+
// shouldn't happen, we've already checked for < 0
|
357
|
+
throw newBNError(getRuntime(), "invalid exponent");
|
358
|
+
}
|
359
|
+
}
|
360
|
+
|
361
|
+
@JRubyMethod(name="gcd")
|
362
|
+
public IRubyObject bn_gcd(IRubyObject other) {
|
363
|
+
return newBN(getRuntime(), value.gcd(getBigInteger(other)));
|
364
|
+
}
|
365
|
+
|
366
|
+
@JRubyMethod(name="mod_sqr")
|
367
|
+
public IRubyObject bn_mod_sqr(IRubyObject other) {
|
368
|
+
try {
|
369
|
+
return newBN(getRuntime(), value.modPow(TWO, getBigInteger(other)));
|
370
|
+
} catch (ArithmeticException e) {
|
371
|
+
throw getRuntime().newZeroDivisionError();
|
372
|
+
}
|
373
|
+
}
|
374
|
+
|
375
|
+
@JRubyMethod(name="mod_inverse")
|
376
|
+
public IRubyObject bn_mod_inverse(IRubyObject other) {
|
377
|
+
try {
|
378
|
+
return newBN(getRuntime(), value.modInverse(getBigInteger(other)));
|
379
|
+
} catch (ArithmeticException e) {
|
380
|
+
throw getRuntime().newZeroDivisionError();
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
@JRubyMethod(name="mod_add")
|
385
|
+
public IRubyObject bn_mod_add(IRubyObject other, IRubyObject mod) {
|
386
|
+
try {
|
387
|
+
return newBN(getRuntime(), value.add(getBigInteger(other)).mod(getBigInteger(mod)));
|
388
|
+
} catch (ArithmeticException e) {
|
389
|
+
throw getRuntime().newZeroDivisionError();
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
@JRubyMethod(name="mod_sub")
|
394
|
+
public IRubyObject bn_mod_sub(IRubyObject other, IRubyObject mod) {
|
395
|
+
try {
|
396
|
+
return newBN(getRuntime(), value.subtract(getBigInteger(other)).mod(getBigInteger(mod)));
|
397
|
+
} catch (ArithmeticException e) {
|
398
|
+
throw getRuntime().newZeroDivisionError();
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
@JRubyMethod(name="mod_mul")
|
403
|
+
public IRubyObject bn_mod_mul(IRubyObject other, IRubyObject mod) {
|
404
|
+
try {
|
405
|
+
return newBN(getRuntime(), value.multiply(getBigInteger(other)).mod(getBigInteger(mod)));
|
406
|
+
} catch (ArithmeticException e) {
|
407
|
+
throw getRuntime().newZeroDivisionError();
|
408
|
+
}
|
409
|
+
}
|
410
|
+
|
411
|
+
@JRubyMethod(name="mod_exp")
|
412
|
+
public IRubyObject bn_mod_exp(IRubyObject other, IRubyObject mod) {
|
413
|
+
try {
|
414
|
+
return newBN(getRuntime(), value.modPow(getBigInteger(other), getBigInteger(mod)));
|
415
|
+
} catch (ArithmeticException e) {
|
416
|
+
throw getRuntime().newZeroDivisionError();
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
@JRubyMethod(name="set_bit!")
|
421
|
+
public synchronized IRubyObject bn_set_bit(IRubyObject n) {
|
422
|
+
// evil mutable BN
|
423
|
+
int pos = RubyNumeric.num2int(n);
|
424
|
+
BigInteger oldValue = this.value;
|
425
|
+
// FIXME? in MRI/OSSL-BIGNUM, the original sign of a BN is remembered, so if
|
426
|
+
// you set the value of an (originally) negative number to zero (through some
|
427
|
+
// combination of clear_bit! and/or mask_bits! calls), and later call set_bit!,
|
428
|
+
// the resulting value will be negative. this seems unintuitive and, frankly,
|
429
|
+
// wrong, not to mention expensive to carry the extra sign field.
|
430
|
+
// I'm not duplicating this behavior here at this time. -BD
|
431
|
+
try {
|
432
|
+
if (oldValue.signum() >= 0) {
|
433
|
+
this.value = oldValue.setBit(pos);
|
434
|
+
} else {
|
435
|
+
this.value = oldValue.abs().setBit(pos).negate();
|
436
|
+
}
|
437
|
+
} catch (ArithmeticException e) {
|
438
|
+
throw newBNError(getRuntime(), "invalid pos");
|
439
|
+
}
|
440
|
+
return this;
|
441
|
+
}
|
442
|
+
|
443
|
+
@JRubyMethod(name="clear_bit!")
|
444
|
+
public synchronized IRubyObject bn_clear_bit(IRubyObject n) {
|
445
|
+
// evil mutable BN
|
446
|
+
int pos = RubyNumeric.num2int(n);
|
447
|
+
BigInteger oldValue = this.value;
|
448
|
+
try {
|
449
|
+
if (oldValue.signum() >= 0) {
|
450
|
+
this.value = oldValue.clearBit(pos);
|
451
|
+
} else {
|
452
|
+
this.value = oldValue.abs().clearBit(pos).negate();
|
453
|
+
}
|
454
|
+
} catch (ArithmeticException e) {
|
455
|
+
throw newBNError(getRuntime(), "invalid pos");
|
456
|
+
}
|
457
|
+
return this;
|
458
|
+
}
|
459
|
+
|
460
|
+
/**
|
461
|
+
* Truncates value to n bits
|
462
|
+
*/
|
463
|
+
@JRubyMethod(name="mask_bits!")
|
464
|
+
public synchronized IRubyObject bn_mask_bits(IRubyObject n) {
|
465
|
+
// evil mutable BN
|
466
|
+
|
467
|
+
int pos = RubyNumeric.num2int(n);
|
468
|
+
if (pos < 0) throw newBNError(getRuntime(), "invalid pos");
|
469
|
+
|
470
|
+
BigInteger oldValue = this.value;
|
471
|
+
|
472
|
+
// TODO: cache 2 ** n values?
|
473
|
+
if (oldValue.signum() >= 0) {
|
474
|
+
if (oldValue.bitLength() < pos) throw newBNError(getRuntime(), "invalid pos");
|
475
|
+
this.value = oldValue.mod(TWO.pow(pos));
|
476
|
+
} else {
|
477
|
+
BigInteger absValue = oldValue.abs();
|
478
|
+
if (absValue.bitLength() < pos) throw newBNError(getRuntime(), "invalid pos");
|
479
|
+
this.value = absValue.mod(TWO.pow(pos)).negate();
|
480
|
+
}
|
481
|
+
|
482
|
+
return this;
|
483
|
+
}
|
484
|
+
|
485
|
+
@JRubyMethod(name="bit_set?")
|
486
|
+
public IRubyObject bn_is_bit_set(IRubyObject n) {
|
487
|
+
int pos = RubyNumeric.num2int(n);
|
488
|
+
BigInteger val = this.value;
|
489
|
+
try {
|
490
|
+
if (val.signum() >= 0) {
|
491
|
+
return getRuntime().newBoolean(val.testBit(pos));
|
492
|
+
} else {
|
493
|
+
return getRuntime().newBoolean(val.abs().testBit(pos));
|
494
|
+
}
|
495
|
+
} catch (ArithmeticException e) {
|
496
|
+
throw newBNError(getRuntime(), "invalid pos");
|
497
|
+
}
|
498
|
+
}
|
499
|
+
|
500
|
+
@JRubyMethod(name="<<")
|
501
|
+
public IRubyObject bn_lshift(IRubyObject n) {
|
502
|
+
int nbits = RubyNumeric.num2int(n);
|
503
|
+
BigInteger val = this.value;
|
504
|
+
if (val.signum() >= 0) {
|
505
|
+
return newBN(getRuntime(), val.shiftLeft(nbits));
|
506
|
+
} else {
|
507
|
+
return newBN(getRuntime(), val.abs().shiftLeft(nbits).negate());
|
508
|
+
}
|
509
|
+
}
|
510
|
+
|
511
|
+
@JRubyMethod(name=">>")
|
512
|
+
public IRubyObject bn_rshift(IRubyObject n) {
|
513
|
+
int nbits = RubyNumeric.num2int(n);
|
514
|
+
BigInteger val = this.value;
|
515
|
+
if (val.signum() >= 0) {
|
516
|
+
return newBN(getRuntime(), val.shiftRight(nbits));
|
517
|
+
} else {
|
518
|
+
return newBN(getRuntime(), val.abs().shiftRight(nbits).negate());
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
@JRubyMethod(name="num_bits")
|
523
|
+
public IRubyObject bn_num_bits() {
|
524
|
+
return getRuntime().newFixnum(this.value.abs().bitLength());
|
525
|
+
}
|
526
|
+
|
527
|
+
@JRubyMethod(name="num_bytes")
|
528
|
+
public IRubyObject bn_num_bytes() {
|
529
|
+
return getRuntime().newFixnum((this.value.abs().bitLength() + 7) / 8);
|
530
|
+
}
|
531
|
+
|
532
|
+
@JRubyMethod(name="num_bits_set")
|
533
|
+
public IRubyObject bn_num_bits_set() {
|
534
|
+
return getRuntime().newFixnum(this.value.abs().bitCount());
|
535
|
+
}
|
536
|
+
|
537
|
+
// note that there is a bug in the MRI version, in argument handling,
|
538
|
+
// so apparently no one ever calls this...
|
539
|
+
@JRubyMethod(name="prime?", rest=true)
|
540
|
+
public IRubyObject bn_is_prime(IRubyObject[] args) {
|
541
|
+
Ruby runtime = getRuntime();
|
542
|
+
int argc = Arity.checkArgumentCount(runtime, args, 0, 1);
|
543
|
+
// BigInteger#isProbablePrime will actually limit checks to a maximum of 50,
|
544
|
+
// depending on bit count.
|
545
|
+
int certainty = argc == 0 ? DEFAULT_CERTAINTY : RubyNumeric.fix2int(args[0]);
|
546
|
+
return runtime.newBoolean(this.value.isProbablePrime(certainty));
|
547
|
+
}
|
548
|
+
|
549
|
+
// FIXME? BigInteger doesn't supply this, so right now this is (essentially)
|
550
|
+
// the same as bn_is_prime
|
551
|
+
@JRubyMethod(name="prime_fasttest?", rest=true)
|
552
|
+
public IRubyObject bn_is_prime_fasttest(IRubyObject[] args) {
|
553
|
+
Ruby runtime = getRuntime();
|
554
|
+
int argc = Arity.checkArgumentCount(runtime, args, 0, 2);
|
555
|
+
// BigInteger#isProbablePrime will actually limit checks to a maximum of 50,
|
556
|
+
// depending on bit count.
|
557
|
+
int certainty = argc == 0 ? DEFAULT_CERTAINTY : RubyNumeric.fix2int(args[0]);
|
558
|
+
return runtime.newBoolean(this.value.isProbablePrime(certainty));
|
559
|
+
}
|
560
|
+
|
561
|
+
@JRubyMethod(name="generate_prime", meta=true, rest=true)
|
562
|
+
public static IRubyObject bn_generate_prime(IRubyObject recv, IRubyObject[] args) {
|
563
|
+
Ruby runtime = recv.getRuntime();
|
564
|
+
int argc = Arity.checkArgumentCount(runtime, args, 1, 4);
|
565
|
+
int bits = RubyNumeric.num2int(args[0]);
|
566
|
+
boolean safe = argc > 1 ? args[1] != runtime.getFalse() : true;
|
567
|
+
BigInteger add = argc > 2 ? getBigInteger(args[2]) : null;
|
568
|
+
BigInteger rem = argc > 3 ? getBigInteger(args[3]) : null;
|
569
|
+
if (bits < 3) {
|
570
|
+
if (safe) throw runtime.newArgumentError("bits < 3");
|
571
|
+
if (bits < 2) throw runtime.newArgumentError("bits < 2");
|
572
|
+
}
|
573
|
+
return newBN(runtime, generatePrime(bits, safe, add, rem));
|
574
|
+
}
|
575
|
+
|
576
|
+
public static BigInteger generatePrime(int bits, boolean safe, BigInteger add, BigInteger rem) {
|
577
|
+
// From OpenSSL man page BN_generate_prime(3):
|
578
|
+
//
|
579
|
+
// "If add is not NULL, the prime will fulfill the condition p % add == rem
|
580
|
+
// (p % add == 1 if rem == NULL) in order to suit a given generator."
|
581
|
+
//
|
582
|
+
// "If safe is true, it will be a safe prime (i.e. a prime p so that
|
583
|
+
// (p-1)/2 is also prime)."
|
584
|
+
//
|
585
|
+
// see [ossl]/crypto/bn/bn_prime.c #BN_generate_prime_ex
|
586
|
+
//
|
587
|
+
|
588
|
+
if (add != null && rem == null) {
|
589
|
+
rem = BigInteger.ONE;
|
590
|
+
}
|
591
|
+
|
592
|
+
// borrowing technique from org.bouncycastle.crypto.generators.DHParametersHelper
|
593
|
+
// (unfortunately the code has package visibility), wherein for safe primes,
|
594
|
+
// we'll use the lowest useful certainty (2) for generation of q, then if
|
595
|
+
// p ( = 2q + 1) is prime to our required certainty (100), we'll verify that q
|
596
|
+
// is as well.
|
597
|
+
//
|
598
|
+
// for typical bit lengths ( >= 1024), this should speed things up by reducing
|
599
|
+
// initial Miller-Rabin iterations from 2 to 1 for candidate values of q.
|
600
|
+
//
|
601
|
+
// it's still painfully slow...
|
602
|
+
//
|
603
|
+
BigInteger p, q;
|
604
|
+
int qbits = bits - 1;
|
605
|
+
SecureRandom secureRandom = getSecureRandom();
|
606
|
+
do {
|
607
|
+
if (safe) {
|
608
|
+
do {
|
609
|
+
q = new BigInteger(qbits, 2, secureRandom);
|
610
|
+
p = q.shiftLeft(1).setBit(0);
|
611
|
+
} while (!(p.isProbablePrime(DEFAULT_CERTAINTY) && q.isProbablePrime(DEFAULT_CERTAINTY)));
|
612
|
+
} else {
|
613
|
+
p = BigInteger.probablePrime(bits, secureRandom);
|
614
|
+
}
|
615
|
+
} while (add != null && !p.mod(add).equals(rem));
|
616
|
+
return p;
|
617
|
+
}
|
618
|
+
|
619
|
+
public static BigInteger generatePrime(int bits, boolean safe) {
|
620
|
+
return generatePrime(bits, safe, null, null);
|
621
|
+
}
|
622
|
+
|
623
|
+
@JRubyMethod(name="rand", meta=true, rest=true)
|
624
|
+
public static IRubyObject bn_rand(IRubyObject recv, IRubyObject[] args) {
|
625
|
+
return getRandomBN(recv.getRuntime(), args, getSecureRandom());
|
626
|
+
}
|
627
|
+
|
628
|
+
@JRubyMethod(name="pseudo_rand", meta=true, rest=true)
|
629
|
+
public static IRubyObject bn_pseudo_rand(IRubyObject recv, IRubyObject[] args) {
|
630
|
+
return getRandomBN(recv.getRuntime(), args, getRandom());
|
631
|
+
}
|
632
|
+
|
633
|
+
public static BN getRandomBN(Ruby runtime, IRubyObject[] args, Random random) {
|
634
|
+
int argc = Arity.checkArgumentCount(runtime, args, 1, 3);
|
635
|
+
int bits = RubyNumeric.num2int(args[0]);
|
636
|
+
int top;
|
637
|
+
boolean bottom;
|
638
|
+
if (argc > 1) {
|
639
|
+
top = RubyNumeric.fix2int(args[1]);
|
640
|
+
bottom = argc == 3 ? args[2].isTrue() : false;
|
641
|
+
} else {
|
642
|
+
top = 0;
|
643
|
+
bottom = false;
|
644
|
+
}
|
645
|
+
|
646
|
+
BigInteger value;
|
647
|
+
try {
|
648
|
+
value = getRandomBI(bits, top, bottom, random);
|
649
|
+
} catch (IllegalArgumentException e) {
|
650
|
+
throw runtime.newArgumentError(e.getMessage());
|
651
|
+
}
|
652
|
+
return newBN(runtime, value);
|
653
|
+
}
|
654
|
+
|
655
|
+
public static BigInteger getRandomBI(int bits, int top, boolean bottom, Random random) {
|
656
|
+
// From OpenSSL man page BN_rand(3):
|
657
|
+
//
|
658
|
+
// "If top is -1, the most significant bit of the random number can be zero.
|
659
|
+
// If top is 0, it is set to 1, and if top is 1, the two most significant bits
|
660
|
+
// of the number will be set to 1, so that the product of two such random numbers
|
661
|
+
// will always have 2*bits length."
|
662
|
+
//
|
663
|
+
// "If bottom is true, the number will be odd."
|
664
|
+
//
|
665
|
+
if (bits <= 0) {
|
666
|
+
if (bits == 0) return BigInteger.ZERO;
|
667
|
+
throw new IllegalArgumentException("Illegal bit length");
|
668
|
+
}
|
669
|
+
if (top < -1 || top > 1) {
|
670
|
+
throw new IllegalArgumentException("Illegal top value");
|
671
|
+
}
|
672
|
+
|
673
|
+
// top/bottom handling adapted from OpenSSL's crypto/bn/bn_rand.c
|
674
|
+
int bytes = (bits + 7) / 8;
|
675
|
+
int bit = (bits - 1) % 8;
|
676
|
+
int mask = 0xff << (bit + 1);
|
677
|
+
|
678
|
+
byte[] buf;
|
679
|
+
random.nextBytes(buf = new byte[bytes]);
|
680
|
+
if (top >= 0) {
|
681
|
+
if (top == 0) {
|
682
|
+
buf[0] |= (1 << bit);
|
683
|
+
} else {
|
684
|
+
if (bit == 0) {
|
685
|
+
buf[0] = 1;
|
686
|
+
buf[1] |= 0x80;
|
687
|
+
}
|
688
|
+
else {
|
689
|
+
buf[0] |= (3 << (bit - 1));
|
690
|
+
}
|
691
|
+
}
|
692
|
+
}
|
693
|
+
buf[0] &= ~mask;
|
694
|
+
if (bottom) {
|
695
|
+
buf[bytes-1] |= 1;
|
696
|
+
}
|
697
|
+
|
698
|
+
// treating result as unsigned
|
699
|
+
return new BigInteger(1, buf);
|
700
|
+
}
|
701
|
+
|
702
|
+
@JRubyMethod(name="rand_range", meta=true)
|
703
|
+
public static IRubyObject bn_rand_range(IRubyObject recv, IRubyObject arg) {
|
704
|
+
return getRandomBNInRange(recv.getRuntime(), getBigInteger(arg), getSecureRandom());
|
705
|
+
}
|
706
|
+
|
707
|
+
@JRubyMethod(name="pseudo_rand_range", meta=true)
|
708
|
+
public static IRubyObject bn_pseudo_rand_range(IRubyObject recv, IRubyObject arg) {
|
709
|
+
return getRandomBNInRange(recv.getRuntime(), getBigInteger(arg), getRandom());
|
710
|
+
}
|
711
|
+
|
712
|
+
private static BN getRandomBNInRange(Ruby runtime, BigInteger limit, Random random) {
|
713
|
+
BigInteger value;
|
714
|
+
try {
|
715
|
+
value = getRandomBIInRange(limit, random);
|
716
|
+
} catch (IllegalArgumentException e) {
|
717
|
+
throw newBNError(runtime, "illegal range");
|
718
|
+
}
|
719
|
+
return newBN(runtime, value);
|
720
|
+
}
|
721
|
+
|
722
|
+
public static BigInteger getRandomBIInRange(BigInteger limit, Random random) {
|
723
|
+
if (limit.signum() < 0) {
|
724
|
+
throw new IllegalArgumentException("illegal range");
|
725
|
+
}
|
726
|
+
int bits = limit.bitLength();
|
727
|
+
BigInteger value;
|
728
|
+
do {
|
729
|
+
value = new BigInteger(bits, random);
|
730
|
+
} while (value.compareTo(limit) >= 0);
|
731
|
+
return value;
|
732
|
+
}
|
733
|
+
|
734
|
+
private static Random getRandom() {
|
735
|
+
Random rand;
|
736
|
+
if ((rand = _random) != null) {
|
737
|
+
return rand;
|
738
|
+
}
|
739
|
+
return _random = new Random();
|
740
|
+
}
|
741
|
+
|
742
|
+
private static SecureRandom getSecureRandom() {
|
743
|
+
SecureRandom rand;
|
744
|
+
if ((rand = _secureRandom) != null) {
|
745
|
+
return rand;
|
746
|
+
}
|
747
|
+
// FIXME: do we want a particular algorithm / provider? BC?
|
748
|
+
return _secureRandom = new SecureRandom();
|
749
|
+
}
|
750
|
+
|
751
|
+
public static RaiseException newBNError(Ruby runtime, String message) {
|
752
|
+
return new RaiseException(runtime, runtime.getModule("OpenSSL").getClass("BNError"), message, true);
|
753
|
+
}
|
754
|
+
|
755
|
+
public static BigInteger getBigInteger(IRubyObject arg) {
|
756
|
+
if (arg.isNil()) return null;
|
757
|
+
switch(arg.getMetaClass().index) {
|
758
|
+
case ClassIndex.FIXNUM:
|
759
|
+
case ClassIndex.BIGNUM:
|
760
|
+
return new BigInteger(arg.toString());
|
761
|
+
default:
|
762
|
+
if (arg instanceof BN) {
|
763
|
+
return ((BN)arg).value;
|
764
|
+
}
|
765
|
+
throw arg.getRuntime().newTypeError("Cannot convert into OpenSSL::BN");
|
766
|
+
}
|
767
|
+
}
|
768
|
+
|
769
|
+
}
|