Skip to content

Commit

Permalink
Comment out WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
reachfh committed Dec 27, 2023
1 parent f6f1c29 commit 80ec611
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions lib/acme_client/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule AcmeClient.Crypto do
end
end

defp parse_validity({:Validity, {:utcTime, not_before}, {:utcTime, not_after}}) do
def parse_validity({:Validity, {:utcTime, not_before}, {:utcTime, not_after}}) do
{:ok, {utctime_to_iso8601(not_before), utctime_to_iso8601(not_after)}}
end

Expand All @@ -106,35 +106,35 @@ defmodule AcmeClient.Crypto do
"20#{yy}-#{mo}-#{dd}T#{hh}:#{mm}:#{ss}Z"
end

@spec make_cert_chain(binary(), binary(), binary()) :: [map()]
def make_cert_chain(domain, certificate, pkey) do
[cert | chain] = String.split(certificate, "\n\n")

{entries, hashes} = Enum.reduce(chain, {[], []}, &get_cert_hash/2)

cert = %{
domain: domain,
cert: cert,
pkey: pkey,
chain: Enum.reverse(hashes)
}

entries ++ [cert]
end

defp get_cert_hash(content, {entries, hashes}) do
content = String.trim(content)
hash = :sha |> :crypto.hash(content) |> Base.encode16()

case Repo.get(Cert, hash) do
nil ->
Logger.info("Adding chain cert: #{hash}")

Repo.insert!(%Cert{hash: hash, content: content})
{[%{domain: hash, cert: content} | entries], [hash | hashes]}

%Cert{content: ^content} ->
{entries, [hash | hashes]}
end
end
# @spec make_cert_chain(binary(), binary(), binary()) :: [map()]
# def make_cert_chain(domain, certificate, pkey) do
# [cert | chain] = String.split(certificate, "\n\n")
#
# {entries, hashes} = Enum.reduce(chain, {[], []}, &get_cert_hash/2)
#
# cert = %{
# domain: domain,
# cert: cert,
# pkey: pkey,
# chain: Enum.reverse(hashes)
# }
#
# entries ++ [cert]
# end

# defp get_cert_hash(content, {entries, hashes}) do
# content = String.trim(content)
# hash = :sha |> :crypto.hash(content) |> Base.encode16()
#
# case Repo.get(Cert, hash) do
# nil ->
# Logger.info("Adding chain cert: #{hash}")
#
# Repo.insert!(%Cert{hash: hash, content: content})
# {[%{domain: hash, cert: content} | entries], [hash | hashes]}
#
# %Cert{content: ^content} ->
# {entries, [hash | hashes]}
# end
# end
end

0 comments on commit 80ec611

Please sign in to comment.