-/* $OpenBSD: bio.h,v 1.33 2018/02/18 12:59:06 tb Exp $ */
+/* $OpenBSD: bio.h,v 1.34 2018/02/20 17:15:27 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#define BIO_TYPE_FILTER 0x0200
#define BIO_TYPE_SOURCE_SINK 0x0400
+/*
+ * BIO_TYPE_START is the first user-allocated BIO type. No pre-defined type,
+ * flag bits aside, may exceed this value.
+ */
+#define BIO_TYPE_START 128
+
/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
* BIO_set_fp(in,stdin,BIO_NOCLOSE); */
#define BIO_NOCLOSE 0x00
BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
asn1_ps_func **psuffix_free);
+int BIO_get_new_index(void);
BIO_METHOD *BIO_s_file(void );
BIO *BIO_new_file(const char *filename, const char *mode);
BIO *BIO_new_fp(FILE *stream, int close_flag);
-/* $OpenBSD: bio_lib.c,v 1.24 2018/02/18 12:58:25 tb Exp $ */
+/* $OpenBSD: bio_lib.c,v 1.25 2018/02/20 17:15:27 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <openssl/err.h>
#include <openssl/stack.h>
+int
+BIO_get_new_index(void)
+{
+ static int bio_type_index = BIO_TYPE_START;
+ int index;
+
+ /* The index will collide with the BIO flag bits if it exceeds 255. */
+ index = CRYPTO_add(&bio_type_index, 1, CRYPTO_LOCK_BIO);
+ if (index > 255)
+ return -1;
+
+ return index;
+}
+
BIO *
BIO_new(BIO_METHOD *method)
{