add get_msg_type function

This commit is contained in:
glyph 2022-05-06 18:35:04 +02:00
parent 588f11e7bc
commit 3745289e98
1 changed files with 16 additions and 0 deletions

View File

@ -18,4 +18,20 @@ defmodule SsbBfe.Types do
<<0, 0>>
end
end
@doc ~S"""
Take a message ID as a string and return the encoded bytes representing
the message type-format. Return `nil` if the ID does not end with `.sha256`
or `.cloaked`.
"""
def get_msg_type(msg_id) do
cond do
String.ends_with?(msg_id, ".sha256") ->
<<1, 0>>
String.ends_with?(msg_id, ".cloaked") ->
<<1, 2>>
true ->
nil
end
end
end