Lines Matching defs:ctx
99 base64_decode_init(base64_decode_ctx_t *ctx, int length, isc_buffer_t *target)
101 ctx->digits = 0;
102 ctx->seen_end = 0;
103 ctx->length = length;
104 ctx->target = target;
108 base64_decode_char(base64_decode_ctx_t *ctx, int c) {
111 if (ctx->seen_end)
115 ctx->val[ctx->digits++] = (int)(s - base64);
116 if (ctx->digits == 4) {
119 if (ctx->val[0] == 64 || ctx->val[1] == 64)
121 if (ctx->val[2] == 64 && ctx->val[3] != 64)
126 if (ctx->val[2] == 64 && (ctx->val[1] & 0xf) != 0)
129 * We don't need to test for ctx->val[2] != 64 as
132 if (ctx->val[3] == 64 && (ctx->val[2] & 0x3) != 0)
134 n = (ctx->val[2] == 64) ? 1 :
135 (ctx->val[3] == 64) ? 2 : 3;
137 ctx->seen_end = 1;
138 if (ctx->val[2] == 64)
139 ctx->val[2] = 0;
140 if (ctx->val[3] == 64)
141 ctx->val[3] = 0;
143 buf[0] = (ctx->val[0]<<2)|(ctx->val[1]>>4);
144 buf[1] = (ctx->val[1]<<4)|(ctx->val[2]>>2);
145 buf[2] = (ctx->val[2]<<6)|(ctx->val[3]);
146 RETERR(isc_mem_tobuffer(ctx->target, buf, n));
147 if (ctx->length >= 0) {
148 if (n > ctx->length)
151 ctx->length -= n;
153 ctx->digits = 0;
159 base64_decode_finish(base64_decode_ctx_t *ctx) {
160 if (ctx->length > 0)
162 if (ctx->digits != 0)
169 base64_decode_ctx_t ctx;
171 base64_decode_init(&ctx, -1, target);
178 RETERR(base64_decode_char(&ctx, c));
180 RETERR(base64_decode_finish(&ctx));