Simplify secret backend fallback

This commit is contained in:
2026-06-21 14:15:55 +02:00
parent 2e61059568
commit c3a8a8a755
2 changed files with 9 additions and 4 deletions

View File

@@ -41,10 +41,7 @@ defmodule BDS.AI.SecretBackend do
@spec decrypt(String.t()) :: {:ok, String.t()} | {:error, term()}
def decrypt(encoded) when is_binary(encoded) do
with {:ok, key} <- secret_key() do
case decrypt_with(encoded, key) do
{:ok, plaintext} -> {:ok, plaintext}
{:error, :invalid_ciphertext} -> decrypt_legacy(encoded)
end
decrypt_with_fallback(encoded, key)
end
end
@@ -79,6 +76,13 @@ defmodule BDS.AI.SecretBackend do
]
end
defp decrypt_with_fallback(encoded, key) do
case decrypt_with(encoded, key) do
{:ok, _plaintext} = ok -> ok
{:error, :invalid_ciphertext} -> decrypt_legacy(encoded)
end
end
defp decrypt_with(encoded, key) do
with {:ok, binary} <- Base.decode64(encoded),
<<iv::binary-size(12), tag::binary-size(16), ciphertext::binary>> <- binary,