From d56676b8d0b906118c3f074dca518e70a2bae313 Mon Sep 17 00:00:00 2001 From: glyph Date: Fri, 6 May 2022 18:47:29 +0200 Subject: [PATCH] add get_box_type function --- lib/ssb_bfe/types.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/ssb_bfe/types.ex b/lib/ssb_bfe/types.ex index d5cf2af..1e1022c 100644 --- a/lib/ssb_bfe/types.ex +++ b/lib/ssb_bfe/types.ex @@ -9,6 +9,21 @@ defmodule SsbBfe.Types do end end + @doc ~S""" + Take a box as a string and return the encoded bytes representing the box + type-format. Return `nil` if the ID does not end with `.box` or `.box2`. + """ + def get_box_type(boxed_str) do + cond do + String.ends_with?(boxed_str, ".box") -> + <<5, 0>> + String.ends_with?(boxed_str, ".box2") -> + <<5, 1>> + true -> + nil + end + end + @doc ~S""" Take a feed ID (key) as a string and return the encoded bytes representing the feed type-format. Return `nil` if the ID does not end with `.ed25519`.