Simplify table values

This commit is contained in:
Mike Cifelli 2024-06-01 10:30:35 -04:00
parent 7e218dfb5d
commit 4dee9f61da
Signed by: mike
GPG Key ID: 6B08C6BE47D08E4C
4 changed files with 28 additions and 6 deletions

View File

@ -1,7 +1,7 @@
defmodule Chronoscope.NTS.KeyEstablishmentResponse do
import Bitwise
@aead_alogorithms %{
@aead_algorithms %{
15 => "AEAD_AES_SIV_CMAC_256",
30 => "AEAD_AES_128_GCM_SIV"
}
@ -16,6 +16,12 @@ defmodule Chronoscope.NTS.KeyEstablishmentResponse do
2 => "Internal Server Error"
}
def aead_algorithm_to_id(algorithm) do
@aead_algorithms
|> Map.new(fn {k, v} -> {v, k} end)
|> Map.get(algorithm)
end
def parse(response) do
parse_response(response, %{})
end
@ -127,7 +133,7 @@ defmodule Chronoscope.NTS.KeyEstablishmentResponse do
end
defp do_parse_aead_algorithm_list([high, low | rest], acc) do
@aead_alogorithms
@aead_algorithms
|> Map.get(combine_octets(high, low), "UNKNOWN")
|> then(&do_parse_aead_algorithm_list(rest, [&1 | acc]))
end

View File

@ -2,6 +2,7 @@ defmodule ChronoscopeWeb.IndexLive do
use ChronoscopeWeb, :live_view
alias Chronoscope.NTS
alias Chronoscope.NTS.KeyEstablishmentResponse
@topic "nts-servers"

View File

@ -37,7 +37,13 @@
<%= status %>
</td>
<td class="py-4 px-6 whitespace-nowrap">
<%= Enum.at(response.aead_algorithms, 0) %>
<% aead_algorithm = Enum.at(response.aead_algorithms, 0) %>
<span class="group relative">
<%= KeyEstablishmentResponse.aead_algorithm_to_id(aead_algorithm) %>
<span class="pointer-events-none absolute -top-9 left-0 w-max p-1 rounded-lg bg-zinc-300 dark:bg-zinc-600 opacity-0 transition-opacity group-hover:opacity-100">
<%= aead_algorithm %>
</span>
</span>
</td>
<td class="py-4 px-6 whitespace-nowrap">
<%= length(response.cookies) %>
@ -46,10 +52,10 @@
<%= response.cookie_length %>
</td>
<td class="py-4 px-6 whitespace-nowrap">
<%= response.cert_expiration %>
<%= response.cert_expiration |> DateTime.from_iso8601 |> then(fn {:ok, dt, _} -> Calendar.strftime(dt, "%Y-%m-%d %H:%M:%SZ") end)%>
</td>
<td class="py-4 px-6 whitespace-nowrap">
<%= server.last_key_establishment %>
<%= server.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ") %>
</td>
<% else %>
@ -70,7 +76,9 @@
<td class="py-4 px-6 whitespace-nowrap"> - </td>
<td class="py-4 px-6 whitespace-nowrap">
<%= server.last_key_establishment %>
<%=
server.last_key_establishment |> Calendar.strftime("%Y-%m-%d %H:%M:%SZ")
%>
</td>
<% end %>
</tr>

View File

@ -3,6 +3,13 @@ defmodule Chronoscope.NTS.KeyEstablishmentResponseTest do
import Chronoscope.NTS.KeyEstablishmentResponse
describe "Chronoscope.NTS.KeyEstablishmentResponse.aead_algorithm_to_id()" do
test "maps names to a numeric identifiers" do
assert aead_algorithm_to_id("AEAD_AES_SIV_CMAC_256") == 15
assert aead_algorithm_to_id("AEAD_AES_128_GCM_SIV") == 30
end
end
describe "Chronoscope.NTS.KeyEstablishmentResponse.parse()" do
test "handles empty response" do
assert parse([]) == %{}