@@ -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
0 commit comments