mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Improve the Base64 line size for NO_ASN
case. Fix report of unread ret
.
This commit is contained in:
@@ -15573,10 +15573,9 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
|
|||||||
|
|
||||||
/* get curve id */
|
/* get curve id */
|
||||||
if ((ret = CheckCurve(oidSum)) < 0)
|
if ((ret = CheckCurve(oidSum)) < 0)
|
||||||
ret = ECC_CURVE_OID_E;
|
return ECC_CURVE_OID_E;
|
||||||
else {
|
else {
|
||||||
curve_id = ret;
|
curve_id = ret;
|
||||||
ret = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,10 +29,11 @@
|
|||||||
#ifndef NO_CODING
|
#ifndef NO_CODING
|
||||||
|
|
||||||
#include <wolfssl/wolfcrypt/coding.h>
|
#include <wolfssl/wolfcrypt/coding.h>
|
||||||
#include <wolfssl/wolfcrypt/asn.h> /* For PEM_LINE_SZ */
|
|
||||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
#include <wolfssl/wolfcrypt/logging.h>
|
#include <wolfssl/wolfcrypt/logging.h>
|
||||||
|
#ifndef NO_ASN
|
||||||
|
#include <wolfssl/wolfcrypt/asn.h> /* For PEM_LINE_SZ */
|
||||||
|
#endif
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
BAD = 0xFF, /* invalid encoding */
|
BAD = 0xFF, /* invalid encoding */
|
||||||
@@ -42,6 +43,14 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BASE64_LINE_SZ
|
||||||
|
#ifdef NO_ASN
|
||||||
|
#define BASE64_LINE_SZ 64
|
||||||
|
#else
|
||||||
|
#define BASE64_LINE_SZ PEM_LINE_SZ
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_BASE64_DECODE
|
#ifdef WOLFSSL_BASE64_DECODE
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -91,7 +100,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
|
|||||||
{
|
{
|
||||||
word32 i = 0;
|
word32 i = 0;
|
||||||
word32 j = 0;
|
word32 j = 0;
|
||||||
word32 plainSz = inLen - ((inLen + (PEM_LINE_SZ - 1)) / PEM_LINE_SZ );
|
word32 plainSz = inLen - ((inLen + (BASE64_LINE_SZ - 1)) / BASE64_LINE_SZ );
|
||||||
int ret;
|
int ret;
|
||||||
const byte maxIdx = (byte)sizeof(base64Decode) + BASE64_MIN - 1;
|
const byte maxIdx = (byte)sizeof(base64Decode) + BASE64_MIN - 1;
|
||||||
|
|
||||||
@@ -291,7 +300,7 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out,
|
|||||||
int getSzOnly = (out == NULL);
|
int getSzOnly = (out == NULL);
|
||||||
|
|
||||||
word32 outSz = (inLen + 3 - 1) / 3 * 4;
|
word32 outSz = (inLen + 3 - 1) / 3 * 4;
|
||||||
word32 addSz = (outSz + PEM_LINE_SZ - 1) / PEM_LINE_SZ; /* new lines */
|
word32 addSz = (outSz + BASE64_LINE_SZ - 1) / BASE64_LINE_SZ; /* new lines */
|
||||||
|
|
||||||
if (escaped == WC_ESC_NL_ENC)
|
if (escaped == WC_ESC_NL_ENC)
|
||||||
addSz *= 3; /* instead of just \n, we're doing %0A triplet */
|
addSz *= 3; /* instead of just \n, we're doing %0A triplet */
|
||||||
@@ -328,8 +337,8 @@ static int DoBase64_Encode(const byte* in, word32 inLen, byte* out,
|
|||||||
|
|
||||||
inLen -= 3;
|
inLen -= 3;
|
||||||
|
|
||||||
/* Insert newline after PEM_LINE_SZ, unless no \n requested */
|
/* Insert newline after BASE64_LINE_SZ, unless no \n requested */
|
||||||
if (escaped != WC_NO_NL_ENC && (++n % (PEM_LINE_SZ/4)) == 0 && inLen) {
|
if (escaped != WC_NO_NL_ENC && (++n % (BASE64_LINE_SZ/4)) == 0 && inLen) {
|
||||||
ret = CEscape(escaped, '\n', out, &i, *outLen, 1, getSzOnly);
|
ret = CEscape(escaped, '\n', out, &i, *outLen, 1, getSzOnly);
|
||||||
if (ret != 0) break;
|
if (ret != 0) break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user