Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated functions #94

Merged
merged 3 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/mongo/auth/scram.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ defmodule Mongo.Auth.SCRAM do
end

defp generate_proof(salted_password, auth_message, digest) do
client_key = :crypto.hmac(digest, salted_password, "Client Key")
client_key = :crypto.mac(:hmac, digest, salted_password, "Client Key")
stored_key = :crypto.hash(digest, client_key)
signature = :crypto.hmac(digest, stored_key, auth_message)
signature = :crypto.mac(:hmac, digest, stored_key, auth_message)
client_proof = xor_keys(client_key, signature, "")
"p=#{Base.encode64(client_proof)}"
end

defp generate_signature(salted_password, auth_message, digest) do
server_key = :crypto.hmac(digest, salted_password, "Server Key")
:crypto.hmac(digest, server_key, auth_message)
server_key = :crypto.mac(:hmac, digest, salted_password, "Server Key")
:crypto.mac(:hmac, digest, server_key, auth_message)
end

defp xor_keys("", "", result), do: result
defp xor_keys(<<fa, ra::binary>>, <<fb, rb::binary>>, result), do: xor_keys(ra, rb, <<result::binary, fa ^^^ fb>>)
defp xor_keys(<<fa, ra::binary>>, <<fb, rb::binary>>, result), do: xor_keys(ra, rb, <<result::binary, bxor(fa, fb)>>)

defp nonce do
:crypto.strong_rand_bytes(18) |> Base.encode64
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/pbkdf2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ defmodule Mongo.PBKDF2 do
end

defp mac_fun(digest, secret) do
&:crypto.hmac(digest, secret, &1)
&:crypto.mac(:hmac, digest, secret, &1)
end
end