On Mon, Feb 11, 2013 at 5:15 PM, Dave Thompson <dthomp...@prinpay.com> wrote: >> From: owner-openssl-us...@openssl.org On Behalf Of Jeffrey Walton >> Sent: Monday, 11 February, 2013 01:12 > >> I'm trying to memory map a file. Does OpenSSL BIO's allow this? >> >> I seem to be failing on BIO_read_filename with a `ret` of 0. The docs >> state I should expect `ret` of 1. When I look for the problem, I'm >> getting an error code of 0 (`err`, success). >> > (BIO_read_filename = BIO_ctrl _SET_FILENAME on a mem-BIO) > That doesn't make sense. OpenSSL doesn't map a file itself; > that isn't portable. I gave up on trying to pipeline the data using a source/sink paradigm.
For what its worth, it does not matter to me how the library internally handles sources/sinks. As a dumb user, I just expect them to work :) > If you *already* have a file mapped into > memory by e.g. mmap in Unix and something different in Windows, > you can create a *readonly* mem-BIO on that memory with > BIO_new_mem_buf. I don't think you can do this for write; > writing to a mem-BIO must be able to re-allocate the underlying > buffer when it thinks necessary, and that can't work for a file > mapped to a fixed area of memory. Thanks. Once I had to turn to C for some of the stuff, I just used C for all of the stuff. The deal breaker was lack of a way to determine a file size when using a file BIO. I could not seek to the end and then do a tell() via BIO_C_GET_FILE_PTR because seek() with {0, SEEK_END} was missing. I even tried sending a BIO_ctrl (BIO_C_SET_FILE_PTR) with {0, SEEK_END} parameters, which resulted in a crash. > BIO_ctrl of an option inapplicable to mem-BIO returns 0 but doesn't > set anything in the error queue. Yes, this isn't too helpful. Gotcha. I'm used to having error information available on failure (GetLastError(), errno, etc). I assumed error information was/is because that's what APIs usually do. Perhaps the docs should state error information on failure is not available. >> I ask because the doc's appear to be incorrect on the return type of >> BIO_read_filename. When I try and use an `int`, I get a size warning >> (long instead of int). So I suspect the docs may be wrong. >> http://www.openssl.org/docs/crypto/BIO_s_file.html. >> > I suspect at some point in the distant past BIO_read_filename was > a separate routine and did return int. When it was combined into > the more general BIO_ctrl/file_ctrl mechanism, that handles many > options some of which need to return long, and the manpage probably > wasn't updated. Gotcha, thanks. I wish I had "Network Security with OpenSSL" with me. It would have saved me a lot of time since I/O is covered in detail. It would have saved you too :) Jeff ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org