Fixes for MIME encoding
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index 0951bd5..d72a002 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -1258,19 +1258,28 @@
/**
- @brief MIME encoded text to the encoded output.
+ @brief MIME encoded data to the encoded output.
- @param[in] pCtx The encoding context to add the MIME data to.
- @param[in] uTagRequirement Either @ref QCBOR_ENCODE_AS_TAG or @ref QCBOR_ENCODE_AS_BORROWED.
- @param[in] MIMEData Pointer and length of the MIME Data.
+ @param[in] pCtx The encoding context to add the MIME data to.
+ @param[in] uTagRequirement Either @ref QCBOR_ENCODE_AS_TAG or
+ @ref QCBOR_ENCODE_AS_BORROWED.
+ @param[in] MIMEData Pointer and length of the MIME data.
The text content is in MIME format per [RFC 2045]
- (https://tools.ietf.org/html/rfc2045) including the headers. Note
- that this only supports text-format MIME. Binary MIME is not
- supported.
+ (https://tools.ietf.org/html/rfc2045) including the headers.
- It is output as CBOR major type 3, a text string, with tag
- @ref CBOR_TAG_MIME indicating the text string is MIME data.
+ It is output as CBOR major type 2, a binary string, with tag @ref
+ CBOR_TAG_BINARY_MIME indicating the string is MIME data. This
+ outputs tag 257, not tag 36, as it can carry any type of MIME binary,
+ 7-bit, 8-bit, quoted-printable and base64 where tag 36 cannot.
+
+ Previous versions of QCBOR, those before spiffy decode, output tag
+ 36. Decoding supports both tag 36 and 257. (if the old behavior with
+ tag 36 is needed, copy the inline functions below and change the tag
+ number).
+
+ See also QCBORDecode_GetMIMEMessage() and
+ @ref QCBOR_TYPE_BINARY_MIME.
*/
static void QCBOREncode_AddTMIMEData(QCBOREncodeContext *pCtx,
uint8_t uTagRequirement,
@@ -2772,11 +2781,10 @@
static inline void
QCBOREncode_AddTMIMEData(QCBOREncodeContext *pMe, uint8_t uTagRequirement, UsefulBufC MIMEData)
{
- // TODO: add support for binary MIME.
if(uTagRequirement == QCBOR_ENCODE_AS_TAG) {
- QCBOREncode_AddTag(pMe, CBOR_TAG_MIME);
+ QCBOREncode_AddTag(pMe, CBOR_TAG_BINARY_MIME);
}
- QCBOREncode_AddText(pMe, MIMEData);
+ QCBOREncode_AddBytes(pMe, MIMEData);
}
static inline void
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index 7809733..cbfbe00 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -1386,8 +1386,7 @@
@param[in] pCtx The decode context.
@param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
@param[out] pMessage The decoded regular expression.
- @param[out] pbIsNot7Bit @c true if MIME is binary or 8-bit.
-
+ @param[out] pbIsTag257 @c true if tag was 257. May be @c NULL.
This decodes the standard CBOR MIME and binary MIME tags, integer tag
numbers of 36 or 257, or encoded CBOR that is not a tag, that is a
@@ -1399,34 +1398,34 @@
The MIME message itself is not parsed.
- This decodes both tag 36 and 257. If it is tag 257, pbIsNot7Bit
- is @c true. While it is clear that tag 36 can't contain,
- binary or 8-bit MIME, it is probably legal for tag 257
- to contain 7-bit MIME. Hopefully in most uses the
- Content-Transfer-Encoding header is present and the
- contents of pbIsNot7Bit can be ignored. It may be NULL.
+ This decodes both tag 36 and 257. If it is tag 257, pbIsTag257
+ is @c true. The difference between the two is that
+ tag 36 is utf8 and tag 257 is a byte string that can
+ carry binary MIME. QCBOR processes them exactly
+ the same. Possibly the difference can be ignored.
+ NULL can be passed to have no value returned.
See also @ref CBOR_TAG_MIME, @ref CBOR_TAG_BINARY_MIME,
- QCBOREncode_AddMIMEData(), @ref QCBOR_TYPE_MIME and
+ QCBOREncode_AddTMIMEData(), @ref QCBOR_TYPE_MIME and
@ref QCBOR_TYPE_BINARY_MIME.
*/
static void QCBORDecode_GetMIMEMessage(QCBORDecodeContext *pCtx,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ bool *pbIsTag257);
static void QCBORDecode_GetMIMEMessageInMapN(QCBORDecodeContext *pCtx,
int64_t nLabel,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ bool *pbIsTag257);
static void QCBORDecode_GetMIMEMessageInMapSZ(QCBORDecodeContext *pCtx,
const char *szLabel,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ bool *pbIsTag257);
/**
@brief Decode the next item as a UUID
@@ -1885,7 +1884,7 @@
QCBORError QCBORDecode_GetMIMEInternal(uint8_t uTagRequirement,
const QCBORItem *pItem,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit);
+ bool *pbIsTag257);
@@ -2219,7 +2218,7 @@
QCBORDecode_GetMIMEMessage(QCBORDecodeContext *pMe,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit)
+ bool *pbIsTag257)
{
if(pMe->uLastError != QCBOR_SUCCESS) {
// Already in error state, do nothing
@@ -2236,7 +2235,7 @@
pMe->uLastError = (uint8_t)QCBORDecode_GetMIMEInternal(uTagRequirement,
&Item,
pMessage,
- pbIsNot7Bit);
+ pbIsTag257);
}
static inline void
@@ -2244,7 +2243,7 @@
int64_t nLabel,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit)
+ bool *pbIsTag257)
{
QCBORItem Item;
QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
@@ -2253,7 +2252,7 @@
pMe->uLastError = (uint8_t)QCBORDecode_GetMIMEInternal(uTagRequirement,
&Item,
pMessage,
- pbIsNot7Bit);
+ pbIsTag257);
}
}
@@ -2262,7 +2261,7 @@
const char *szLabel,
uint8_t uTagRequirement,
UsefulBufC *pMessage,
- bool *pbIsNot7Bit)
+ bool *pbIsTag257)
{
QCBORItem Item;
QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
@@ -2271,7 +2270,7 @@
pMe->uLastError = (uint8_t)QCBORDecode_GetMIMEInternal(uTagRequirement,
&Item,
pMessage,
- pbIsNot7Bit);
+ pbIsTag257);
}
}