Lines Matching defs:ctx
126 base32_decode_init(base32_decode_ctx_t *ctx, int length, const char base[],
129 ctx->digits = 0;
130 ctx->seen_end = 0;
131 ctx->seen_32 = 0;
132 ctx->length = length;
133 ctx->target = target;
134 ctx->base = base;
135 ctx->pad = pad;
139 base32_decode_char(base32_decode_ctx_t *ctx, int c) {
143 if (ctx->seen_end)
145 if ((s = strchr(ctx->base, c)) == NULL)
147 last = (unsigned int)(s - ctx->base);
158 if (last != 32 && ctx->seen_32 != 0)
164 if (last == 32 && !ctx->pad)
172 if (last == 32 && ctx->seen_32 == 0)
173 switch (ctx->digits) {
178 if ((ctx->val[1]&0x03) != 0)
180 ctx->seen_32 = 1;
185 if ((ctx->val[3]&0x0f) != 0)
187 ctx->seen_32 = 3;
190 if ((ctx->val[4]&0x01) != 0)
192 ctx->seen_32 = 3;
197 if ((ctx->val[6]&0x07) != 0)
199 ctx->seen_32 = 4;
206 ctx->val[ctx->digits++] = (last == 32) ? 0 : last;
208 if (ctx->digits == 8) {
212 if (ctx->seen_32 != 0) {
213 ctx->seen_end = 1;
214 n = ctx->seen_32;
216 buf[0] = (ctx->val[0]<<3)|(ctx->val[1]>>2);
217 buf[1] = (ctx->val[1]<<6)|(ctx->val[2]<<1)|(ctx->val[3]>>4);
218 buf[2] = (ctx->val[3]<<4)|(ctx->val[4]>>1);
219 buf[3] = (ctx->val[4]<<7)|(ctx->val[5]<<2)|(ctx->val[6]>>3);
220 buf[4] = (ctx->val[6]<<5)|(ctx->val[7]);
221 RETERR(isc_mem_tobuffer(ctx->target, buf, n));
222 if (ctx->length >= 0) {
223 if (n > ctx->length)
226 ctx->length -= n;
228 ctx->digits = 0;
234 base32_decode_finish(base32_decode_ctx_t *ctx) {
236 if (ctx->length > 0)
241 if (!ctx->pad && ctx->digits != 0) {
242 ctx->pad = 1;
244 RETERR(base32_decode_char(ctx, '='));
245 } while (ctx->digits != 0);
247 if (ctx->digits != 0)
256 base32_decode_ctx_t ctx;
258 base32_decode_init(&ctx, -1, base, pad, target);
261 RETERR(base32_decode_char(&ctx, c));
264 RETERR(base32_decode_finish(&ctx));