diff --git a/CHANGES.md b/CHANGES.md index 9a3d86c69c..038a8ae632 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,10 @@ OpenSSL 3.1 ### Changes between 3.0 and 3.1 [xx XXX xxxx] + * Added a new BIO_s_dgram_mem() to read/write datagrams to memory + + *Matt Caswell* + * Add a mac salt length option for the pkcs12 command. *Xinping Chen* diff --git a/doc/man3/BIO_s_mem.pod b/doc/man3/BIO_s_mem.pod index 6b3cc6a2da..95dd91b034 100644 --- a/doc/man3/BIO_s_mem.pod +++ b/doc/man3/BIO_s_mem.pod @@ -2,7 +2,7 @@ =head1 NAME -BIO_s_secmem, +BIO_s_secmem, BIO_s_dgram_mem, BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data, BIO_set_mem_buf, BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO @@ -11,6 +11,7 @@ BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO #include const BIO_METHOD *BIO_s_mem(void); + const BIO_METHOD *BIO_s_dgram_mem(void); const BIO_METHOD *BIO_s_secmem(void); BIO_set_mem_eof_return(BIO *b, int v); @@ -31,6 +32,22 @@ as appropriate to accommodate the stored data. BIO_s_secmem() is like BIO_s_mem() except that the secure heap is used for buffer storage. +BIO_s_dgram_mem() is a memory BIO that respects datagram semantics. A single +call to L will write a single datagram to the memory BIO. A +subsequent call to L will read the data in that datagram. The +L call will never return more data than was written in the original +L call even if there were subsequent L calls that +wrote more datagrams. Each successive call to L will read the next +datagram. If a L call supplies a read buffer that is smaller than +the size of the datagram, then the read buffer will be completely filled and the +remaining data from the datagram will be discarded. + +It is not possible to write a zero length datagram. Calling L in +this case will return 0 and no datagrams will be written. Calling L +when there are no datagrams in the BIO to read will return a negative result and +the "retry" flags will be set (i.e. calling L will return +true). A datagram mem BIO will never return true from L. + Any data written to a memory BIO can be recalled by reading from it. Unless the memory BIO is read only any data read from it is deleted from the BIO. @@ -56,6 +73,7 @@ it will return zero and BIO_should_retry(b) will be false. If B is non zero then it will return B when it is empty and it will set the read retry flag (that is BIO_read_retry(b) is true). To avoid ambiguity with a normal positive return value B should be set to a negative value, typically -1. +Calling this macro will fail for datagram mem BIOs. BIO_get_mem_data() sets *B to a pointer to the start of the memory BIOs data and returns the total amount of data available. It is implemented as a macro. @@ -86,15 +104,15 @@ copy operation, if a BIO contains a lot of data and it is read in small chunks intertwined with writes the operation can be very slow. Adding a buffering BIO to the chain can speed up the process. -Calling BIO_set_mem_buf() on a BIO created with BIO_new_secmem() will -give undefined results, including perhaps a program crash. +Calling BIO_set_mem_buf() on a secmem or dgram BIO will give undefined results, +including perhaps a program crash. -Switching the memory BIO from read write to read only is not supported and +Switching a memory BIO from read write to read only is not supported and can give undefined results including a program crash. There are two notable exceptions to the rule. The first one is to assign a static memory buffer immediately after BIO creation and set the BIO as read only. -The other supported sequence is to start with read write BIO then temporarily +The other supported sequence is to start with a read write BIO then temporarily switch it to read only and call BIO_reset() on the read only BIO immediately before switching it back to read write. Before the BIO is freed it must be switched back to the read write mode. @@ -114,13 +132,10 @@ preceding that write operation cannot be undone. Calling BIO_get_mem_ptr() prior to a BIO_reset() call with BIO_FLAGS_NONCLEAR_RST set has the same effect as a write operation. -=head1 BUGS - -There should be an option to set the maximum size of a memory BIO. - =head1 RETURN VALUES -BIO_s_mem() and BIO_s_secmem() return a valid memory B structure. +BIO_s_mem(), BIO_s_dgram_mem() and BIO_s_secmem() return a valid memory +B structure. BIO_set_mem_eof_return(), BIO_set_mem_buf() and BIO_get_mem_ptr() return 1 on success or a value which is less than or equal to 0 if an error occurred.