add sig encoder and improve base64 extractor
This commit is contained in:
parent
40a108f5e5
commit
8ce0502782
@ -2,8 +2,15 @@
|
||||
# - use the `where` conditional guard with e.g. `is_number`
|
||||
|
||||
defmodule SsbBfe.Encoder do
|
||||
# Extract the base64 substring from a sigil-link and decode it.
|
||||
defp extract_base64_data(str) do
|
||||
base64_data = String.slice(str, 1, 44)
|
||||
base64_data = String.slice(str, 1..44)
|
||||
Base.decode64(base64_data)
|
||||
end
|
||||
|
||||
# Provide a pattern with which to split a string and base64 decode the first part.
|
||||
defp extract_base64_data(str, pattern) do
|
||||
[base64_data | _] = String.split(str, pattern)
|
||||
Base.decode64(base64_data)
|
||||
end
|
||||
|
||||
@ -19,8 +26,7 @@ defmodule SsbBfe.Encoder do
|
||||
|
||||
def encode_box(box_str) do
|
||||
box_tf_tag = SsbBfe.Types.get_box_type(box_str)
|
||||
[base64_data, _] = String.split(box_str, ".")
|
||||
{:ok, decoded_base64_data} = Base.decode64(base64_data)
|
||||
{:ok, decoded_base64_data} = extract_base64_data(box_str, ".")
|
||||
box_tf_tag <> decoded_base64_data
|
||||
end
|
||||
|
||||
@ -35,4 +41,9 @@ defmodule SsbBfe.Encoder do
|
||||
{:ok, decoded_base64_data} = extract_base64_data(msg_id)
|
||||
msg_tf_tag <> decoded_base64_data
|
||||
end
|
||||
|
||||
def encode_sig(sig) do
|
||||
{:ok, decoded_base64_data} = extract_base64_data(sig, ".sig.ed25519")
|
||||
<<4, 0>> <> decoded_base64_data
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user