@@ -5556,7 +5556,7 @@ int DecodeObjectId(const byte* in, word32 inSz, word16* out, word32* outSz)
55565556 }
55575557
55585558 /* return length */
5559- *outSz = y;
5559+ *outSz = (word32) y;
55605560
55615561 return 0;
55625562}
@@ -37034,73 +37034,43 @@ int wc_Asn1PrintOptions_Set(Asn1PrintOptions* opts, enum Asn1PrintOpt opt,
3703437034 break;
3703537035 /* Number of spaces to indent for each change in depth. */
3703637036 case ASN1_PRINT_OPT_INDENT:
37037- /* Only 4 bits available for value. */
37037+ /* Only 4 bits allowed for value. */
3703837038 if (val >= (1 << 4)) {
3703937039 ret = BAD_FUNC_ARG;
3704037040 }
3704137041 else {
37042- opts->indent = val;
37042+ opts->indent = (word8) val;
3704337043 }
3704437044 break;
3704537045 /* Draw branches instead of indenting. */
3704637046 case ASN1_PRINT_OPT_DRAW_BRANCH:
3704737047 /* Boolean value. */
37048- if (val > 1) {
37049- ret = BAD_FUNC_ARG;
37050- }
37051- else {
37052- opts->draw_branch = val;
37053- }
37048+ opts->draw_branch = (val > 0);
3705437049 break;
3705537050 /* Show raw data of primitive types as octets. */
3705637051 case ASN1_PRINT_OPT_SHOW_DATA:
3705737052 /* Boolean value. */
37058- if (val > 1) {
37059- ret = BAD_FUNC_ARG;
37060- }
37061- else {
37062- opts->show_data = val;
37063- }
37053+ opts->show_data = (val > 0);
3706437054 break;
3706537055 /* Show header data as octets. */
3706637056 case ASN1_PRINT_OPT_SHOW_HEADER_DATA:
3706737057 /* Boolean value. */
37068- if (val > 1) {
37069- ret = BAD_FUNC_ARG;
37070- }
37071- else {
37072- opts->show_header_data = val;
37073- }
37058+ opts->show_header_data = (val > 0);
3707437059 break;
3707537060 /* Show the wolfSSL OID value for OBJECT_ID. */
3707637061 case ASN1_PRINT_OPT_SHOW_OID:
3707737062 /* Boolean value. */
37078- if (val > 1) {
37079- ret = BAD_FUNC_ARG;
37080- }
37081- else {
37082- opts->show_oid = val;
37083- }
37063+ opts->show_oid = (val > 0);
3708437064 break;
3708537065 /* Don't show text representations of primitive types. */
3708637066 case ASN1_PRINT_OPT_SHOW_NO_TEXT:
3708737067 /* Boolean value. */
37088- if (val > 1) {
37089- ret = BAD_FUNC_ARG;
37090- }
37091- else {
37092- opts->show_no_text = val;
37093- }
37068+ opts->show_no_text = (val > 0);
3709437069 break;
3709537070 /* Don't show dump text representations of primitive types. */
3709637071 case ASN1_PRINT_OPT_SHOW_NO_DUMP_TEXT:
3709737072 /* Boolean value. */
37098- if (val > 1) {
37099- ret = BAD_FUNC_ARG;
37100- }
37101- else {
37102- opts->show_no_dump_text = val;
37103- }
37073+ opts->show_no_dump_text = (val > 0);
3710437074 break;
3710537075 }
3710637076 }
@@ -37251,7 +37221,7 @@ static void PrintObjectIdText(Asn1* asn1, Asn1PrintOptions* opts)
3725137221{
3725237222 word32 oid = (word32)-1;
3725337223#if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
37254- word32 nid;
37224+ int nid;
3725537225#endif
3725637226 const char* ln = NULL;
3725737227 word32 i = 0;
@@ -37262,7 +37232,7 @@ static void PrintObjectIdText(Asn1* asn1, Asn1PrintOptions* opts)
3726237232 asn1->item.len + 2);
3726337233#if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
3726437234 /* Lookup NID for OID value. */
37265- if ((nid = oid2nid(oid, oidIgnoreType)) != (word32) -1) {
37235+ if ((nid = oid2nid(oid, oidIgnoreType)) != -1) {
3726637236 /* Lookup long name for NID. */
3726737237 ln = wolfSSL_OBJ_nid2ln(nid);
3726837238 }
@@ -37546,9 +37516,9 @@ static void DrawBranch(Asn1* asn1)
3754637516 * @param [in] data Data to print.
3754737517 * @param [in] len Number of bytes to print.
3754837518 */
37549- static void PrintHexBytes(XFILE file, unsigned char* data, int len)
37519+ static void PrintHexBytes(XFILE file, unsigned char* data, word32 len)
3755037520{
37551- int i;
37521+ word32 i;
3755237522
3755337523 for (i = 0; i < len; i++) {
3755437524 XFPRINTF(file, " %02x", data[i]);
@@ -37564,15 +37534,18 @@ static void DumpHeader(Asn1* asn1, Asn1PrintOptions* opts)
3756437534{
3756537535 /* Put on same line when not showing data too and not showing text data. */
3756637536 if ((!opts->show_data) && opts->show_no_text) {
37567- XFPRINTF(asn1->file, "%10s %02x ", "", asn1->item.tag );
37537+ XFPRINTF(asn1->file, "%10s", "");
3756837538 }
3756937539 else {
3757037540 /* Align with start of data. */
37571- XFPRINTF(asn1->file, "\n%12s %02x", "", asn1->item.tag);
37541+ XFPRINTF(asn1->file, "\n%12s", "");
37542+ }
37543+ XFPRINTF(asn1->file, " %02x", asn1->item.tag);
37544+ if (asn1->curr >= asn1->offset + 1) {
37545+ /* Print the header bytes as hex bytes separated by a space. */
37546+ PrintHexBytes(asn1->file, asn1->data + asn1->offset + 1,
37547+ asn1->curr - (asn1->offset + 1));
3757237548 }
37573- /* Print the header bytes as hex bytes separated by a space. */
37574- PrintHexBytes(asn1->file, asn1->data + asn1->offset + 1,
37575- asn1->curr - (asn1->offset + 1));
3757637549}
3757737550
3757837551/* Print ASN.1 item info based on header and indeces.
@@ -37628,16 +37601,12 @@ static int wc_Asn1_Print(Asn1* asn1, Asn1PrintOptions* opts)
3762837601{
3762937602 int ret = 0;
3763037603
37631- if ((asn1 == NULL) || (opts == NULL)) {
37632- ret = BAD_FUNC_ARG;
37633- }
37634-
3763537604 /* Process tag. */
3763637605 if (asn1->part == ASN_PART_TAG) {
3763737606 /* Recalculate which depth we are at. */
3763837607 UpdateDepth(asn1);
3763937608 /* Get tag. */
37640- asn1->item.tag = asn1->data[asn1->curr] & ~ASN_CONSTRUCTED;
37609+ asn1->item.tag = asn1->data[asn1->curr] & (byte) ~ASN_CONSTRUCTED;
3764137610 /* Store whether tag indicates constructed. */
3764237611 asn1->item.cons = (asn1->data[asn1->curr] & ASN_CONSTRUCTED) ==
3764337612 ASN_CONSTRUCTED;
@@ -37660,7 +37629,7 @@ static int wc_Asn1_Print(Asn1* asn1, Asn1PrintOptions* opts)
3766037629 /* Store ASN.1 item data offset. */
3766137630 asn1->item.data_idx = asn1->curr;
3766237631 /* Store ASN.1 item data length. */
37663- asn1->item.len = len;
37632+ asn1->item.len = (word32) len;
3766437633
3766537634 /* Print info about ASN.1 item. */
3766637635 PrintInfo(asn1, opts);
@@ -37721,7 +37690,7 @@ static int wc_Asn1_Print(Asn1* asn1, Asn1PrintOptions* opts)
3772137690 * @param [in] data BER/DER data to print.
3772237691 * @param [in] len Length of data to print in bytes.
3772337692 * @return 0 on success.
37724- * @return BAD_FUNC_ARG when asn1 or opts is NULL.
37693+ * @return BAD_FUNC_ARG when asn1, opts or data is NULL.
3772537694 * @return ASN_LEN_E when ASN.1 item's length too long.
3772637695 * @return ASN_DEPTH_E when end offset invalid.
3772737696 * @return ASN_PARSE_E when not all of an ASN.1 item parsed.
@@ -37731,7 +37700,7 @@ int wc_Asn1_PrintAll(Asn1* asn1, Asn1PrintOptions* opts, unsigned char* data,
3773137700{
3773237701 int ret = 0;
3773337702
37734- if (asn1 == NULL) {
37703+ if (( asn1 == NULL) || (opts == NULL) || (data == NULL) ) {
3773537704 ret = BAD_FUNC_ARG;
3773637705 }
3773737706
0 commit comments