- EVP_EncodeUpdate(&(ctx->base64),
- (unsigned char *)ctx->buf,&ctx->buf_len,
- (unsigned char *)in,n);
+
+ if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
+ {
+ if (ctx->tmp_len > 0)
+ {
+ OPENSSL_assert(ctx->tmp_len <= 3);
+ n=3-ctx->tmp_len;
+ /* There's a theoretical possibility for this */
+ if (n > inl)
+ n=inl;
+ memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
+ ctx->tmp_len+=n;
+ ret += n;
+ if (ctx->tmp_len < 3)
+ break;
+ ctx->buf_len=EVP_EncodeBlock((unsigned char *)ctx->buf,(unsigned char *)ctx->tmp,ctx->tmp_len);
+ OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf));
+ OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
+ /* Since we're now done using the temporary
+ buffer, the length should be 0'd */
+ ctx->tmp_len=0;
+ }
+ else
+ {
+ if (n < 3)
+ {
+ memcpy(ctx->tmp,in,n);
+ ctx->tmp_len=n;
+ ret += n;
+ break;
+ }
+ n-=n%3;
+ ctx->buf_len=EVP_EncodeBlock((unsigned char *)ctx->buf,(const unsigned char *)in,n);
+ OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf));
+ OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
+ ret += n;
+ }
+ }
+ else
+ {
+ EVP_EncodeUpdate(&(ctx->base64),
+ (unsigned char *)ctx->buf,&ctx->buf_len,
+ (unsigned char *)in,n);
+ OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf));
+ OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
+ ret += n;
+ }