X-Git-Url: https://bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=src%2Fcodec%2Fpemdec.t0;h=2237abbfe00bffdc8e6f0682a16ba8b14e649fac;hp=7a0798c5683daa36e6e3d221372aaeec676c5cc4;hb=ffe3c9166b35cdb220cc0ecc1614afb8451ae420;hpb=3210f38e0491b39aec1ef419cb4114e9483089fb;ds=sidebyside diff --git a/src/codec/pemdec.t0 b/src/codec/pemdec.t0 index 7a0798c..2237abb 100644 --- a/src/codec/pemdec.t0 +++ b/src/codec/pemdec.t0 @@ -24,7 +24,7 @@ preamble { #include "inner.h" -#define CTX ((br_pem_decoder_context *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) +#define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) /* see bearssl_pem.h */ void @@ -144,7 +144,8 @@ cc: read8-native ( -- x ) { begin over ifnot 2drop skip-newline 0 ret then read8 dup `\n = if 2drop orig-len swap - ret then - norm-upper over set8 1+ swap 1- swap + dup `\r = if drop else norm-upper over set8 then + 1+ swap 1- swap again ; \ Remove trailing dashes from the name buffer. @@ -169,13 +170,21 @@ cc: read8-native ( -- x ) { \ Convert a Base64 character to its numerical value. Returned value is \ 0 to 63 for Base64 characters, -1 for '=', and -2 for all other characters. -: from-base64 ( char -- x ) - dup dup `A >= swap `Z <= and if 65 - ret then - dup dup `a >= swap `z <= and if 71 - ret then - dup dup `0 >= swap `9 <= and if 4 + ret then - dup `+ = if drop 62 ret then - dup `/ = if drop 63 ret then - `= <> 1- ; +cc: from-base64 ( char -- x ) { + uint32_t c = T0_POP(); + uint32_t p, q, r, z; + p = c - 0x41; + q = c - 0x61; + r = c - 0x30; + + z = ((p + 2) & -LT(p, 26)) + | ((q + 28) & -LT(q, 26)) + | ((r + 54) & -LT(r, 10)) + | (64 & -EQ(c, 0x2B)) + | (65 & -EQ(c, 0x2F)) + | EQ(c, 0x3D); + T0_PUSHi((int32_t)z - 2); +} \ Test whether a character is whitespace (but not a newline). : ws? ( x -- bool ) @@ -203,7 +212,9 @@ cc: write8 ( x -- ) { \ Flush the output buffer. cc: flush-buf ( -- ) { if (CTX->ptr > 0) { - CTX->dest(CTX->dest_ctx, CTX->buf, CTX->ptr); + if (CTX->dest) { + CTX->dest(CTX->dest_ctx, CTX->buf, CTX->ptr); + } CTX->ptr = 0; } }