Lines Matching refs:ctx

109 base64_decode_init(base64_decode_ctx_t *ctx, int length, isc_buffer_t *target)
111 ctx->digits = 0;
112 ctx->seen_end = ISC_FALSE;
113 ctx->length = length;
114 ctx->target = target;
118 base64_decode_char(base64_decode_ctx_t *ctx, int c) {
121 if (ctx->seen_end)
125 ctx->val[ctx->digits++] = s - base64;
126 if (ctx->digits == 4) {
129 if (ctx->val[0] == 64 || ctx->val[1] == 64)
131 if (ctx->val[2] == 64 && ctx->val[3] != 64)
136 if (ctx->val[2] == 64 && (ctx->val[1] & 0xf) != 0)
139 * We don't need to test for ctx->val[2] != 64 as
142 if (ctx->val[3] == 64 && (ctx->val[2] & 0x3) != 0)
144 n = (ctx->val[2] == 64) ? 1 :
145 (ctx->val[3] == 64) ? 2 : 3;
147 ctx->seen_end = ISC_TRUE;
148 if (ctx->val[2] == 64)
149 ctx->val[2] = 0;
150 if (ctx->val[3] == 64)
151 ctx->val[3] = 0;
153 buf[0] = (ctx->val[0]<<2)|(ctx->val[1]>>4);
154 buf[1] = (ctx->val[1]<<4)|(ctx->val[2]>>2);
155 buf[2] = (ctx->val[2]<<6)|(ctx->val[3]);
156 RETERR(mem_tobuffer(ctx->target, buf, n));
157 if (ctx->length >= 0) {
158 if (n > ctx->length)
161 ctx->length -= n;
163 ctx->digits = 0;
169 base64_decode_finish(base64_decode_ctx_t *ctx) {
170 if (ctx->length > 0)
172 if (ctx->digits != 0)
179 base64_decode_ctx_t ctx;
184 base64_decode_init(&ctx, length, target);
186 while (!ctx.seen_end && (ctx.length != 0)) {
199 RETERR(base64_decode_char(&ctx, tr->base[i]));
201 if (ctx.length < 0 && !ctx.seen_end)
203 RETERR(base64_decode_finish(&ctx));
209 base64_decode_ctx_t ctx;
211 base64_decode_init(&ctx, -1, target);
218 RETERR(base64_decode_char(&ctx, c));
220 RETERR(base64_decode_finish(&ctx));