Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
0381-base64-introduce-new-types-for-base64-alph...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0381-base64-introduce-new-types-for-base64-alphabet.patch of Package erlang
From 919435a6bd07420faffa9ac851f5c254ba6d96be Mon Sep 17 00:00:00 2001 From: Maxim Fedorov <dane@whatsapp.com> Date: Thu, 22 Apr 2021 09:26:05 -0700 Subject: [PATCH] base64: introduce new types for base64 alphabet No change in logic, but specs are updated to reflect RFC 4648 compliance. --- lib/stdlib/doc/src/base64.xml | 19 ++++++++++++++---- lib/stdlib/src/base64.erl | 37 +++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/stdlib/doc/src/base64.xml b/lib/stdlib/doc/src/base64.xml index 2b50f03bbd..74773ab0ca 100644 --- a/lib/stdlib/doc/src/base64.xml +++ b/lib/stdlib/doc/src/base64.xml @@ -39,12 +39,23 @@ <datatypes> <datatype> - <name name="ascii_string"/> + <name name="base64_alphabet"/> + <desc><p>Base 64 Encoding alphabet, see <url href="https://www.ietf.org/rfc/rfc4648.txt">RFC 4648</url>.</p> + </desc> + </datatype> + <datatype> + <name name="base64_string"/> + <desc><p>Base 64 encoded string.</p> + </desc> + </datatype> + <datatype> + <name name="base64_binary"/> + <desc><p>Base 64 encoded binary.</p> + </desc> </datatype> <datatype> - <name name="ascii_binary"/> - <desc><p>A <c>binary()</c> with ASCII characters in the range 1 to - 255.</p> + <name name="byte_string"/> + <desc><p>Arbitrary sequences of octets.</p> </desc> </datatype> </datatypes> diff --git a/lib/stdlib/src/base64.erl b/lib/stdlib/src/base64.erl index 6ea4147abf..e2993cba9d 100644 --- a/lib/stdlib/src/base64.erl +++ b/lib/stdlib/src/base64.erl @@ -24,14 +24,21 @@ -export([encode/1, decode/1, mime_decode/1, encode_to_string/1, decode_to_string/1, mime_decode_to_string/1]). + +%% RFC 4648: Base 64 Encoding alphabet +-type base64_alphabet() :: $A..$Z | $a..$z | $0..$9 | $+ | $/ | $=. + %% The following type is a subtype of string() for return values -%% of (some) functions of this module. --type ascii_string() :: [1..255]. --type ascii_binary() :: binary(). +%% of encoding functions. +-type base64_string() :: [base64_alphabet()]. +-type base64_binary() :: binary(). + +%% Decoded sequence of octets +-type byte_string() :: [byte()]. -spec encode_to_string(Data) -> Base64String when - Data :: ascii_string() | ascii_binary(), - Base64String :: ascii_string(). + Data :: byte_string() | binary(), + Base64String :: base64_string(). encode_to_string(Bin) when is_binary(Bin) -> encode_to_string(binary_to_list(Bin)); @@ -39,8 +46,8 @@ encode_to_string(List) when is_list(List) -> encode_list_to_string(List). -spec encode(Data) -> Base64 when - Data :: ascii_string() | ascii_binary(), - Base64 :: ascii_binary(). + Data :: byte_string() | binary(), + Base64 :: base64_binary(). encode(Bin) when is_binary(Bin) -> encode_binary(Bin, <<>>); @@ -99,8 +106,8 @@ encode_list([B1,B2,B3|Ls], A) -> %% converting, whereas decode crashes if an illegal character is found -spec decode(Base64) -> Data when - Base64 :: ascii_string() | ascii_binary(), - Data :: ascii_binary(). + Base64 :: base64_string() | base64_binary(), + Data :: binary(). decode(Bin) when is_binary(Bin) -> decode_binary(Bin, <<>>); @@ -108,8 +115,8 @@ decode(List) when is_list(List) -> decode_list(List, <<>>). -spec mime_decode(Base64) -> Data when - Base64 :: ascii_string() | ascii_binary(), - Data :: ascii_binary(). + Base64 :: base64_string() | base64_binary(), + Data :: binary(). mime_decode(Bin) when is_binary(Bin) -> mime_decode_binary(Bin, <<>>); @@ -121,8 +128,8 @@ mime_decode(List) when is_list(List) -> %% character is found -spec decode_to_string(Base64) -> DataString when - Base64 :: ascii_string() | ascii_binary(), - DataString :: ascii_string(). + Base64 :: base64_string() | base64_binary(), + DataString :: byte_string(). decode_to_string(Bin) when is_binary(Bin) -> decode_to_string(binary_to_list(Bin)); @@ -130,8 +137,8 @@ decode_to_string(List) when is_list(List) -> decode_list_to_string(List). -spec mime_decode_to_string(Base64) -> DataString when - Base64 :: ascii_string() | ascii_binary(), - DataString :: ascii_string(). + Base64 :: base64_string() | base64_binary(), + DataString :: byte_string(). mime_decode_to_string(Bin) when is_binary(Bin) -> mime_decode_to_string(binary_to_list(Bin)); -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor