[前][次][番号順一覧][スレッド一覧]

ruby-changes:36188

From: usa <ko1@a...>
Date: Tue, 4 Nov 2014 21:21:12 +0900 (JST)
Subject: [ruby-changes:36188] usa:r48269 (trunk): * lib/securerandom.rb (SecureRandom.random_bytes): use fiddle directly

usa	2014-11-04 21:20:59 +0900 (Tue, 04 Nov 2014)

  New Revision: 48269

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48269

  Log:
    * lib/securerandom.rb (SecureRandom.random_bytes): use fiddle directly
      instead of using Win32API.

  Modified files:
    trunk/ChangeLog
    trunk/lib/securerandom.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48268)
+++ ChangeLog	(revision 48269)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Nov  4 21:20:07 2014  NAKAMURA Usaku  <usa@r...>
+
+	* lib/securerandom.rb (SecureRandom.random_bytes): use fiddle directly
+	  instead of using Win32API.
+
 Tue Nov  4 21:04:30 2014  NAKAMURA Usaku  <usa@r...>
 
 	* test/rubygems/test_gem_request_set_lockfile.rb
Index: lib/securerandom.rb
===================================================================
--- lib/securerandom.rb	(revision 48268)
+++ lib/securerandom.rb	(revision 48269)
@@ -91,16 +91,21 @@ module SecureRandom https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L91
 
     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'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]