- return 0;
-
- /* Try to get the current position */
- loc = BIO_tell(new_bio);
-
- if ((buff = BIO_new(BIO_f_buffer())) == NULL
- || (new_bio_tmp = BIO_push(buff, new_bio)) == NULL)
- goto err;
-
- /* Assumption, if we can't detect PEM */
- input_type = INPUT_TYPE_DER;
- flag_buffered = 1;
- new_bio = new_bio_tmp;
-
- if (BIO_buffer_peek(new_bio, peekbuf, sizeof(peekbuf) - 1) > 0) {
-#ifndef OPENSSL_NO_DSA
- const unsigned char *p = NULL;
- unsigned int magic = 0, bitlen = 0;
- int isdss = 0, ispub = -1;
-# ifndef OPENSSL_NO_RC4
- unsigned int saltlen = 0, keylen = 0;
-# endif
-#endif
-
- peekbuf[sizeof(peekbuf) - 1] = '\0';
- if (strstr(peekbuf, "-----BEGIN ") != NULL)
- input_type = INPUT_TYPE_PEM;
-#ifndef OPENSSL_NO_DSA
- else if (p = (unsigned char *)peekbuf,
- ossl_do_blob_header(&p, sizeof(peekbuf), &magic, &bitlen,
- &isdss, &ispub))
- input_type = INPUT_TYPE_MSBLOB;
-# ifndef OPENSSL_NO_RC4
- else if (p = (unsigned char *)peekbuf,
- ossl_do_PVK_header(&p, sizeof(peekbuf), 0, &saltlen, &keylen))
- input_type = INPUT_TYPE_PVK;
-# endif
-#endif
- }
-
- /*
- * After peeking, we know that the underlying source BIO has moved ahead
- * from its earlier position and that if it supports BIO_tell(), that
- * should be a number that differs from |loc|. Otherwise, we will get
- * the same value, which may one of:
- *
- * - zero (the source BIO doesn't support BIO_tell() / BIO_seek() /
- * BIO_reset())
- * - -1 (the underlying operating system / C library routines do not
- * support BIO_tell() / BIO_seek() / BIO_reset())
- *
- * If it turns out that the source BIO does support BIO_tell(), we pop
- * the buffer BIO filter and mark this input as |INPUT_TYPE_ANY|, which
- * fully unleashes OSSL_DECODER to do its thing.
- */
- if (BIO_tell(new_bio) != loc) {
- /* In this case, anything goes */
- input_type = INPUT_TYPE_ANY;
-
- /* Restore the source BIO like it was when entering this function */
- new_bio = BIO_pop(buff);
- BIO_free(buff);
- (void)BIO_seek(new_bio, loc);
-
- flag_buffered = 0;
- }
-
- if ((ctx = file_open_stream(new_bio, NULL, input_type, provctx)) == NULL)
- goto err;
-
- ctx->flag_attached = flag_attached;
- ctx->flag_buffered = flag_buffered;