Sha256: aab977be5a50288308b6efdc11639ed588ce7dec664c0b7f932f9220f3899102

Contents?: true

Size: 1007 Bytes

Versions: 52

Compression:

Stored size: 1007 Bytes

Contents

require 'ffi'

module BCrypt
  class Engine
    extend FFI::Library

    BCRYPT_MAXSALT = 16
    BCRYPT_SALT_OUTPUT_SIZE = 7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1
    BCRYPT_OUTPUT_SIZE = 128

    ffi_lib File.expand_path("../bcrypt_ext", __FILE__)

    attach_function :ruby_bcrypt, [:buffer_out, :string, :string], :string
    attach_function :ruby_bcrypt_gensalt, [:buffer_out, :uint8, :pointer], :string

    def self.__bc_salt(cost, seed)
      buffer_out = FFI::Buffer.alloc_out(BCRYPT_SALT_OUTPUT_SIZE, 1)
      seed_ptr = FFI::MemoryPointer.new(:uint8, BCRYPT_MAXSALT)
      seed.bytes.to_a.each_with_index { |b, i| seed_ptr.int8_put(i, b) }
      out = ruby_bcrypt_gensalt(buffer_out, cost, seed_ptr)
      seed_ptr.free
      buffer_out.free
      out || ""
    end

    def self.__bc_crypt(key, salt, cost)
      buffer_out = FFI::Buffer.alloc_out(BCRYPT_OUTPUT_SIZE, 1)
      out = ruby_bcrypt(buffer_out, key || "", salt)
      buffer_out.free
      out && out.any? ? out : nil
    end
  end
end

Version data entries

52 entries across 49 versions & 5 rubygems

Version Path
challah-1.0.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-1.0.0.beta3 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-1.0.0.beta2 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-1.0.0.beta vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.9.1.beta.3 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
devise_sociable-0.1.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.9.1.beta vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.9.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-rolls-0.2.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.8.3 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.8.1 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-rolls-0.1.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.8.0.pre vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.7.1 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.7.0 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb
challah-0.7.0.pre2 vendor/bundle/gems/bcrypt-ruby-3.0.1/lib/bcrypt_engine.rb