Skip to content

Instantly share code, notes, and snippets.

@aharpervc
Created May 18, 2015 16:03
Show Gist options
  • Save aharpervc/e2675cc13ef000d8c791 to your computer and use it in GitHub Desktop.
Save aharpervc/e2675cc13ef000d8c791 to your computer and use it in GitHub Desktop.

Revisions

  1. aharpervc revised this gist May 18, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion securerandom.rb.patch
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    - dlload "advapi32"
    - extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)"
    - extern "int CryptGenRandom(void*, unsigned long, void*)"
    +
    +
    + begin
    + dlload "advapi32"
    + extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)"
  2. aharpervc created this gist May 18, 2015.
    38 changes: 38 additions & 0 deletions securerandom.rb.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    --- /home/vagrant/.rake-compiler/sources/ruby-2.2.1/lib/securerandom.rb.original 2015-05-18 08:49:56.007018200 -0700
    +++ /home/vagrant/.rake-compiler/sources/ruby-2.2.1/lib/securerandom.rb 2015-05-18 08:58:42.187018200 -0700
    @@ -45,9 +45,14 @@

    module AdvApi32 # :nodoc:
    extend Fiddle::Importer
    - dlload "advapi32"
    - extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)"
    - extern "int CryptGenRandom(void*, unsigned long, void*)"
    +
    + begin
    + dlload "advapi32"
    + extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)"
    + extern "int CryptGenRandom(void*, unsigned long, void*)"
    + rescue Fiddle::DLError => e
    + STDERR.puts "(Ignore this error if cross compiling) #{e}"
    + end

    def self.get_provider
    hProvStr = " " * Fiddle::SIZEOF_VOIDP
    @@ -74,9 +79,14 @@

    module Kernel32 # :nodoc:
    extend Fiddle::Importer
    - dlload "kernel32"
    - extern "unsigned long GetLastError()"
    - extern "unsigned long FormatMessageA(unsigned long, void*, unsigned long, unsigned long, void*, unsigned long, void*)"
    +
    + begin
    + dlload "kernel32"
    + extern "unsigned long GetLastError()"
    + extern "unsigned long FormatMessageA(unsigned long, void*, unsigned long, unsigned long, void*, unsigned long, void*)"
    + rescue Fiddle::DLError => e
    + STDERR.puts "(Ignore this error if cross compiling) #{e}"
    + end

    # Following code is based on David Garamond's GUID library for Ruby.
    def self.last_error_message