Hey Jayson,
Seems you're not making progress so I thought its worth going back to the beginning.
The error message says that the bcrypt_nif.so file cannot be found, i.e. it doesn't exist on disk. If the .so file is invalid, or otherwise faulty, the beam will return a different error. e.g. if I `echo junkyjunkyjunkyjunkyjunkyjunky > ./priv/bcrypt_nif.so` a different error is returned:
=ERROR REPORT==== 18-Oct-2013::08:21:19 ===
The on_load function for module bcrypt_nif returned {error,
{load_failed,
"Failed to load NIF library: 'dlopen(/zfs/shared/repos/erlang-bcrypt/ebin/../priv/bcrypt_nif.so,
2): no suitable image found. Did find:\n\t/zfs/shared/repos/erlang-bcrypt/ebin/../priv/bcrypt_nif.so: file too short'"}}
Is your nif.so is missing? If so, this sounds like a build-time issue in either mix or bcrypt.
wrt to mix, how about sharing your config somewhere?
Here's a test run with a minimal mix, on OSX 10.8.5, Erlang R16B02, built via homebrew (IIRC with custom crypto, but I don't think this should matter for you), and elixir recent master branch. The only change to mix.exs is to add `[{ :bcrypt, github: "opscode/erlang-bcrypt" }]` in the dependencies.
dch@akai /ramdisk % mix new bc --bare
* creating README.md
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/bc.ex
* creating test
* creating test/test_helper.exs
* creating test/bc_test.exs
Your mix project was created with success.
You can use mix to compile it, test it, and more:
cd bc
mix compile
mix test
Run `mix help` for more information.
dch@akai /ramdisk % cd bc
dch@akai bc % vi mix.exs
… sprinkles pixie dust …
dch@akai bc % cat mix.exs
defmodule Bc.Mixfile do
use Mix.Project
def project do
[ app: :bc,
version: "0.0.1",
elixir: "~> 0.10.3-dev",
deps: deps ]
end
# Configuration for the OTP application
def application do
[]
end
defp deps do
[{ :bcrypt, github: "opscode/erlang-bcrypt" }]
end
end
dch@akai bc % mix deps.get
* Getting bcrypt [git: "git://
github.com/opscode/erlang-bcrypt.git"]
Cloning into 'deps/bcrypt'...
remote: Counting objects: 423, done.
remote: Compressing objects: 100% (220/220), done.
remote: Total 423 (delta 199), reused 392 (delta 175)
Receiving objects: 100% (423/423), 576.47 KiB | 278.00 KiB/s, done.
Resolving deltas: 100% (199/199), done.
Checking connectivity... done
* Compiling bcrypt
==> bcrypt (compile)
Compiled src/bcrypt_app.erl
Compiled src/bcrypt_nif.erl
Compiled src/bcrypt.erl
Compiled src/bcrypt_nif_worker.erl
Compiled src/bcrypt_port_sup.erl
Compiled src/bcrypt_pool.erl
Compiled src/bcrypt_port.erl
Compiled src/bcrypt_sup.erl
Compiling c_src/async_queue.c
Compiling c_src/bcrypt.c
Compiling c_src/bcrypt_nif.c
Compiling c_src/bcrypt_port.c
Compiling c_src/blowfish.c
cc -I/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/include -I/usr/local/Cellar/erlang/R16B02/lib/erlang/erts-5.10.3/include -L/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/lib -lerl_interface -lei bcrypt_port.c bcrypt.o blowfish.o -L/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/lib -lerl_interface -lei -lpthread -o ../priv/bcrypt
dch@akai bc % find . |grep \.so
./deps/bcrypt/priv/bcrypt_nif.so
dch@akai bc % iex -pa deps/bcrypt/ebin
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (0.10.3-dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(console@akai)1> :application.start :crypto
:ok
iex(console@akai)2> :application.start :bcrypt
:ok
iex(console@akai)3> {:ok, salt} = :bcrypt.gen_salt
{:ok, '$2a$12$4JcHRWAf1A08jlWmeegkwO'}
iex(console@akai)4> {:ok, hash} = :bcrypt.hashpw "foo", salt
{:ok, '$2a$12$4JcHRWAf1A08jlWmeegkwO7J6K7b9X0ufvOAaIvQ2nmlt.kFRAYsu'}
iex(console@akai)5>
If that doesn't work, I'd also suggest confirming that this compiles & and runs at erlang level:
dch@akai /ramdisk % erl +V
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 5.10.3
dch@akai /ramdisk % git clone git://
github.com/opscode/erlang-bcrypt.git
Cloning into 'erlang-bcrypt'...
…
dch@akai /ramdisk % cd erlang-bcrypt
dch@akai erlang-bcrypt % make
erlang-bcrypt (compile)
Compiled src/bcrypt_app.erl
Compiled src/bcrypt.erl
Compiled src/bcrypt_nif.erl
Compiled src/bcrypt_nif_worker.erl
Compiled src/bcrypt_port_sup.erl
Compiled src/bcrypt_sup.erl
Compiled src/bcrypt_pool.erl
Compiled src/bcrypt_port.erl
Compiling c_src/async_queue.c
Compiling c_src/bcrypt.c
Compiling c_src/bcrypt_nif.c
Compiling c_src/bcrypt_port.c
Compiling c_src/blowfish.c
cc -I/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/include -I/usr/local/Cellar/erlang/R16B02/lib/erlang/erts-5.10.3/include -L/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/lib -lerl_interface -lei bcrypt_port.c bcrypt.o blowfish.o -L/usr/local/Cellar/erlang/R16B02/lib/erlang/lib/erl_interface-3.7.14/lib -lerl_interface -lei -lpthread -o ../priv/bcrypt
dch@akai erlang-bcrypt % find . |grep \.so
./priv/bcrypt_nif.so
dch@akai erlang-bcrypt % erl -pa ./ebin -s crypto -s bcrypt
Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V5.10.3 (abort with ^G)
1> {ok, Salt} = bcrypt:gen_salt().
{ok,"$2a$12$2pL.yJMEKUA.7j/ZDQe5Iu"}
2> {ok, Hash} = bcrypt:hashpw("foo", Salt).
{ok,"$2a$12$2pL.yJMEKUA.7j/ZDQe5IuuE4bVyXaSh4JJDnNMeUBAEqoH3vuaWW"}
3> {ok, Hash} =:= bcrypt:hashpw("foo", Hash).
true
4> q().
ok
FWIW there's also
https://github.com/tonyg/erlang-scrypt but if bcrypt doesn't even build we should sort that out first.
--
Dave Cottlehuber
Sent with Airmail