add string encoding

This commit is contained in:
glyph 2022-09-20 19:33:58 +01:00
parent 99b6a046b4
commit e4b9dc7b54
2 changed files with 23 additions and 1 deletions

View File

@ -15,4 +15,26 @@ defmodule SsbBfe do
def hello do
:world
end
def encode(value) when is_bitstring(value) do
cond do
String.starts_with?(value, "@") ->
SsbBfe.Encoder.encode_feed(value)
String.starts_with?(value, "%") ->
SsbBfe.Encoder.encode_msg(value)
String.starts_with?(value, "&") ->
SsbBfe.Encoder.encode_blob(value)
String.ends_with?(value, ".sig.ed25519") ->
SsbBfe.Encoder.encode_sig(value)
String.ends_with?(value, [".box", ".box2"]) ->
SsbBfe.Encoder.encode_box(value)
true ->
SsbBfe.Encoder.encode_str(value)
end
end
end

View File

@ -1,5 +1,5 @@
# might be good to use a multiclause function for the `encode` function
# - use the `where` conditional guard with e.g. `is_number`
# - use the `when` conditional guard with e.g. `is_number`
defmodule SsbBfe.Encoder do
# Extract the base64 substring from a sigil-link and decode it.