Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1092 fix #1165

Merged
merged 3 commits into from Oct 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ruby/shared/openssl/pkcs12.rb
Expand Up @@ -31,6 +31,7 @@ def initialize(str = nil, password = '')
@der = file.read
file.close
else
str.force_encoding(Encoding::ASCII_8BIT)
@der = str
end

Expand Down
48 changes: 31 additions & 17 deletions test/mri/openssl/test_pkcs12.rb
Expand Up @@ -52,31 +52,28 @@ def setup
end

def test_create
pkcs12 = OpenSSL::PKCS12.create(
"omg",
"hello",
TEST_KEY_RSA1024,
@mycert
)
pkcs12 = create_store
assert_equal @mycert, pkcs12.certificate
assert_equal TEST_KEY_RSA1024, pkcs12.key
assert_nil pkcs12.ca_certs
end

def test_load
temp = OpenSSL::PKCS12.create(
"omg",
"hello",
TEST_KEY_RSA1024,
@mycert
)

Tempfile.open('test_cert.pk12') do |f|
f << temp.to_der
f.rewind
def test_from_file
tempfile do |f|
OpenSSL::PKCS12.new(f, 'omg')
end
end

def test_from_ascii_string
tempfile do |f|
OpenSSL::PKCS12.new(f.read.force_encoding(Encoding::ASCII_8BIT), 'omg')
end
end

def test_from_utf8_string
tempfile do |f|
OpenSSL::PKCS12.new(f.read.force_encoding(Encoding::UTF_8), 'omg')
end
end

def test_create_no_pass
Expand Down Expand Up @@ -219,6 +216,23 @@ def assert_include_cert cert, ary
false
end

def create_store
OpenSSL::PKCS12.create(
"omg",
"hello",
TEST_KEY_RSA1024,
@mycert
)
end

def tempfile store=create_store
Tempfile.open('test_cert.pk12') do |f|
f << store.to_der
f.rewind
yield f
end
end

end
end

Expand Down