Skip to content

Commit

Permalink
Minor stylistic improvevments
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Nov 30, 2023
1 parent bfccb7e commit 6acea5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
23 changes: 9 additions & 14 deletions lib/cryppo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,10 @@ defmodule Cryppo do
def load(serialized) when is_binary(serialized) do
case String.split(serialized, ".") do
["Sign", "Rsa4096", signature, data] ->
with {:ok, sig} <- RsaSignature.load(signature, data), do: {:ok, sig}
RsaSignature.load(signature, data)

[strategy_name, encrypted_data, encryption_artefacts] ->
with {:ok, encrypted_data} <-
EncryptedData.load(strategy_name, encrypted_data, encryption_artefacts) do
{:ok, encrypted_data}
end
EncryptedData.load(strategy_name, encrypted_data, encryption_artefacts)

[
strategy,
Expand All @@ -303,15 +300,13 @@ defmodule Cryppo do
key_derivation_strategy,
derivation_artefacts
] ->
with {:ok, encrypted_data_with_derived_key} <-
EncryptedDataWithDerivedKey.load(
strategy,
encrypted_data,
encryption_artefacts,
key_derivation_strategy,
derivation_artefacts
),
do: {:ok, encrypted_data_with_derived_key}
EncryptedDataWithDerivedKey.load(
strategy,
encrypted_data,
encryption_artefacts,
key_derivation_strategy,
derivation_artefacts
)

_ ->
{:error, :invalid_serialization_value}
Expand Down
4 changes: 1 addition & 3 deletions lib/cryppo/encrypted_data_with_derived_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ defmodule Cryppo.EncryptedDataWithDerivedKey do
derived_key: %DerivedKey{} = derived_key,
encrypted_data: %EncryptedData{} = encrypted_data
}) do
[encrypted_data, derived_key]
|> Enum.map(fn v -> Serialization.serialize(v) end)
|> Enum.join(".")
[encrypted_data, derived_key] |> Enum.map_join(".", &Serialization.serialize/1)
end
end
end

0 comments on commit 6acea5e

Please sign in to comment.