summaryrefslogtreecommitdiffstats
path: root/MdePkg/Include
diff options
context:
space:
mode:
authorMike Turner <miketur@microsoft.com>2018-12-28 16:00:02 +0800
committerLiming Gao <liming.gao@intel.com>2019-02-02 21:41:11 +0800
commit1f7af69d10fa3c88e996d38179d5f985f6c7dfe5 (patch)
treea4c0deb98925e7ee02cab05754b12f6e96d044fe /MdePkg/Include
parent97c8f5b9e7d3136b6051a05cf056ce5ca9e79893 (diff)
downloadedk2-1f7af69d10fa3c88e996d38179d5f985f6c7dfe5.tar.gz
edk2-1f7af69d10fa3c88e996d38179d5f985f6c7dfe5.tar.bz2
edk2-1f7af69d10fa3c88e996d38179d5f985f6c7dfe5.zip
MdePkg/BaseLib: Add Base64Encode() and Base64Decode()
Introduce public functions Base64Encode and Base64Decode. https://bugzilla.tianocore.org/show_bug.cgi?id=1370 v2:1.Remove some white space. 2.Add unit test with test vectors in RFC 4648. https://github.com/shenglei10/edk2/tree/encode_test https://github.com/shenglei10/edk2/tree/decode_test v3:1.Align white space. 2.Update comments of Base64Encode and Base64Decode. 3.Change the use of macro RETURN_DEVICE_ERROR to RETURN_INVALID_PARAMETER in string.c. v4:Change parameters' names. v5:1.Update usage of variables. 2.Remove debug message in Base64Decode(). Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'MdePkg/Include')
-rw-r--r--MdePkg/Include/Library/BaseLib.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index c58e4b089d..9c42f82a7d 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -2761,6 +2761,62 @@ AsciiCharToUpper (
);
/**
+ Convert binary data to a Base64 encoded ascii string based on RFC4648.
+
+ Produce a Null-terminated Ascii string in the output buffer specified by Destination and DestinationSize.
+ The Ascii string is produced by converting the data string specified by Source and SourceLength.
+
+ @param Source Input UINT8 data
+ @param SourceLength Number of UINT8 bytes of data
+ @param Destination Pointer to output string buffer
+ @param DestinationSize Size of ascii buffer. Set to 0 to get the size needed.
+ Caller is responsible for passing in buffer of DestinationSize
+
+ @retval RETURN_SUCCESS When ascii buffer is filled in.
+ @retval RETURN_INVALID_PARAMETER If Source is NULL or DestinationSize is NULL.
+ @retval RETURN_INVALID_PARAMETER If SourceLength or DestinationSize is bigger than (MAX_ADDRESS - (UINTN)Destination).
+ @retval RETURN_BUFFER_TOO_SMALL If SourceLength is 0 and DestinationSize is <1.
+ @retval RETURN_BUFFER_TOO_SMALL If Destination is NULL or DestinationSize is smaller than required buffersize.
+
+**/
+RETURN_STATUS
+EFIAPI
+Base64Encode (
+ IN CONST UINT8 *Source,
+ IN UINTN SourceLength,
+ OUT CHAR8 *Destination OPTIONAL,
+ IN OUT UINTN *DestinationSize
+ );
+
+/**
+ Convert Base64 ascii string to binary data based on RFC4648.
+
+ Produce Null-terminated binary data in the output buffer specified by Destination and DestinationSize.
+ The binary data is produced by converting the Base64 ascii string specified by Source and SourceLength.
+
+ @param Source Input ASCII characters
+ @param SourceLength Number of ASCII characters
+ @param Destination Pointer to output buffer
+ @param DestinationSize Caller is responsible for passing in buffer of at least DestinationSize.
+ Set 0 to get the size needed. Set to bytes stored on return.
+
+ @retval RETURN_SUCCESS When binary buffer is filled in.
+ @retval RETURN_INVALID_PARAMETER If Source is NULL or DestinationSize is NULL.
+ @retval RETURN_INVALID_PARAMETER If SourceLength or DestinationSize is bigger than (MAX_ADDRESS -(UINTN)Destination ).
+ @retval RETURN_INVALID_PARAMETER If there is any invalid character in input stream.
+ @retval RETURN_BUFFER_TOO_SMALL If buffer length is smaller than required buffer size.
+
+ **/
+RETURN_STATUS
+EFIAPI
+Base64Decode (
+ IN CONST CHAR8 *Source,
+ IN UINTN SourceLength,
+ OUT UINT8 *Destination OPTIONAL,
+ IN OUT UINTN *DestinationSize
+ );
+
+/**
Converts an 8-bit value to an 8-bit BCD value.
Converts the 8-bit value specified by Value to BCD. The BCD value is