Skip to content
Closed
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
13 changes: 11 additions & 2 deletions lib/mix/lib/mix/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ defmodule Mix.Utils do
end
end

@checksums [:sha512]
@checksums [:sha224, :sha256, :sha384, :sha512, :sha3_224, :sha3_256, :sha3_384, :sha3_512]

defp require_checksum(opts) do
cond do
Expand All @@ -615,7 +615,7 @@ defmodule Mix.Utils do
with expected when expected != nil <- opts[hash],
actual when actual != expected <- hexhash(binary, hash) do
message = """
Data does not match the given SHA-512 checksum.
Data does not match the given #{hash_name(hash)} checksum.

Expected: #{expected}
Actual: #{actual}
Expand All @@ -628,6 +628,15 @@ defmodule Mix.Utils do
end)
end

defp hash_name(:sha224), do: "SHA-224"
defp hash_name(:sha256), do: "SHA-256"
defp hash_name(:sha384), do: "SHA-384"
defp hash_name(:sha512), do: "SHA-512"
defp hash_name(:sha3_224), do: "SHA3-224"
defp hash_name(:sha3_256), do: "SHA3-256"
defp hash_name(:sha3_384), do: "SHA3-384"
defp hash_name(:sha3_512), do: "SHA3-512"

defp hexhash(binary, hash) do
Base.encode16(:crypto.hash(hash, binary), case: :lower)
end
Expand Down