Skip to content

Commit 164c6f0

Browse files
committed
refactor: improve readability
1 parent 0f4079d commit 164c6f0

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/mix/tasks/generate_vapid_keys.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ defmodule Mix.Tasks.Generate.Vapid.Keys do
1111
vapid_private_key: Base.url_encode64(private_key, padding: false),
1212
vapid_subject: "mailto:admin@email.com"
1313
}
14+
|> IO.inspect
1415
end
1516
end

lib/web_push_elixir.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule WebPushElixir do
2020
|> :binary.part(0, length)
2121
end
2222

23-
defp encrypt(message, p256dh, auth) do
23+
defp encrypt_payload(message, p256dh, auth) do
2424
client_public_key = url_decode(p256dh)
2525
client_auth_secret = url_decode(auth)
2626

@@ -95,22 +95,22 @@ defmodule WebPushElixir do
9595
vapid_public_key = url_decode(System.get_env("VAPID_PUBLIC_KEY"))
9696
vapid_private_key = url_decode(System.get_env("VAPID_PRIVATE_KEY"))
9797

98-
%{endpoint: endpoint, keys: %{auth: auth, p256dh: p256dh}} =
98+
%{endpoint: endpoint, keys: %{p256dh: p256dh, auth: auth}} =
9999
Jason.decode!(subscription, keys: :atoms)
100100

101-
encrypted = encrypt(message, p256dh, auth)
101+
encrypted_payload = encrypt_payload(message, p256dh, auth)
102102

103103
signed_json_web_token =
104104
sign_json_web_token(endpoint, vapid_public_key, vapid_private_key)
105105

106-
HTTPoison.post(endpoint, encrypted.ciphertext, %{
106+
HTTPoison.post(endpoint, encrypted_payload.ciphertext, %{
107107
"Authorization" => "WebPush #{signed_json_web_token}",
108108
"Content-Encoding" => "aesgcm",
109-
"Content-Length" => "#{byte_size(encrypted.ciphertext)}",
109+
"Content-Length" => "#{byte_size(encrypted_payload.ciphertext)}",
110110
"Content-Type" => "application/octet-stream",
111111
"Crypto-Key" =>
112-
"dh=#{url_encode(encrypted.local_public_key)};p256ecdsa=#{url_encode(vapid_public_key)}",
113-
"Encryption" => "salt=#{url_encode(encrypted.salt)}",
112+
"dh=#{url_encode(encrypted_payload.local_public_key)};p256ecdsa=#{url_encode(vapid_public_key)}",
113+
"Encryption" => "salt=#{url_encode(encrypted_payload.salt)}",
114114
"TTL" => "60"
115115
})
116116
end

0 commit comments

Comments
 (0)