Skip to content

Commit 1245751

Browse files
committed
Drop earlier Erlang/OTP versions
1 parent 5884b46 commit 1245751

5 files changed

Lines changed: 25 additions & 52 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
matrix:
1717
include:
1818
- pair:
19-
elixir: 1.7.4
20-
otp: 20.3.8.26
19+
elixir: 1.11
20+
otp: 23.3
2121
- pair:
22-
elixir: 1.14.2
22+
elixir: 1.14
2323
otp: 25.2
2424
lint: lint
2525
steps:

lib/plug/crypto/key_generator.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,5 @@ defmodule Plug.Crypto.KeyGenerator do
9292
iterate(fun, iteration - 1, next, :crypto.exor(next, acc))
9393
end
9494

95-
# TODO: remove when we require OTP 22.1
96-
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
97-
defp hmac_fun(digest, key), do: &:crypto.mac(:hmac, digest, key, &1)
98-
else
99-
defp hmac_fun(digest, key), do: &:crypto.hmac(digest, key, &1)
100-
end
95+
defp hmac_fun(digest, key), do: &:crypto.mac(:hmac, digest, key, &1)
10196
end

lib/plug/crypto/message_encryptor.ex

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,47 +108,32 @@ defmodule Plug.Crypto.MessageEncryptor do
108108
end
109109
end
110110

111-
# TODO: remove when we require OTP 22
112-
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :crypto_one_time_aead, 6) do
113-
defp block_encrypt(cipher, key, iv, {aad, payload}) do
114-
cipher = cipher_alias(cipher, bit_size(key))
115-
:crypto.crypto_one_time_aead(cipher, key, iv, payload, aad, true)
116-
catch
117-
:error, :notsup -> raise_notsup(cipher)
118-
end
119-
120-
defp block_decrypt(cipher, key, iv, {aad, payload, tag}) do
121-
cipher = cipher_alias(cipher, bit_size(key))
122-
:crypto.crypto_one_time_aead(cipher, key, iv, payload, aad, tag, false)
123-
catch
124-
:error, :notsup -> raise_notsup(cipher)
125-
end
126-
127-
defp cipher_alias(:aes_gcm, 128), do: :aes_128_gcm
128-
defp cipher_alias(:aes_gcm, 192), do: :aes_192_gcm
129-
defp cipher_alias(:aes_gcm, 256), do: :aes_256_gcm
130-
defp cipher_alias(other, _), do: other
131-
else
132-
defp block_encrypt(cipher, key, iv, payload) do
133-
:crypto.block_encrypt(cipher, key, iv, payload)
134-
catch
135-
:error, :notsup -> raise_notsup(cipher)
136-
end
111+
defp block_encrypt(cipher, key, iv, {aad, payload}) do
112+
cipher = cipher_alias(cipher, bit_size(key))
113+
:crypto.crypto_one_time_aead(cipher, key, iv, payload, aad, true)
114+
catch
115+
:error, :notsup -> raise_notsup(cipher)
116+
end
137117

138-
defp block_decrypt(cipher, key, iv, payload) do
139-
:crypto.block_decrypt(cipher, key, iv, payload)
140-
catch
141-
:error, :notsup -> raise_notsup(cipher)
142-
end
118+
defp block_decrypt(cipher, key, iv, {aad, payload, tag}) do
119+
cipher = cipher_alias(cipher, bit_size(key))
120+
:crypto.crypto_one_time_aead(cipher, key, iv, payload, aad, tag, false)
121+
catch
122+
:error, :notsup -> raise_notsup(cipher)
143123
end
144124

125+
defp cipher_alias(:aes_gcm, 128), do: :aes_128_gcm
126+
defp cipher_alias(:aes_gcm, 192), do: :aes_192_gcm
127+
defp cipher_alias(:aes_gcm, 256), do: :aes_256_gcm
128+
defp cipher_alias(other, _), do: other
129+
145130
defp raise_notsup(algo) do
146131
raise "the algorithm #{inspect(algo)} is not supported by your Erlang/OTP installation. " <>
147132
"Please make sure it was compiled with the correct OpenSSL/BoringSSL bindings"
148133
end
149134

150135
# Wraps a decrypted content encryption key (CEK) with secret and
151-
# sign_secret using AES GCM mode. Accepts keys of 128, 192, or
136+
# sign_secret using AES GCM mode. Accepts keys of 128, 192, or
152137
# 256 bits based on the length of the secret key.
153138
#
154139
# See: https://tools.ietf.org/html/rfc7518#section-4.7
@@ -165,7 +150,7 @@ defmodule Plug.Crypto.MessageEncryptor do
165150
end
166151

167152
# Unwraps an encrypted content encryption key (CEK) with secret and
168-
# sign_secret using AES GCM mode. Accepts keys of 128, 192, or 256
153+
# sign_secret using AES GCM mode. Accepts keys of 128, 192, or 256
169154
# bits based on the length of the secret key.
170155
#
171156
# See: https://tools.ietf.org/html/rfc7518#section-4.7

lib/plug/crypto/message_verifier.ex

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ defmodule Plug.Crypto.MessageVerifier do
4747
defp hmac_sha2_sign(payload, key, digest_type) do
4848
protected = hmac_sha2_to_protected(digest_type)
4949
plain_text = signing_input(protected, payload)
50-
signature = hmac(digest_type, key, plain_text)
50+
signature = :crypto.mac(:hmac, digest_type, key, plain_text)
5151
encode_token(plain_text, signature)
5252
end
5353

5454
defp hmac_sha2_verify(signed, key) when is_binary(signed) and is_binary(key) do
5555
case decode_token(signed) do
5656
{protected, payload, plain_text, signature} when protected in ["HS256", "HS384", "HS512"] ->
5757
digest_type = hmac_sha2_to_digest_type(protected)
58-
challenge = hmac(digest_type, key, plain_text)
58+
challenge = :crypto.mac(:hmac, digest_type, key, plain_text)
5959

6060
if Plug.Crypto.secure_compare(challenge, signature) do
6161
{:ok, payload}
@@ -93,11 +93,4 @@ defmodule Plug.Crypto.MessageVerifier do
9393
|> Kernel.<>(".")
9494
|> Kernel.<>(Base.url_encode64(payload, padding: false))
9595
end
96-
97-
# TODO: remove when we require OTP 22.1
98-
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
99-
defp hmac(digest, key, data), do: :crypto.mac(:hmac, digest, key, data)
100-
else
101-
defp hmac(digest, key, data), do: :crypto.hmac(digest, key, data)
102-
end
10396
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Plug.Crypto.MixProject do
99
[
1010
app: :plug_crypto,
1111
version: @version,
12-
elixir: "~> 1.7",
12+
elixir: "~> 1.11",
1313
start_permanent: Mix.env() == :prod,
1414
deps: deps(),
1515
package: package(),

0 commit comments

Comments
 (0)