OpenSSL::Random#pseudo_bytes raises ArgumentError on negative arguments
-----------------------------------------------------------------------

                 Key: JRUBY-3151
                 URL: http://jira.codehaus.org/browse/JRUBY-3151
             Project: JRuby
          Issue Type: Bug
          Components: RubySpec
            Reporter: Charles Oliver Nutter
            Assignee: Thomas E Enebo
             Fix For: JRuby 1.1.6


The error:

{noformat}
     [java] OpenSSL::Random#pseudo_bytes
     [java] - generates a random binary string of specified length
     [java] - generates different binary strings with subsequent invocations
     [java] org.jruby.ext.openssl.Random:87:in `generate': 
java.lang.NegativeArraySizeException
     [java]     from org.jruby.ext.openssl.Random:81:in `pseudo_bytes'
     [java]     from 
org.jruby.ext.openssl.Random$s_method_1_0$RUBYINVOKER$pseudo_bytes:-1:in `call'
     [java]     from org.jruby.runtime.callsite.CachingCallSite:280:in 
`cacheAndCall'
     [java]     from org.jruby.runtime.callsite.CachingCallSite:116:in `call'
{noformat}

The actual spec (it's the -1 spec at the bottom that's blowing up):

{noformat}
require File.dirname(__FILE__) + '/../../../../spec_helper'
require 'openssl'

describe :openssl_random_bytes, :shared => true do |cmd|
  it "generates a random binary string of specified length" do
    (1..64).each do |idx|
      bytes = OpenSSL::Random.pseudo_bytes(idx)
      bytes.class.should == String
      bytes.length.should == idx
    end
  end

  it "generates different binary strings with subsequent invocations" do
    # quick and dirty check, but good enough
    values = []
    256.times do
      val = OpenSSL::Random.pseudo_bytes(16)
      # make sure the random bytes are not repeating
      values.include?(val).should == false
      values << val
    end
  end

  it "raises ArgumentError on negative arguments" do
    lambda {
      OpenSSL::Random.pseudo_bytes(-1)
    }.should raise_error(ArgumentError)
  end
end
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to