-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add base64 encoding and decoding APIs that accept az_span. #1816
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b3b407
Add base64 encoding and decoding APIs that accept az_span.
ahsonkhan bff55bd
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-c into …
ahsonkhan 03c7608
Add entry to the changelog.
ahsonkhan 07e6ce9
Address PR feedback - move const to r.h.s.
ahsonkhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @file | ||
* | ||
* @brief Defines APIs to convert between binary data and UTF-8 encoded text that is represented in | ||
* base 64. | ||
* | ||
* @note You MUST NOT use any symbols (macros, functions, structures, enums, etc.) | ||
* prefixed with an underscore ('_') directly in your application code. These symbols | ||
* are part of Azure SDK's internal implementation; we do not document these symbols | ||
* and they are subject to change in future versions of the SDK which would break your code. | ||
*/ | ||
|
||
#ifndef _az_BASE64_H | ||
#define _az_BASE64_H | ||
|
||
#include <azure/core/az_result.h> | ||
#include <azure/core/az_span.h> | ||
|
||
#include <stdint.h> | ||
|
||
#include <azure/core/_az_cfg_prefix.h> | ||
|
||
/** | ||
* @brief Encodes the span of binary data into UTF-8 encoded text represented as base 64. | ||
* | ||
* @param destination_base64_text The output #az_span where the encoded base 64 text should be | ||
* copied to as a result of the operation. | ||
* @param[in] source_bytes The input #az_span that contains binary data to be encoded. | ||
* @param[out] out_written A pointer to an `int32_t` that receives the number of bytes written into | ||
* the destination #az_span. This can be used to slice the output for subsequent calls, if | ||
* necessary. | ||
* | ||
* @return An #az_result value indicating the result of the operation. | ||
* @retval #AZ_OK Success. | ||
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE The \p destination_base64_text is not large enough to contain | ||
* the encoded bytes. | ||
*/ | ||
AZ_NODISCARD az_result | ||
az_base64_encode(az_span destination_base64_text, az_span source_bytes, int32_t* out_written); | ||
|
||
/** | ||
* @brief Returns the maximum length of the result if you were to encode an #az_span of the | ||
* specified length which contained binary data. | ||
* | ||
* @param source_bytes_size The size of the span containing binary data. | ||
* | ||
* @return The maximum length of the result. | ||
*/ | ||
AZ_NODISCARD int32_t az_base64_get_max_encoded_size(int32_t source_bytes_size); | ||
|
||
/** | ||
* @brief Decodes the span of UTF-8 encoded text represented as base 64 into binary data. | ||
* | ||
* @param destination_bytes The output #az_span where the decoded binary data should be copied to as | ||
* a result of the operation. | ||
* @param[in] source_base64_text The input #az_span that contains the base 64 text to be decoded. | ||
* @param[out] out_written A pointer to an `int32_t` that receives the number of bytes written into | ||
* the destination #az_span. This can be used to slice the output for subsequent calls, if | ||
* necessary. | ||
* | ||
* @return An #az_result value indicating the result of the operation. | ||
* @retval #AZ_OK Success. | ||
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE The \p destination_bytes is not large enough to contain | ||
* the decoded text. | ||
* @retval #AZ_ERROR_UNEXPECTED_CHAR The input \p source_base64_text contains characters outside of | ||
* the expected base 64 range, has invalid or more than two padding characters, or is incomplete | ||
* (that is, not a multiple of 4). | ||
* @retval #AZ_ERROR_UNEXPECTED_END The input \p source_base64_text is incomplete (that is, it is | ||
* not of a size which is a multiple of 4). | ||
*/ | ||
AZ_NODISCARD az_result | ||
az_base64_decode(az_span destination_bytes, az_span source_base64_text, int32_t* out_written); | ||
|
||
/** | ||
* @brief Returns the maximum length of the result if you were to decode an #az_span of the | ||
* specified length which contained base 64 encoded text. | ||
* | ||
* @param source_base64_text_size The size of the span containing base 64 encoded text. | ||
* | ||
* @return The maximum length of the result. | ||
*/ | ||
AZ_NODISCARD int32_t az_base64_get_max_decoded_size(int32_t source_base64_text_size); | ||
|
||
#include <azure/core/_az_cfg_suffix.h> | ||
|
||
#endif // _az_BASE64_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we got rid of that in most places already (probably the remaining IoT files can remove it too). Let me dig up the rational as to why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here: #1057
From @antkmsft