Lines Matching refs:ctx
122 static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size);
123 static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
125 static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
152 BIO_ASN1_BUF_CTX *ctx; in asn1_bio_new() local
153 ctx = OPENSSL_malloc(sizeof(BIO_ASN1_BUF_CTX)); in asn1_bio_new()
154 if (!ctx) in asn1_bio_new()
156 if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) in asn1_bio_new()
159 b->ptr = (char *)ctx; in asn1_bio_new()
164 static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) in asn1_bio_init() argument
166 ctx->buf = OPENSSL_malloc(size); in asn1_bio_init()
167 if (!ctx->buf) in asn1_bio_init()
169 ctx->bufsize = size; in asn1_bio_init()
170 ctx->bufpos = 0; in asn1_bio_init()
171 ctx->buflen = 0; in asn1_bio_init()
172 ctx->copylen = 0; in asn1_bio_init()
173 ctx->asn1_class = V_ASN1_UNIVERSAL; in asn1_bio_init()
174 ctx->asn1_tag = V_ASN1_OCTET_STRING; in asn1_bio_init()
175 ctx->ex_buf = 0; in asn1_bio_init()
176 ctx->ex_pos = 0; in asn1_bio_init()
177 ctx->ex_len = 0; in asn1_bio_init()
178 ctx->state = ASN1_STATE_START; in asn1_bio_init()
184 BIO_ASN1_BUF_CTX *ctx; in asn1_bio_free() local
185 ctx = (BIO_ASN1_BUF_CTX *) b->ptr; in asn1_bio_free()
186 if (ctx == NULL) in asn1_bio_free()
188 if (ctx->buf) in asn1_bio_free()
189 OPENSSL_free(ctx->buf); in asn1_bio_free()
190 OPENSSL_free(ctx); in asn1_bio_free()
199 BIO_ASN1_BUF_CTX *ctx; in asn1_bio_write() local
204 ctx = (BIO_ASN1_BUF_CTX *) b->ptr; in asn1_bio_write()
205 if (ctx == NULL) in asn1_bio_write()
213 switch (ctx->state) in asn1_bio_write()
218 if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, in asn1_bio_write()
226 ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, in asn1_bio_write()
235 ctx->buflen = in asn1_bio_write()
236 ASN1_object_size(0, inl, ctx->asn1_tag) - inl; in asn1_bio_write()
237 OPENSSL_assert(ctx->buflen <= ctx->bufsize); in asn1_bio_write()
238 p = ctx->buf; in asn1_bio_write()
240 ctx->asn1_tag, ctx->asn1_class); in asn1_bio_write()
241 ctx->copylen = inl; in asn1_bio_write()
242 ctx->state = ASN1_STATE_HEADER_COPY; in asn1_bio_write()
248 ctx->buf + ctx->bufpos, ctx->buflen); in asn1_bio_write()
252 ctx->buflen -= ret; in asn1_bio_write()
253 if (ctx->buflen) in asn1_bio_write()
254 ctx->bufpos += ret; in asn1_bio_write()
257 ctx->bufpos = 0; in asn1_bio_write()
258 ctx->state = ASN1_STATE_DATA_COPY; in asn1_bio_write()
265 if (inl > ctx->copylen) in asn1_bio_write()
266 wrmax = ctx->copylen; in asn1_bio_write()
273 ctx->copylen -= ret; in asn1_bio_write()
277 if (ctx->copylen == 0) in asn1_bio_write()
278 ctx->state = ASN1_STATE_HEADER; in asn1_bio_write()
301 static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, in asn1_bio_flush_ex() argument
305 if (ctx->ex_len <= 0) in asn1_bio_flush_ex()
309 ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, in asn1_bio_flush_ex()
310 ctx->ex_len); in asn1_bio_flush_ex()
313 ctx->ex_len -= ret; in asn1_bio_flush_ex()
314 if (ctx->ex_len > 0) in asn1_bio_flush_ex()
315 ctx->ex_pos += ret; in asn1_bio_flush_ex()
319 cleanup(b, &ctx->ex_buf, &ctx->ex_len, in asn1_bio_flush_ex()
320 &ctx->ex_arg); in asn1_bio_flush_ex()
321 ctx->state = next; in asn1_bio_flush_ex()
322 ctx->ex_pos = 0; in asn1_bio_flush_ex()
329 static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, in asn1_bio_setup_ex() argument
334 if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) in asn1_bio_setup_ex()
339 if (ctx->ex_len > 0) in asn1_bio_setup_ex()
340 ctx->state = ex_state; in asn1_bio_setup_ex()
342 ctx->state = other_state; in asn1_bio_setup_ex()
373 BIO_ASN1_BUF_CTX *ctx; in asn1_bio_ctrl() local
376 ctx = (BIO_ASN1_BUF_CTX *) b->ptr; in asn1_bio_ctrl()
377 if (ctx == NULL) in asn1_bio_ctrl()
384 ctx->prefix = ex_func->ex_func; in asn1_bio_ctrl()
385 ctx->prefix_free = ex_func->ex_free_func; in asn1_bio_ctrl()
390 ex_func->ex_func = ctx->prefix; in asn1_bio_ctrl()
391 ex_func->ex_free_func = ctx->prefix_free; in asn1_bio_ctrl()
396 ctx->suffix = ex_func->ex_func; in asn1_bio_ctrl()
397 ctx->suffix_free = ex_func->ex_free_func; in asn1_bio_ctrl()
402 ex_func->ex_func = ctx->suffix; in asn1_bio_ctrl()
403 ex_func->ex_free_func = ctx->suffix_free; in asn1_bio_ctrl()
407 ctx->ex_arg = arg2; in asn1_bio_ctrl()
411 *(void **)arg2 = ctx->ex_arg; in asn1_bio_ctrl()
419 if (ctx->state == ASN1_STATE_HEADER) in asn1_bio_ctrl()
421 if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, in asn1_bio_ctrl()
426 if (ctx->state == ASN1_STATE_POST_COPY) in asn1_bio_ctrl()
428 ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, in asn1_bio_ctrl()
434 if (ctx->state == ASN1_STATE_DONE) in asn1_bio_ctrl()