In DoAuth.Crypto, we allow for loosey-goosey calls to sign.
For example, we allow raw iolists.
It contradicts the uptight coding principles.
How?
[ ] Only support T.t() | list(T.t()) as it is implemented in on_the_map.
@doc """
Wrapper around detached signatures that creates an object tracking
corresponding public key.
Note that we allow "Uptight iolist" as a message, which is a list of `Uptight.Text` objects.
"""
@spec sign(T.t() | list(T.t()), keypair()) :: detached_sig()
def sign(msg, kp) do
sign_raw(msg |> unwrap_message(), kp |> unwrap_keypair())
end
defp unwrap_message(%T{} = msg) do
msg |> T.un()
end
defp unwrap_message(msg) when is_list(msg) do
msg |> map(&T.un/1)
end
defp unwrap_keypair(%{secret: _, public: _} = kp) do
kp |> map(&Binary.un/1)
end
defp sign_raw(msg, %{secret: sk, public: pk}) do
%{public: pk, signature: C.sign_detached(msg, sk)} |> map(&Binary.new!/1)
end
[ ] Make sure that we never expose loose interfaces and all the _raw functions are private, unless we have a good reason to have them public.
Why?
In DoAuth.Crypto, we allow for loosey-goosey calls to
sign
. For example, we allow raw iolists. It contradicts the uptight coding principles.How?
[ ] Only support
T.t() | list(T.t())
as it is implemented in on_the_map.[ ] Make sure that we never expose loose interfaces and all the
_raw
functions are private, unless we have a good reason to have them public.