Bio chain operation
--- Translation according to OpenSSL DOC / CRYPTO / BIO / BIO_PUSH.POD and its own understanding
(Author: DragonKing Mail: wzhah@263.net Posted: http: //gdwzh.126.com of openssl professional forum)
When I introduced the BIO structure, I said that the BIO structure is actually a chain structure. Single BIO is only a special case of a Bio chain, then we construct or add a Bio in a BIO chain, how to get from a BIO chain Delete a Bio, then this section is specifically telling this problem.
In fact, in OpenSSL, the operation of the BIO chain is still very simple, including two functions (openssl / bio.h):
BIO * BIO_PUSH (BIO * B, BIO * APPEND);
BIO * BIO_POP (BIO * B);
[Bio_Push]
This function attached to the BIO named Append in the parameter to BIO named B and returns B. In fact, the OpenSSL author itself recognizes that Bio_Push's function name may cause misunderstanding because the Bio_Push function actually connects two BIOs, not Push's function, should be Join.
Let's take a few simple examples to illustrate the role of Bio_push, assuming that MD1, MD2 is the Bio, BASE64 type BIO, and f is the file type Bio, then
BIO_PUSH (B64, F);
Then form a B64-F chain. Then do the following:
Bio_push (MD2, B64);
Bio_push (MD1, MD2);
Then it will form the Bio chain of MD1-MD2-B64-F. You can see that after a Bio is constructed, the first BIO represents the entire Bio chain, which is almost the same.
At this time, any data to MD1 will pass through the summary of MD1, MD2 (or HUSH operation), and then submitted to file f through Base64. It can be seen that after constructing a good Bio chain, the operation is very convenient, you don't have to care about the specific thing, the entire BIO chain automatically specifies the data of the data.
It should be noted that if it is a read operation, the data will be transmitted and processed in the opposite direction. For the above BIO chain, the data is read from the F file, and then the base64 is decoded, then MD1, MD2 encoding, finally read .
[BIO_POP]
This function removes the Bio named B from a BIO chain and returns the next Bio. If there is no next Bio, then return null. The removed BIO is a single Bio, which is not related to the original Bio chain so you can release it or connect to another Bio. It can be seen that if it is a single Bio, there is no meaning.
If you perform actions:
BIO_POP (MD2);
Then the return value will be b64, and the MD2 is removed from the above chain, forming a new MD1-B64-F Bio chain, and is also written in the data operation, but there is no change, but the underlying processing process It has changed, which is the concept of packaging and transparency. It can be seen that although the Bio_POP parameter is just a Bio, the direct consequence of this operation will affect the chain of the BIO, so when the chain of the Bio is different, the result is different. In addition: Bio_Push and Bio_POP operations may also result in other additional results, some related BIOs may call some control operations, which are different from each type of Bio, which will be explained in their respective descriptions.