@@ -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