diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-04 12:20:59 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-04 12:20:59 +0000 |
commit | 07f460829a95ac98092ca08dd42fab1a17541aa7 (patch) | |
tree | c44bda276e14100fe64684a6e680b07030ef6c1a | |
parent | 7343f15302ad70a33784eeba1aed5d383f004693 (diff) |
* lib/securerandom.rb (SecureRandom.random_bytes): use fiddle directly
instead of using Win32API.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/securerandom.rb | 13 |
2 files changed, 14 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Tue Nov 4 21:20:07 2014 NAKAMURA Usaku <[email protected]> + + * lib/securerandom.rb (SecureRandom.random_bytes): use fiddle directly + instead of using Win32API. + Tue Nov 4 21:04:30 2014 NAKAMURA Usaku <[email protected]> * test/rubygems/test_gem_request_set_lockfile.rb diff --git a/lib/securerandom.rb b/lib/securerandom.rb index bb1d83e0d9..6f85532ce8 100644 --- a/lib/securerandom.rb +++ b/lib/securerandom.rb @@ -91,16 +91,21 @@ module SecureRandom unless defined?(@has_win32) begin - require 'Win32API' + advapi32 = Module.new do + require "fiddle/import" + extend Fiddle::Importer + dlload "advapi32" + extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)" + extern "int CryptGenRandom(void*, unsigned long, void*)" + end - crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L') - @crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'VIP', 'L') + @crypt_gen_random = advapi32.method(:CryptGenRandom) hProvStr = " " * Fiddle::SIZEOF_VOIDP prov_rsa_full = 1 crypt_verifycontext = 0xF0000000 - if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0 + if advapi32.CryptAcquireContext(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0 raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}" end type = Fiddle::SIZEOF_VOIDP == Fiddle::SIZEOF_LONG_LONG ? 'q' : 'l' |