Bio chain positioning operation
--- Translation according to OpenSSL DOC / CRYPTO / BIO / BIO_FIND_TYPE.POD and its own understanding
(Author: DragonKing Mail: wzhah@263.net Posted: http: //gdwzh.126.com of openssl professional forum)
One of the previous articles have spent the construction method of the Bio chain. It is here to find a specific Bio in a BIO chain. How to traverse every Bio in the BIO chain, this group function is defined as follows (OpenSSL / BIO. h):
BIO * BIO_FIND_TYPE (BIO * B, INT BIO_TYPE);
BIO * BIO_NEXT (BIO * B);
#define bio_method_type (b) ((b) -> Method-> Type)
It can be seen that there are two functions in this group function, the other is a macro definition, where the value of Bio_Type is as follows:
#define bio_type_none 0
#define bio_type_mem (1 | 0x0400)
#define bio_type_file (2 | 0x0400)
#define bio_type_fd (4 | 0x0400 | 0x0100)
#define bio_type_socket (5 | 0x0400 | 0x0100)
#define bio_type_null (6 | 0x0400)
#define bio_type_ssl (7 | 0x0200)
#define bio_type_md (8 | 0x0200)
#define bio_type_buffer (9 | 0x0200)
#define bio_type_cipher (10 | 0x0200)
#define bio_type_base64 (11 | 0x0200)
#define bio_type_connect (12 | 0x0400 | 0x0100)
#define bio_type_accept (13 | 0x0400 | 0x0100)
#define bio_type_proxy_client (14 | 0x0200)
#define bio_type_proxy_server (15 | 0x0200)
#define bio_type_nbio_test (16 | 0x0200)
#define bio_type_null_filter (17 | 0x0200)
#define bio_type_ber (18 | 0x0200)
#define bio_type_bio (19 | 0x0400)
#define bio_type_descriptor 0x0100
#define bio_type_filter 0x0200
#define bio_type_source_sink 0x0400
It can be seen that most of these definitions are named according to various BIO types, but not with the existing BIO type, in the later article, I will introduce these BIO types one by one. Now everyone can have a concept.
[BIO_FIND_TYPE]
This function searches in a given BIO type Bio_Type in a given BIO chain, and the starting position of the search is B. If a given type is a specific implementation type, you will search for a type of Bio; if it is just a general type definition, such as Bio_Type_Source_sink (is the Source / Sink type Bio), then this type is the first The found BIO is eligible. After finding the conformable BIO, Bio_Find_Type returns to the Bio, otherwise returns NULL. It should be noted that if you use the 0.9.5a version of the 0.9.5A, if you assign a value to NULL to the input parameter B, it may cause an exception error! [BIO_NEXT]
The function is the name suggests that it returns the next Bio in the BIO chain where the current Bio is located, so it can be used to traverse the entire BIO chain, and can be combined with the BIO_FIND_TYPE function and find all specific types of BIO in the entire BIO chain. This function is new in version 0.9.6. Former version to use this feature, you can only use Bio-> Next_BIO to locate.
[BIO_METHOD_TYPE]
This function returns the type of a given BIO.
Here is an example of finding all Digest type BIO in a BIO chain:
BIO * BTMP;
BTMP = in_bio; / * in_bio is the BIO chain of the searched * /
Do {
BTMP = BIO_FIND_TYPE (BTMP, BIO_TYPE_MD);
IF (btmp == null) Break; / * If not found * /
/ * BTMP is a Digest type Bio, doing some processing you need ... * /
...
BTMP = BIO_NEXT (BTMP);
WHILE (BTMP);
As soon as, I have already finished the basic knowledge of BIO. The following article will begin to introduce every specific BIO type. I want to have the front of these layings and knowledge, and it will be more relaxed behind. Please continue to pay attention to the OpenSSL professional forum of http://gdwzh.126.com!