1*8fb009dcSAndroid Build Coastguard Worker /* Copyright (C) 1995-1998 Eric Young ([email protected]) 2*8fb009dcSAndroid Build Coastguard Worker * All rights reserved. 3*8fb009dcSAndroid Build Coastguard Worker * 4*8fb009dcSAndroid Build Coastguard Worker * This package is an SSL implementation written 5*8fb009dcSAndroid Build Coastguard Worker * by Eric Young ([email protected]). 6*8fb009dcSAndroid Build Coastguard Worker * The implementation was written so as to conform with Netscapes SSL. 7*8fb009dcSAndroid Build Coastguard Worker * 8*8fb009dcSAndroid Build Coastguard Worker * This library is free for commercial and non-commercial use as long as 9*8fb009dcSAndroid Build Coastguard Worker * the following conditions are aheared to. The following conditions 10*8fb009dcSAndroid Build Coastguard Worker * apply to all code found in this distribution, be it the RC4, RSA, 11*8fb009dcSAndroid Build Coastguard Worker * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12*8fb009dcSAndroid Build Coastguard Worker * included with this distribution is covered by the same copyright terms 13*8fb009dcSAndroid Build Coastguard Worker * except that the holder is Tim Hudson ([email protected]). 14*8fb009dcSAndroid Build Coastguard Worker * 15*8fb009dcSAndroid Build Coastguard Worker * Copyright remains Eric Young's, and as such any Copyright notices in 16*8fb009dcSAndroid Build Coastguard Worker * the code are not to be removed. 17*8fb009dcSAndroid Build Coastguard Worker * If this package is used in a product, Eric Young should be given attribution 18*8fb009dcSAndroid Build Coastguard Worker * as the author of the parts of the library used. 19*8fb009dcSAndroid Build Coastguard Worker * This can be in the form of a textual message at program startup or 20*8fb009dcSAndroid Build Coastguard Worker * in documentation (online or textual) provided with the package. 21*8fb009dcSAndroid Build Coastguard Worker * 22*8fb009dcSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 23*8fb009dcSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 24*8fb009dcSAndroid Build Coastguard Worker * are met: 25*8fb009dcSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the copyright 26*8fb009dcSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 27*8fb009dcSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 28*8fb009dcSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 29*8fb009dcSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 30*8fb009dcSAndroid Build Coastguard Worker * 3. All advertising materials mentioning features or use of this software 31*8fb009dcSAndroid Build Coastguard Worker * must display the following acknowledgement: 32*8fb009dcSAndroid Build Coastguard Worker * "This product includes cryptographic software written by 33*8fb009dcSAndroid Build Coastguard Worker * Eric Young ([email protected])" 34*8fb009dcSAndroid Build Coastguard Worker * The word 'cryptographic' can be left out if the rouines from the library 35*8fb009dcSAndroid Build Coastguard Worker * being used are not cryptographic related :-). 36*8fb009dcSAndroid Build Coastguard Worker * 4. If you include any Windows specific code (or a derivative thereof) from 37*8fb009dcSAndroid Build Coastguard Worker * the apps directory (application code) you must include an acknowledgement: 38*8fb009dcSAndroid Build Coastguard Worker * "This product includes software written by Tim Hudson ([email protected])" 39*8fb009dcSAndroid Build Coastguard Worker * 40*8fb009dcSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41*8fb009dcSAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42*8fb009dcSAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43*8fb009dcSAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44*8fb009dcSAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45*8fb009dcSAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46*8fb009dcSAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47*8fb009dcSAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48*8fb009dcSAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49*8fb009dcSAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50*8fb009dcSAndroid Build Coastguard Worker * SUCH DAMAGE. 51*8fb009dcSAndroid Build Coastguard Worker * 52*8fb009dcSAndroid Build Coastguard Worker * The licence and distribution terms for any publically available version or 53*8fb009dcSAndroid Build Coastguard Worker * derivative of this code cannot be changed. i.e. this code cannot simply be 54*8fb009dcSAndroid Build Coastguard Worker * copied and put under another distribution licence 55*8fb009dcSAndroid Build Coastguard Worker * [including the GNU Public Licence.] */ 56*8fb009dcSAndroid Build Coastguard Worker 57*8fb009dcSAndroid Build Coastguard Worker #ifndef OPENSSL_HEADER_BIO_H 58*8fb009dcSAndroid Build Coastguard Worker #define OPENSSL_HEADER_BIO_H 59*8fb009dcSAndroid Build Coastguard Worker 60*8fb009dcSAndroid Build Coastguard Worker #include <openssl/base.h> 61*8fb009dcSAndroid Build Coastguard Worker 62*8fb009dcSAndroid Build Coastguard Worker #include <stdio.h> // For FILE 63*8fb009dcSAndroid Build Coastguard Worker 64*8fb009dcSAndroid Build Coastguard Worker #include <openssl/buffer.h> 65*8fb009dcSAndroid Build Coastguard Worker #include <openssl/err.h> // for ERR_print_errors_fp 66*8fb009dcSAndroid Build Coastguard Worker #include <openssl/ex_data.h> 67*8fb009dcSAndroid Build Coastguard Worker #include <openssl/stack.h> 68*8fb009dcSAndroid Build Coastguard Worker #include <openssl/thread.h> 69*8fb009dcSAndroid Build Coastguard Worker 70*8fb009dcSAndroid Build Coastguard Worker #if defined(__cplusplus) 71*8fb009dcSAndroid Build Coastguard Worker extern "C" { 72*8fb009dcSAndroid Build Coastguard Worker #endif 73*8fb009dcSAndroid Build Coastguard Worker 74*8fb009dcSAndroid Build Coastguard Worker 75*8fb009dcSAndroid Build Coastguard Worker // BIO abstracts over a file-descriptor like interface. 76*8fb009dcSAndroid Build Coastguard Worker 77*8fb009dcSAndroid Build Coastguard Worker 78*8fb009dcSAndroid Build Coastguard Worker // Allocation and freeing. 79*8fb009dcSAndroid Build Coastguard Worker 80*8fb009dcSAndroid Build Coastguard Worker DEFINE_STACK_OF(BIO) 81*8fb009dcSAndroid Build Coastguard Worker 82*8fb009dcSAndroid Build Coastguard Worker // BIO_new creates a new BIO with the given method and a reference count of one. 83*8fb009dcSAndroid Build Coastguard Worker // It returns the fresh |BIO|, or NULL on error. 84*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new(const BIO_METHOD *method); 85*8fb009dcSAndroid Build Coastguard Worker 86*8fb009dcSAndroid Build Coastguard Worker // BIO_free decrements the reference count of |bio|. If the reference count 87*8fb009dcSAndroid Build Coastguard Worker // drops to zero, it calls the destroy callback, if present, on the method and 88*8fb009dcSAndroid Build Coastguard Worker // frees |bio| itself. It then repeats that for the next BIO in the chain, if 89*8fb009dcSAndroid Build Coastguard Worker // any. 90*8fb009dcSAndroid Build Coastguard Worker // 91*8fb009dcSAndroid Build Coastguard Worker // It returns one on success or zero otherwise. 92*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_free(BIO *bio); 93*8fb009dcSAndroid Build Coastguard Worker 94*8fb009dcSAndroid Build Coastguard Worker // BIO_vfree performs the same actions as |BIO_free|, but has a void return 95*8fb009dcSAndroid Build Coastguard Worker // value. This is provided for API-compat. 96*8fb009dcSAndroid Build Coastguard Worker // 97*8fb009dcSAndroid Build Coastguard Worker // TODO(fork): remove. 98*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_vfree(BIO *bio); 99*8fb009dcSAndroid Build Coastguard Worker 100*8fb009dcSAndroid Build Coastguard Worker // BIO_up_ref increments the reference count of |bio| and returns one. 101*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_up_ref(BIO *bio); 102*8fb009dcSAndroid Build Coastguard Worker 103*8fb009dcSAndroid Build Coastguard Worker 104*8fb009dcSAndroid Build Coastguard Worker // Basic I/O. 105*8fb009dcSAndroid Build Coastguard Worker 106*8fb009dcSAndroid Build Coastguard Worker // BIO_read attempts to read |len| bytes into |data|. It returns the number of 107*8fb009dcSAndroid Build Coastguard Worker // bytes read, zero on EOF, or a negative number on error. 108*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_read(BIO *bio, void *data, int len); 109*8fb009dcSAndroid Build Coastguard Worker 110*8fb009dcSAndroid Build Coastguard Worker // BIO_gets reads a line from |bio| and writes at most |size| bytes into |buf|. 111*8fb009dcSAndroid Build Coastguard Worker // It returns the number of bytes read or a negative number on error. This 112*8fb009dcSAndroid Build Coastguard Worker // function's output always includes a trailing NUL byte, so it will read at 113*8fb009dcSAndroid Build Coastguard Worker // most |size - 1| bytes. 114*8fb009dcSAndroid Build Coastguard Worker // 115*8fb009dcSAndroid Build Coastguard Worker // If the function read a complete line, the output will include the newline 116*8fb009dcSAndroid Build Coastguard Worker // character, '\n'. If no newline was found before |size - 1| bytes or EOF, it 117*8fb009dcSAndroid Build Coastguard Worker // outputs the bytes which were available. 118*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_gets(BIO *bio, char *buf, int size); 119*8fb009dcSAndroid Build Coastguard Worker 120*8fb009dcSAndroid Build Coastguard Worker // BIO_write writes |len| bytes from |data| to |bio|. It returns the number of 121*8fb009dcSAndroid Build Coastguard Worker // bytes written or a negative number on error. 122*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_write(BIO *bio, const void *data, int len); 123*8fb009dcSAndroid Build Coastguard Worker 124*8fb009dcSAndroid Build Coastguard Worker // BIO_write_all writes |len| bytes from |data| to |bio|, looping as necessary. 125*8fb009dcSAndroid Build Coastguard Worker // It returns one if all bytes were successfully written and zero on error. 126*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_write_all(BIO *bio, const void *data, size_t len); 127*8fb009dcSAndroid Build Coastguard Worker 128*8fb009dcSAndroid Build Coastguard Worker // BIO_puts writes a NUL terminated string from |buf| to |bio|. It returns the 129*8fb009dcSAndroid Build Coastguard Worker // number of bytes written or a negative number on error. 130*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_puts(BIO *bio, const char *buf); 131*8fb009dcSAndroid Build Coastguard Worker 132*8fb009dcSAndroid Build Coastguard Worker // BIO_flush flushes any buffered output. It returns one on success and zero 133*8fb009dcSAndroid Build Coastguard Worker // otherwise. 134*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_flush(BIO *bio); 135*8fb009dcSAndroid Build Coastguard Worker 136*8fb009dcSAndroid Build Coastguard Worker 137*8fb009dcSAndroid Build Coastguard Worker // Low-level control functions. 138*8fb009dcSAndroid Build Coastguard Worker // 139*8fb009dcSAndroid Build Coastguard Worker // These are generic functions for sending control requests to a BIO. In 140*8fb009dcSAndroid Build Coastguard Worker // general one should use the wrapper functions like |BIO_get_close|. 141*8fb009dcSAndroid Build Coastguard Worker 142*8fb009dcSAndroid Build Coastguard Worker // BIO_ctrl sends the control request |cmd| to |bio|. The |cmd| argument should 143*8fb009dcSAndroid Build Coastguard Worker // be one of the |BIO_C_*| values. 144*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg); 145*8fb009dcSAndroid Build Coastguard Worker 146*8fb009dcSAndroid Build Coastguard Worker // BIO_ptr_ctrl acts like |BIO_ctrl| but passes the address of a |void*| 147*8fb009dcSAndroid Build Coastguard Worker // pointer as |parg| and returns the value that is written to it, or NULL if 148*8fb009dcSAndroid Build Coastguard Worker // the control request returns <= 0. 149*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT char *BIO_ptr_ctrl(BIO *bp, int cmd, long larg); 150*8fb009dcSAndroid Build Coastguard Worker 151*8fb009dcSAndroid Build Coastguard Worker // BIO_int_ctrl acts like |BIO_ctrl| but passes the address of a copy of |iarg| 152*8fb009dcSAndroid Build Coastguard Worker // as |parg|. 153*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); 154*8fb009dcSAndroid Build Coastguard Worker 155*8fb009dcSAndroid Build Coastguard Worker // BIO_reset resets |bio| to its initial state, the precise meaning of which 156*8fb009dcSAndroid Build Coastguard Worker // depends on the concrete type of |bio|. It returns one on success and zero 157*8fb009dcSAndroid Build Coastguard Worker // otherwise. 158*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_reset(BIO *bio); 159*8fb009dcSAndroid Build Coastguard Worker 160*8fb009dcSAndroid Build Coastguard Worker // BIO_eof returns non-zero when |bio| has reached end-of-file. The precise 161*8fb009dcSAndroid Build Coastguard Worker // meaning of which depends on the concrete type of |bio|. Note that in the 162*8fb009dcSAndroid Build Coastguard Worker // case of BIO_pair this always returns non-zero. 163*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_eof(BIO *bio); 164*8fb009dcSAndroid Build Coastguard Worker 165*8fb009dcSAndroid Build Coastguard Worker // BIO_set_flags ORs |flags| with |bio->flags|. 166*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_flags(BIO *bio, int flags); 167*8fb009dcSAndroid Build Coastguard Worker 168*8fb009dcSAndroid Build Coastguard Worker // BIO_test_flags returns |bio->flags| AND |flags|. 169*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_test_flags(const BIO *bio, int flags); 170*8fb009dcSAndroid Build Coastguard Worker 171*8fb009dcSAndroid Build Coastguard Worker // BIO_should_read returns non-zero if |bio| encountered a temporary error 172*8fb009dcSAndroid Build Coastguard Worker // while reading (i.e. EAGAIN), indicating that the caller should retry the 173*8fb009dcSAndroid Build Coastguard Worker // read. 174*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_should_read(const BIO *bio); 175*8fb009dcSAndroid Build Coastguard Worker 176*8fb009dcSAndroid Build Coastguard Worker // BIO_should_write returns non-zero if |bio| encountered a temporary error 177*8fb009dcSAndroid Build Coastguard Worker // while writing (i.e. EAGAIN), indicating that the caller should retry the 178*8fb009dcSAndroid Build Coastguard Worker // write. 179*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_should_write(const BIO *bio); 180*8fb009dcSAndroid Build Coastguard Worker 181*8fb009dcSAndroid Build Coastguard Worker // BIO_should_retry returns non-zero if the reason that caused a failed I/O 182*8fb009dcSAndroid Build Coastguard Worker // operation is temporary and thus the operation should be retried. Otherwise, 183*8fb009dcSAndroid Build Coastguard Worker // it was a permanent error and it returns zero. 184*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_should_retry(const BIO *bio); 185*8fb009dcSAndroid Build Coastguard Worker 186*8fb009dcSAndroid Build Coastguard Worker // BIO_should_io_special returns non-zero if |bio| encountered a temporary 187*8fb009dcSAndroid Build Coastguard Worker // error while performing a special I/O operation, indicating that the caller 188*8fb009dcSAndroid Build Coastguard Worker // should retry. The operation that caused the error is returned by 189*8fb009dcSAndroid Build Coastguard Worker // |BIO_get_retry_reason|. 190*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_should_io_special(const BIO *bio); 191*8fb009dcSAndroid Build Coastguard Worker 192*8fb009dcSAndroid Build Coastguard Worker // BIO_RR_CONNECT indicates that a connect would have blocked 193*8fb009dcSAndroid Build Coastguard Worker #define BIO_RR_CONNECT 0x02 194*8fb009dcSAndroid Build Coastguard Worker 195*8fb009dcSAndroid Build Coastguard Worker // BIO_RR_ACCEPT indicates that an accept would have blocked 196*8fb009dcSAndroid Build Coastguard Worker #define BIO_RR_ACCEPT 0x03 197*8fb009dcSAndroid Build Coastguard Worker 198*8fb009dcSAndroid Build Coastguard Worker // BIO_get_retry_reason returns the special I/O operation that needs to be 199*8fb009dcSAndroid Build Coastguard Worker // retried. The return value is one of the |BIO_RR_*| values. 200*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_retry_reason(const BIO *bio); 201*8fb009dcSAndroid Build Coastguard Worker 202*8fb009dcSAndroid Build Coastguard Worker // BIO_set_retry_reason sets the special I/O operation that needs to be retried 203*8fb009dcSAndroid Build Coastguard Worker // to |reason|, which should be one of the |BIO_RR_*| values. 204*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_retry_reason(BIO *bio, int reason); 205*8fb009dcSAndroid Build Coastguard Worker 206*8fb009dcSAndroid Build Coastguard Worker // BIO_clear_flags ANDs |bio->flags| with the bitwise-complement of |flags|. 207*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_clear_flags(BIO *bio, int flags); 208*8fb009dcSAndroid Build Coastguard Worker 209*8fb009dcSAndroid Build Coastguard Worker // BIO_set_retry_read sets the |BIO_FLAGS_READ| and |BIO_FLAGS_SHOULD_RETRY| 210*8fb009dcSAndroid Build Coastguard Worker // flags on |bio|. 211*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_retry_read(BIO *bio); 212*8fb009dcSAndroid Build Coastguard Worker 213*8fb009dcSAndroid Build Coastguard Worker // BIO_set_retry_write sets the |BIO_FLAGS_WRITE| and |BIO_FLAGS_SHOULD_RETRY| 214*8fb009dcSAndroid Build Coastguard Worker // flags on |bio|. 215*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_retry_write(BIO *bio); 216*8fb009dcSAndroid Build Coastguard Worker 217*8fb009dcSAndroid Build Coastguard Worker // BIO_get_retry_flags gets the |BIO_FLAGS_READ|, |BIO_FLAGS_WRITE|, 218*8fb009dcSAndroid Build Coastguard Worker // |BIO_FLAGS_IO_SPECIAL| and |BIO_FLAGS_SHOULD_RETRY| flags from |bio|. 219*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_retry_flags(BIO *bio); 220*8fb009dcSAndroid Build Coastguard Worker 221*8fb009dcSAndroid Build Coastguard Worker // BIO_clear_retry_flags clears the |BIO_FLAGS_READ|, |BIO_FLAGS_WRITE|, 222*8fb009dcSAndroid Build Coastguard Worker // |BIO_FLAGS_IO_SPECIAL| and |BIO_FLAGS_SHOULD_RETRY| flags from |bio|. 223*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_clear_retry_flags(BIO *bio); 224*8fb009dcSAndroid Build Coastguard Worker 225*8fb009dcSAndroid Build Coastguard Worker // BIO_method_type returns the type of |bio|, which is one of the |BIO_TYPE_*| 226*8fb009dcSAndroid Build Coastguard Worker // values. 227*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_method_type(const BIO *bio); 228*8fb009dcSAndroid Build Coastguard Worker 229*8fb009dcSAndroid Build Coastguard Worker // These are passed to the BIO callback 230*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_FREE 0x01 231*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_READ 0x02 232*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_WRITE 0x03 233*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_PUTS 0x04 234*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_GETS 0x05 235*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_CTRL 0x06 236*8fb009dcSAndroid Build Coastguard Worker 237*8fb009dcSAndroid Build Coastguard Worker // The callback is called before and after the underling operation, 238*8fb009dcSAndroid Build Coastguard Worker // The BIO_CB_RETURN flag indicates if it is after the call 239*8fb009dcSAndroid Build Coastguard Worker #define BIO_CB_RETURN 0x80 240*8fb009dcSAndroid Build Coastguard Worker 241*8fb009dcSAndroid Build Coastguard Worker // bio_info_cb is the type of a callback function that can be called for most 242*8fb009dcSAndroid Build Coastguard Worker // BIO operations. The |event| argument is one of |BIO_CB_*| and can be ORed 243*8fb009dcSAndroid Build Coastguard Worker // with |BIO_CB_RETURN| if the callback is being made after the operation in 244*8fb009dcSAndroid Build Coastguard Worker // question. In that case, |return_value| will contain the return value from 245*8fb009dcSAndroid Build Coastguard Worker // the operation. 246*8fb009dcSAndroid Build Coastguard Worker typedef long (*bio_info_cb)(BIO *bio, int event, const char *parg, int cmd, 247*8fb009dcSAndroid Build Coastguard Worker long larg, long return_value); 248*8fb009dcSAndroid Build Coastguard Worker 249*8fb009dcSAndroid Build Coastguard Worker // BIO_callback_ctrl allows the callback function to be manipulated. The |cmd| 250*8fb009dcSAndroid Build Coastguard Worker // arg will generally be |BIO_CTRL_SET_CALLBACK| but arbitrary command values 251*8fb009dcSAndroid Build Coastguard Worker // can be interpreted by the |BIO|. 252*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp); 253*8fb009dcSAndroid Build Coastguard Worker 254*8fb009dcSAndroid Build Coastguard Worker // BIO_pending returns the number of bytes pending to be read. 255*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t BIO_pending(const BIO *bio); 256*8fb009dcSAndroid Build Coastguard Worker 257*8fb009dcSAndroid Build Coastguard Worker // BIO_ctrl_pending calls |BIO_pending| and exists only for compatibility with 258*8fb009dcSAndroid Build Coastguard Worker // OpenSSL. 259*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t BIO_ctrl_pending(const BIO *bio); 260*8fb009dcSAndroid Build Coastguard Worker 261*8fb009dcSAndroid Build Coastguard Worker // BIO_wpending returns the number of bytes pending to be written. 262*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t BIO_wpending(const BIO *bio); 263*8fb009dcSAndroid Build Coastguard Worker 264*8fb009dcSAndroid Build Coastguard Worker // BIO_set_close sets the close flag for |bio|. The meaning of which depends on 265*8fb009dcSAndroid Build Coastguard Worker // the type of |bio| but, for example, a memory BIO interprets the close flag 266*8fb009dcSAndroid Build Coastguard Worker // as meaning that it owns its buffer. It returns one on success and zero 267*8fb009dcSAndroid Build Coastguard Worker // otherwise. 268*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_close(BIO *bio, int close_flag); 269*8fb009dcSAndroid Build Coastguard Worker 270*8fb009dcSAndroid Build Coastguard Worker // BIO_number_read returns the number of bytes that have been read from 271*8fb009dcSAndroid Build Coastguard Worker // |bio|. 272*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio); 273*8fb009dcSAndroid Build Coastguard Worker 274*8fb009dcSAndroid Build Coastguard Worker // BIO_number_written returns the number of bytes that have been written to 275*8fb009dcSAndroid Build Coastguard Worker // |bio|. 276*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio); 277*8fb009dcSAndroid Build Coastguard Worker 278*8fb009dcSAndroid Build Coastguard Worker 279*8fb009dcSAndroid Build Coastguard Worker // Managing chains of BIOs. 280*8fb009dcSAndroid Build Coastguard Worker // 281*8fb009dcSAndroid Build Coastguard Worker // BIOs can be put into chains where the output of one is used as the input of 282*8fb009dcSAndroid Build Coastguard Worker // the next etc. The most common case is a buffering BIO, which accepts and 283*8fb009dcSAndroid Build Coastguard Worker // buffers writes until flushed into the next BIO in the chain. 284*8fb009dcSAndroid Build Coastguard Worker 285*8fb009dcSAndroid Build Coastguard Worker // BIO_push adds |appended_bio| to the end of the chain with |bio| at the head. 286*8fb009dcSAndroid Build Coastguard Worker // It returns |bio|. Note that |appended_bio| may be the head of a chain itself 287*8fb009dcSAndroid Build Coastguard Worker // and thus this function can be used to join two chains. 288*8fb009dcSAndroid Build Coastguard Worker // 289*8fb009dcSAndroid Build Coastguard Worker // BIO_push takes ownership of the caller's reference to |appended_bio|. 290*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_push(BIO *bio, BIO *appended_bio); 291*8fb009dcSAndroid Build Coastguard Worker 292*8fb009dcSAndroid Build Coastguard Worker // BIO_pop removes |bio| from the head of a chain and returns the next BIO in 293*8fb009dcSAndroid Build Coastguard Worker // the chain, or NULL if there is no next BIO. 294*8fb009dcSAndroid Build Coastguard Worker // 295*8fb009dcSAndroid Build Coastguard Worker // The caller takes ownership of the chain's reference to |bio|. 296*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_pop(BIO *bio); 297*8fb009dcSAndroid Build Coastguard Worker 298*8fb009dcSAndroid Build Coastguard Worker // BIO_next returns the next BIO in the chain after |bio|, or NULL if there is 299*8fb009dcSAndroid Build Coastguard Worker // no such BIO. 300*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_next(BIO *bio); 301*8fb009dcSAndroid Build Coastguard Worker 302*8fb009dcSAndroid Build Coastguard Worker // BIO_free_all calls |BIO_free|. 303*8fb009dcSAndroid Build Coastguard Worker // 304*8fb009dcSAndroid Build Coastguard Worker // TODO(fork): update callers and remove. 305*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_free_all(BIO *bio); 306*8fb009dcSAndroid Build Coastguard Worker 307*8fb009dcSAndroid Build Coastguard Worker // BIO_find_type walks a chain of BIOs and returns the first that matches 308*8fb009dcSAndroid Build Coastguard Worker // |type|, which is one of the |BIO_TYPE_*| values. 309*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_find_type(BIO *bio, int type); 310*8fb009dcSAndroid Build Coastguard Worker 311*8fb009dcSAndroid Build Coastguard Worker // BIO_copy_next_retry sets the retry flags and |retry_reason| of |bio| from 312*8fb009dcSAndroid Build Coastguard Worker // the next BIO in the chain. 313*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_copy_next_retry(BIO *bio); 314*8fb009dcSAndroid Build Coastguard Worker 315*8fb009dcSAndroid Build Coastguard Worker 316*8fb009dcSAndroid Build Coastguard Worker // Printf functions. 317*8fb009dcSAndroid Build Coastguard Worker 318*8fb009dcSAndroid Build Coastguard Worker // BIO_printf behaves like |printf| but outputs to |bio| rather than a |FILE|. 319*8fb009dcSAndroid Build Coastguard Worker // It returns the number of bytes written or a negative number on error. 320*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_printf(BIO *bio, const char *format, ...) 321*8fb009dcSAndroid Build Coastguard Worker OPENSSL_PRINTF_FORMAT_FUNC(2, 3); 322*8fb009dcSAndroid Build Coastguard Worker 323*8fb009dcSAndroid Build Coastguard Worker 324*8fb009dcSAndroid Build Coastguard Worker // Utility functions. 325*8fb009dcSAndroid Build Coastguard Worker 326*8fb009dcSAndroid Build Coastguard Worker // BIO_indent prints min(|indent|, |max_indent|) spaces. It returns one on 327*8fb009dcSAndroid Build Coastguard Worker // success and zero otherwise. 328*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_indent(BIO *bio, unsigned indent, unsigned max_indent); 329*8fb009dcSAndroid Build Coastguard Worker 330*8fb009dcSAndroid Build Coastguard Worker // BIO_hexdump writes a hex dump of |data| to |bio|. Each line will be indented 331*8fb009dcSAndroid Build Coastguard Worker // by |indent| spaces. It returns one on success and zero otherwise. 332*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_hexdump(BIO *bio, const uint8_t *data, size_t len, 333*8fb009dcSAndroid Build Coastguard Worker unsigned indent); 334*8fb009dcSAndroid Build Coastguard Worker 335*8fb009dcSAndroid Build Coastguard Worker // ERR_print_errors prints the current contents of the error stack to |bio| 336*8fb009dcSAndroid Build Coastguard Worker // using human readable strings where possible. 337*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void ERR_print_errors(BIO *bio); 338*8fb009dcSAndroid Build Coastguard Worker 339*8fb009dcSAndroid Build Coastguard Worker // BIO_read_asn1 reads a single ASN.1 object from |bio|. If successful it sets 340*8fb009dcSAndroid Build Coastguard Worker // |*out| to be an allocated buffer (that should be freed with |OPENSSL_free|), 341*8fb009dcSAndroid Build Coastguard Worker // |*out_size| to the length, in bytes, of that buffer and returns one. 342*8fb009dcSAndroid Build Coastguard Worker // Otherwise it returns zero. 343*8fb009dcSAndroid Build Coastguard Worker // 344*8fb009dcSAndroid Build Coastguard Worker // If the length of the object is greater than |max_len| or 2^32 then the 345*8fb009dcSAndroid Build Coastguard Worker // function will fail. Long-form tags are not supported. If the length of the 346*8fb009dcSAndroid Build Coastguard Worker // object is indefinite the full contents of |bio| are read, unless it would be 347*8fb009dcSAndroid Build Coastguard Worker // greater than |max_len|, in which case the function fails. 348*8fb009dcSAndroid Build Coastguard Worker // 349*8fb009dcSAndroid Build Coastguard Worker // If the function fails then some unknown amount of data may have been read 350*8fb009dcSAndroid Build Coastguard Worker // from |bio|. 351*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, 352*8fb009dcSAndroid Build Coastguard Worker size_t max_len); 353*8fb009dcSAndroid Build Coastguard Worker 354*8fb009dcSAndroid Build Coastguard Worker 355*8fb009dcSAndroid Build Coastguard Worker // Memory BIOs. 356*8fb009dcSAndroid Build Coastguard Worker // 357*8fb009dcSAndroid Build Coastguard Worker // Memory BIOs can be used as a read-only source (with |BIO_new_mem_buf|) or a 358*8fb009dcSAndroid Build Coastguard Worker // writable sink (with |BIO_new|, |BIO_s_mem| and |BIO_mem_contents|). Data 359*8fb009dcSAndroid Build Coastguard Worker // written to a writable, memory BIO can be recalled by reading from it. 360*8fb009dcSAndroid Build Coastguard Worker // 361*8fb009dcSAndroid Build Coastguard Worker // Calling |BIO_reset| on a read-only BIO resets it to the original contents. 362*8fb009dcSAndroid Build Coastguard Worker // On a writable BIO, it clears any data. 363*8fb009dcSAndroid Build Coastguard Worker // 364*8fb009dcSAndroid Build Coastguard Worker // If the close flag is set to |BIO_NOCLOSE| (not the default) then the 365*8fb009dcSAndroid Build Coastguard Worker // underlying |BUF_MEM| will not be freed when the |BIO| is freed. 366*8fb009dcSAndroid Build Coastguard Worker // 367*8fb009dcSAndroid Build Coastguard Worker // Memory BIOs support |BIO_gets| and |BIO_puts|. 368*8fb009dcSAndroid Build Coastguard Worker // 369*8fb009dcSAndroid Build Coastguard Worker // |BIO_ctrl_pending| returns the number of bytes currently stored. 370*8fb009dcSAndroid Build Coastguard Worker 371*8fb009dcSAndroid Build Coastguard Worker // BIO_NOCLOSE and |BIO_CLOSE| can be used as symbolic arguments when a "close 372*8fb009dcSAndroid Build Coastguard Worker // flag" is passed to a BIO function. 373*8fb009dcSAndroid Build Coastguard Worker #define BIO_NOCLOSE 0 374*8fb009dcSAndroid Build Coastguard Worker #define BIO_CLOSE 1 375*8fb009dcSAndroid Build Coastguard Worker 376*8fb009dcSAndroid Build Coastguard Worker // BIO_s_mem returns a |BIO_METHOD| that uses a in-memory buffer. 377*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_s_mem(void); 378*8fb009dcSAndroid Build Coastguard Worker 379*8fb009dcSAndroid Build Coastguard Worker // BIO_new_mem_buf creates read-only BIO that reads from |len| bytes at |buf|. 380*8fb009dcSAndroid Build Coastguard Worker // It returns the BIO or NULL on error. This function does not copy or take 381*8fb009dcSAndroid Build Coastguard Worker // ownership of |buf|. The caller must ensure the memory pointed to by |buf| 382*8fb009dcSAndroid Build Coastguard Worker // outlives the |BIO|. 383*8fb009dcSAndroid Build Coastguard Worker // 384*8fb009dcSAndroid Build Coastguard Worker // If |len| is negative, then |buf| is treated as a NUL-terminated string, but 385*8fb009dcSAndroid Build Coastguard Worker // don't depend on this in new code. 386*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len); 387*8fb009dcSAndroid Build Coastguard Worker 388*8fb009dcSAndroid Build Coastguard Worker // BIO_mem_contents sets |*out_contents| to point to the current contents of 389*8fb009dcSAndroid Build Coastguard Worker // |bio| and |*out_len| to contain the length of that data. It returns one on 390*8fb009dcSAndroid Build Coastguard Worker // success and zero otherwise. 391*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_mem_contents(const BIO *bio, 392*8fb009dcSAndroid Build Coastguard Worker const uint8_t **out_contents, 393*8fb009dcSAndroid Build Coastguard Worker size_t *out_len); 394*8fb009dcSAndroid Build Coastguard Worker 395*8fb009dcSAndroid Build Coastguard Worker // BIO_get_mem_data sets |*contents| to point to the current contents of |bio| 396*8fb009dcSAndroid Build Coastguard Worker // and returns the length of the data. 397*8fb009dcSAndroid Build Coastguard Worker // 398*8fb009dcSAndroid Build Coastguard Worker // WARNING: don't use this, use |BIO_mem_contents|. A return value of zero from 399*8fb009dcSAndroid Build Coastguard Worker // this function can mean either that it failed or that the memory buffer is 400*8fb009dcSAndroid Build Coastguard Worker // empty. 401*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_get_mem_data(BIO *bio, char **contents); 402*8fb009dcSAndroid Build Coastguard Worker 403*8fb009dcSAndroid Build Coastguard Worker // BIO_get_mem_ptr sets |*out| to a BUF_MEM containing the current contents of 404*8fb009dcSAndroid Build Coastguard Worker // |bio|. It returns one on success or zero on error. 405*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_mem_ptr(BIO *bio, BUF_MEM **out); 406*8fb009dcSAndroid Build Coastguard Worker 407*8fb009dcSAndroid Build Coastguard Worker // BIO_set_mem_buf sets |b| as the contents of |bio|. If |take_ownership| is 408*8fb009dcSAndroid Build Coastguard Worker // non-zero, then |b| will be freed when |bio| is closed. Returns one on 409*8fb009dcSAndroid Build Coastguard Worker // success or zero otherwise. 410*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership); 411*8fb009dcSAndroid Build Coastguard Worker 412*8fb009dcSAndroid Build Coastguard Worker // BIO_set_mem_eof_return sets the value that will be returned from reading 413*8fb009dcSAndroid Build Coastguard Worker // |bio| when empty. If |eof_value| is zero then an empty memory BIO will 414*8fb009dcSAndroid Build Coastguard Worker // return EOF (that is it will return zero and |BIO_should_retry| will be 415*8fb009dcSAndroid Build Coastguard Worker // false). If |eof_value| is non zero then it will return |eof_value| when it 416*8fb009dcSAndroid Build Coastguard Worker // is empty and it will set the read retry flag (that is |BIO_read_retry| is 417*8fb009dcSAndroid Build Coastguard Worker // true). To avoid ambiguity with a normal positive return value, |eof_value| 418*8fb009dcSAndroid Build Coastguard Worker // should be set to a negative value, typically -1. 419*8fb009dcSAndroid Build Coastguard Worker // 420*8fb009dcSAndroid Build Coastguard Worker // For a read-only BIO, the default is zero (EOF). For a writable BIO, the 421*8fb009dcSAndroid Build Coastguard Worker // default is -1 so that additional data can be written once exhausted. 422*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_mem_eof_return(BIO *bio, int eof_value); 423*8fb009dcSAndroid Build Coastguard Worker 424*8fb009dcSAndroid Build Coastguard Worker 425*8fb009dcSAndroid Build Coastguard Worker // File descriptor BIOs. 426*8fb009dcSAndroid Build Coastguard Worker // 427*8fb009dcSAndroid Build Coastguard Worker // File descriptor BIOs are wrappers around the system's |read| and |write| 428*8fb009dcSAndroid Build Coastguard Worker // functions. If the close flag is set then then |close| is called on the 429*8fb009dcSAndroid Build Coastguard Worker // underlying file descriptor when the BIO is freed. 430*8fb009dcSAndroid Build Coastguard Worker // 431*8fb009dcSAndroid Build Coastguard Worker // |BIO_reset| attempts to seek the file pointer to the start of file using 432*8fb009dcSAndroid Build Coastguard Worker // |lseek|. 433*8fb009dcSAndroid Build Coastguard Worker 434*8fb009dcSAndroid Build Coastguard Worker #if !defined(OPENSSL_NO_POSIX_IO) 435*8fb009dcSAndroid Build Coastguard Worker // BIO_s_fd returns a |BIO_METHOD| for file descriptor fds. 436*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_s_fd(void); 437*8fb009dcSAndroid Build Coastguard Worker 438*8fb009dcSAndroid Build Coastguard Worker // BIO_new_fd creates a new file descriptor BIO wrapping |fd|. If |close_flag| 439*8fb009dcSAndroid Build Coastguard Worker // is non-zero, then |fd| will be closed when the BIO is. 440*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_fd(int fd, int close_flag); 441*8fb009dcSAndroid Build Coastguard Worker #endif 442*8fb009dcSAndroid Build Coastguard Worker 443*8fb009dcSAndroid Build Coastguard Worker // BIO_set_fd sets the file descriptor of |bio| to |fd|. If |close_flag| is 444*8fb009dcSAndroid Build Coastguard Worker // non-zero then |fd| will be closed when |bio| is. It returns one on success 445*8fb009dcSAndroid Build Coastguard Worker // or zero on error. 446*8fb009dcSAndroid Build Coastguard Worker // 447*8fb009dcSAndroid Build Coastguard Worker // This function may also be used with socket BIOs (see |BIO_s_socket| and 448*8fb009dcSAndroid Build Coastguard Worker // |BIO_new_socket|). 449*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_fd(BIO *bio, int fd, int close_flag); 450*8fb009dcSAndroid Build Coastguard Worker 451*8fb009dcSAndroid Build Coastguard Worker // BIO_get_fd returns the file descriptor currently in use by |bio| or -1 if 452*8fb009dcSAndroid Build Coastguard Worker // |bio| does not wrap a file descriptor. If there is a file descriptor and 453*8fb009dcSAndroid Build Coastguard Worker // |out_fd| is not NULL, it also sets |*out_fd| to the file descriptor. 454*8fb009dcSAndroid Build Coastguard Worker // 455*8fb009dcSAndroid Build Coastguard Worker // This function may also be used with socket BIOs (see |BIO_s_socket| and 456*8fb009dcSAndroid Build Coastguard Worker // |BIO_new_socket|). 457*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd); 458*8fb009dcSAndroid Build Coastguard Worker 459*8fb009dcSAndroid Build Coastguard Worker 460*8fb009dcSAndroid Build Coastguard Worker // File BIOs. 461*8fb009dcSAndroid Build Coastguard Worker // 462*8fb009dcSAndroid Build Coastguard Worker // File BIOs are wrappers around a C |FILE| object. 463*8fb009dcSAndroid Build Coastguard Worker // 464*8fb009dcSAndroid Build Coastguard Worker // |BIO_flush| on a file BIO calls |fflush| on the wrapped stream. 465*8fb009dcSAndroid Build Coastguard Worker // 466*8fb009dcSAndroid Build Coastguard Worker // |BIO_reset| attempts to seek the file pointer to the start of file using 467*8fb009dcSAndroid Build Coastguard Worker // |fseek|. 468*8fb009dcSAndroid Build Coastguard Worker // 469*8fb009dcSAndroid Build Coastguard Worker // Setting the close flag causes |fclose| to be called on the stream when the 470*8fb009dcSAndroid Build Coastguard Worker // BIO is freed. 471*8fb009dcSAndroid Build Coastguard Worker 472*8fb009dcSAndroid Build Coastguard Worker // BIO_s_file returns a BIO_METHOD that wraps a |FILE|. 473*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_s_file(void); 474*8fb009dcSAndroid Build Coastguard Worker 475*8fb009dcSAndroid Build Coastguard Worker // BIO_new_file creates a file BIO by opening |filename| with the given mode. 476*8fb009dcSAndroid Build Coastguard Worker // See the |fopen| manual page for details of the mode argument. On Windows, 477*8fb009dcSAndroid Build Coastguard Worker // files may be opened in either binary or text mode so, as in |fopen|, callers 478*8fb009dcSAndroid Build Coastguard Worker // must specify the desired option in |mode|. 479*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_file(const char *filename, const char *mode); 480*8fb009dcSAndroid Build Coastguard Worker 481*8fb009dcSAndroid Build Coastguard Worker // BIO_FP_TEXT indicates the |FILE| should be switched to text mode on Windows. 482*8fb009dcSAndroid Build Coastguard Worker // It has no effect on non-Windows platforms. 483*8fb009dcSAndroid Build Coastguard Worker #define BIO_FP_TEXT 0x10 484*8fb009dcSAndroid Build Coastguard Worker 485*8fb009dcSAndroid Build Coastguard Worker // BIO_new_fp creates a new file BIO that wraps |file|. If |flags| contains 486*8fb009dcSAndroid Build Coastguard Worker // |BIO_CLOSE|, then |fclose| will be called on |file| when the BIO is closed. 487*8fb009dcSAndroid Build Coastguard Worker // 488*8fb009dcSAndroid Build Coastguard Worker // On Windows, if |flags| contains |BIO_FP_TEXT|, this function will 489*8fb009dcSAndroid Build Coastguard Worker // additionally switch |file| to text mode. This is not recommended, but may be 490*8fb009dcSAndroid Build Coastguard Worker // required for OpenSSL compatibility. If |file| was not already in text mode, 491*8fb009dcSAndroid Build Coastguard Worker // mode changes can cause unflushed data in |file| to be written in unexpected 492*8fb009dcSAndroid Build Coastguard Worker // ways. See |_setmode| in Windows documentation for details. 493*8fb009dcSAndroid Build Coastguard Worker // 494*8fb009dcSAndroid Build Coastguard Worker // Unlike OpenSSL, if |flags| does not contain |BIO_FP_TEXT|, the translation 495*8fb009dcSAndroid Build Coastguard Worker // mode of |file| is left as-is. In OpenSSL, |file| will be set to binary, with 496*8fb009dcSAndroid Build Coastguard Worker // the same pitfalls as above. BoringSSL does not do this so that wrapping a 497*8fb009dcSAndroid Build Coastguard Worker // |FILE| in a |BIO| will not inadvertently change its state. 498*8fb009dcSAndroid Build Coastguard Worker // 499*8fb009dcSAndroid Build Coastguard Worker // To avoid these pitfalls, callers should set the desired translation mode when 500*8fb009dcSAndroid Build Coastguard Worker // opening the file. If targeting just BoringSSL, this is sufficient. If 501*8fb009dcSAndroid Build Coastguard Worker // targeting both OpenSSL and BoringSSL, callers should set |BIO_FP_TEXT| to 502*8fb009dcSAndroid Build Coastguard Worker // match the desired state of the file. 503*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_fp(FILE *file, int flags); 504*8fb009dcSAndroid Build Coastguard Worker 505*8fb009dcSAndroid Build Coastguard Worker // BIO_get_fp sets |*out_file| to the current |FILE| for |bio|. It returns one 506*8fb009dcSAndroid Build Coastguard Worker // on success and zero otherwise. 507*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_fp(BIO *bio, FILE **out_file); 508*8fb009dcSAndroid Build Coastguard Worker 509*8fb009dcSAndroid Build Coastguard Worker // BIO_set_fp sets the |FILE| for |bio|. If |flags| contains |BIO_CLOSE| then 510*8fb009dcSAndroid Build Coastguard Worker // |fclose| will be called on |file| when |bio| is closed. It returns one on 511*8fb009dcSAndroid Build Coastguard Worker // success and zero otherwise. 512*8fb009dcSAndroid Build Coastguard Worker // 513*8fb009dcSAndroid Build Coastguard Worker // On Windows, if |flags| contains |BIO_FP_TEXT|, this function will 514*8fb009dcSAndroid Build Coastguard Worker // additionally switch |file| to text mode. This is not recommended, but may be 515*8fb009dcSAndroid Build Coastguard Worker // required for OpenSSL compatibility. If |file| was not already in text mode, 516*8fb009dcSAndroid Build Coastguard Worker // mode changes can cause unflushed data in |file| to be written in unexpected 517*8fb009dcSAndroid Build Coastguard Worker // ways. See |_setmode| in Windows documentation for details. 518*8fb009dcSAndroid Build Coastguard Worker // 519*8fb009dcSAndroid Build Coastguard Worker // Unlike OpenSSL, if |flags| does not contain |BIO_FP_TEXT|, the translation 520*8fb009dcSAndroid Build Coastguard Worker // mode of |file| is left as-is. In OpenSSL, |file| will be set to binary, with 521*8fb009dcSAndroid Build Coastguard Worker // the same pitfalls as above. BoringSSL does not do this so that wrapping a 522*8fb009dcSAndroid Build Coastguard Worker // |FILE| in a |BIO| will not inadvertently change its state. 523*8fb009dcSAndroid Build Coastguard Worker // 524*8fb009dcSAndroid Build Coastguard Worker // To avoid these pitfalls, callers should set the desired translation mode when 525*8fb009dcSAndroid Build Coastguard Worker // opening the file. If targeting just BoringSSL, this is sufficient. If 526*8fb009dcSAndroid Build Coastguard Worker // targeting both OpenSSL and BoringSSL, callers should set |BIO_FP_TEXT| to 527*8fb009dcSAndroid Build Coastguard Worker // match the desired state of the file. 528*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_fp(BIO *bio, FILE *file, int flags); 529*8fb009dcSAndroid Build Coastguard Worker 530*8fb009dcSAndroid Build Coastguard Worker // BIO_read_filename opens |filename| for reading and sets the result as the 531*8fb009dcSAndroid Build Coastguard Worker // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| 532*8fb009dcSAndroid Build Coastguard Worker // will be closed when |bio| is freed. On Windows, the file is opened in binary 533*8fb009dcSAndroid Build Coastguard Worker // mode. 534*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_read_filename(BIO *bio, const char *filename); 535*8fb009dcSAndroid Build Coastguard Worker 536*8fb009dcSAndroid Build Coastguard Worker // BIO_write_filename opens |filename| for writing and sets the result as the 537*8fb009dcSAndroid Build Coastguard Worker // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| 538*8fb009dcSAndroid Build Coastguard Worker // will be closed when |bio| is freed. On Windows, the file is opened in binary 539*8fb009dcSAndroid Build Coastguard Worker // mode. 540*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_write_filename(BIO *bio, const char *filename); 541*8fb009dcSAndroid Build Coastguard Worker 542*8fb009dcSAndroid Build Coastguard Worker // BIO_append_filename opens |filename| for appending and sets the result as 543*8fb009dcSAndroid Build Coastguard Worker // the |FILE| for |bio|. It returns one on success and zero otherwise. The 544*8fb009dcSAndroid Build Coastguard Worker // |FILE| will be closed when |bio| is freed. On Windows, the file is opened in 545*8fb009dcSAndroid Build Coastguard Worker // binary mode. 546*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_append_filename(BIO *bio, const char *filename); 547*8fb009dcSAndroid Build Coastguard Worker 548*8fb009dcSAndroid Build Coastguard Worker // BIO_rw_filename opens |filename| for reading and writing and sets the result 549*8fb009dcSAndroid Build Coastguard Worker // as the |FILE| for |bio|. It returns one on success and zero otherwise. The 550*8fb009dcSAndroid Build Coastguard Worker // |FILE| will be closed when |bio| is freed. On Windows, the file is opened in 551*8fb009dcSAndroid Build Coastguard Worker // binary mode. 552*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_rw_filename(BIO *bio, const char *filename); 553*8fb009dcSAndroid Build Coastguard Worker 554*8fb009dcSAndroid Build Coastguard Worker // BIO_tell returns the file offset of |bio|, or a negative number on error or 555*8fb009dcSAndroid Build Coastguard Worker // if |bio| does not support the operation. 556*8fb009dcSAndroid Build Coastguard Worker // 557*8fb009dcSAndroid Build Coastguard Worker // TODO(https://crbug.com/boringssl/465): On platforms where |long| is 32-bit, 558*8fb009dcSAndroid Build Coastguard Worker // this function cannot report 64-bit offsets. 559*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_tell(BIO *bio); 560*8fb009dcSAndroid Build Coastguard Worker 561*8fb009dcSAndroid Build Coastguard Worker // BIO_seek sets the file offset of |bio| to |offset|. It returns a non-negative 562*8fb009dcSAndroid Build Coastguard Worker // number on success and a negative number on error. If |bio| is a file 563*8fb009dcSAndroid Build Coastguard Worker // descriptor |BIO|, it returns the resulting file offset on success. If |bio| 564*8fb009dcSAndroid Build Coastguard Worker // is a file |BIO|, it returns zero on success. 565*8fb009dcSAndroid Build Coastguard Worker // 566*8fb009dcSAndroid Build Coastguard Worker // WARNING: This function's return value conventions differs from most functions 567*8fb009dcSAndroid Build Coastguard Worker // in this library. 568*8fb009dcSAndroid Build Coastguard Worker // 569*8fb009dcSAndroid Build Coastguard Worker // TODO(https://crbug.com/boringssl/465): On platforms where |long| is 32-bit, 570*8fb009dcSAndroid Build Coastguard Worker // this function cannot handle 64-bit offsets. 571*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT long BIO_seek(BIO *bio, long offset); 572*8fb009dcSAndroid Build Coastguard Worker 573*8fb009dcSAndroid Build Coastguard Worker 574*8fb009dcSAndroid Build Coastguard Worker // Socket BIOs. 575*8fb009dcSAndroid Build Coastguard Worker // 576*8fb009dcSAndroid Build Coastguard Worker // Socket BIOs behave like file descriptor BIOs but, on Windows systems, wrap 577*8fb009dcSAndroid Build Coastguard Worker // the system's |recv| and |send| functions instead of |read| and |write|. On 578*8fb009dcSAndroid Build Coastguard Worker // Windows, file descriptors are provided by C runtime and are not 579*8fb009dcSAndroid Build Coastguard Worker // interchangeable with sockets. 580*8fb009dcSAndroid Build Coastguard Worker // 581*8fb009dcSAndroid Build Coastguard Worker // Socket BIOs may be used with |BIO_set_fd| and |BIO_get_fd|. 582*8fb009dcSAndroid Build Coastguard Worker // 583*8fb009dcSAndroid Build Coastguard Worker // TODO(davidben): Add separate APIs and fix the internals to use |SOCKET|s 584*8fb009dcSAndroid Build Coastguard Worker // around rather than rely on int casts. 585*8fb009dcSAndroid Build Coastguard Worker 586*8fb009dcSAndroid Build Coastguard Worker #if !defined(OPENSSL_NO_SOCK) 587*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_s_socket(void); 588*8fb009dcSAndroid Build Coastguard Worker 589*8fb009dcSAndroid Build Coastguard Worker // BIO_new_socket allocates and initialises a fresh BIO which will read and 590*8fb009dcSAndroid Build Coastguard Worker // write to the socket |fd|. If |close_flag| is |BIO_CLOSE| then closing the 591*8fb009dcSAndroid Build Coastguard Worker // BIO will close |fd|. It returns the fresh |BIO| or NULL on error. 592*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_socket(int fd, int close_flag); 593*8fb009dcSAndroid Build Coastguard Worker #endif // !OPENSSL_NO_SOCK 594*8fb009dcSAndroid Build Coastguard Worker 595*8fb009dcSAndroid Build Coastguard Worker 596*8fb009dcSAndroid Build Coastguard Worker // Connect BIOs. 597*8fb009dcSAndroid Build Coastguard Worker // 598*8fb009dcSAndroid Build Coastguard Worker // A connection BIO creates a network connection and transfers data over the 599*8fb009dcSAndroid Build Coastguard Worker // resulting socket. 600*8fb009dcSAndroid Build Coastguard Worker 601*8fb009dcSAndroid Build Coastguard Worker #if !defined(OPENSSL_NO_SOCK) 602*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_s_connect(void); 603*8fb009dcSAndroid Build Coastguard Worker 604*8fb009dcSAndroid Build Coastguard Worker // BIO_new_connect returns a BIO that connects to the given hostname and port. 605*8fb009dcSAndroid Build Coastguard Worker // The |host_and_optional_port| argument should be of the form 606*8fb009dcSAndroid Build Coastguard Worker // "www.example.com" or "www.example.com:443". If the port is omitted, it must 607*8fb009dcSAndroid Build Coastguard Worker // be provided with |BIO_set_conn_port|. 608*8fb009dcSAndroid Build Coastguard Worker // 609*8fb009dcSAndroid Build Coastguard Worker // It returns the new BIO on success, or NULL on error. 610*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO *BIO_new_connect(const char *host_and_optional_port); 611*8fb009dcSAndroid Build Coastguard Worker 612*8fb009dcSAndroid Build Coastguard Worker // BIO_set_conn_hostname sets |host_and_optional_port| as the hostname and 613*8fb009dcSAndroid Build Coastguard Worker // optional port that |bio| will connect to. If the port is omitted, it must be 614*8fb009dcSAndroid Build Coastguard Worker // provided with |BIO_set_conn_port|. 615*8fb009dcSAndroid Build Coastguard Worker // 616*8fb009dcSAndroid Build Coastguard Worker // It returns one on success and zero otherwise. 617*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_conn_hostname(BIO *bio, 618*8fb009dcSAndroid Build Coastguard Worker const char *host_and_optional_port); 619*8fb009dcSAndroid Build Coastguard Worker 620*8fb009dcSAndroid Build Coastguard Worker // BIO_set_conn_port sets |port_str| as the port or service name that |bio| 621*8fb009dcSAndroid Build Coastguard Worker // will connect to. It returns one on success and zero otherwise. 622*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_conn_port(BIO *bio, const char *port_str); 623*8fb009dcSAndroid Build Coastguard Worker 624*8fb009dcSAndroid Build Coastguard Worker // BIO_set_conn_int_port sets |*port| as the port that |bio| will connect to. 625*8fb009dcSAndroid Build Coastguard Worker // It returns one on success and zero otherwise. 626*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_conn_int_port(BIO *bio, const int *port); 627*8fb009dcSAndroid Build Coastguard Worker 628*8fb009dcSAndroid Build Coastguard Worker // BIO_set_nbio sets whether |bio| will use non-blocking I/O operations. It 629*8fb009dcSAndroid Build Coastguard Worker // returns one on success and zero otherwise. This only works for connect BIOs 630*8fb009dcSAndroid Build Coastguard Worker // and must be called before |bio| is connected to take effect. 631*8fb009dcSAndroid Build Coastguard Worker // 632*8fb009dcSAndroid Build Coastguard Worker // For socket and fd BIOs, callers must configure blocking vs. non-blocking I/O 633*8fb009dcSAndroid Build Coastguard Worker // using the underlying platform APIs. 634*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_nbio(BIO *bio, int on); 635*8fb009dcSAndroid Build Coastguard Worker 636*8fb009dcSAndroid Build Coastguard Worker // BIO_do_connect connects |bio| if it has not been connected yet. It returns 637*8fb009dcSAndroid Build Coastguard Worker // one on success and <= 0 otherwise. 638*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_do_connect(BIO *bio); 639*8fb009dcSAndroid Build Coastguard Worker #endif // !OPENSSL_NO_SOCK 640*8fb009dcSAndroid Build Coastguard Worker 641*8fb009dcSAndroid Build Coastguard Worker 642*8fb009dcSAndroid Build Coastguard Worker // Datagram BIOs. 643*8fb009dcSAndroid Build Coastguard Worker // 644*8fb009dcSAndroid Build Coastguard Worker // TODO(fork): not implemented. 645*8fb009dcSAndroid Build Coastguard Worker 646*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DGRAM_QUERY_MTU 40 // as kernel for current MTU 647*8fb009dcSAndroid Build Coastguard Worker 648*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for MTU. want to use 649*8fb009dcSAndroid Build Coastguard Worker this if asking the kernel fails */ 650*8fb009dcSAndroid Build Coastguard Worker 651*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU was exceed in 652*8fb009dcSAndroid Build Coastguard Worker the previous write operation. */ 653*8fb009dcSAndroid Build Coastguard Worker 654*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT is unsupported as it is unused by consumers 655*8fb009dcSAndroid Build Coastguard Worker // and depends on |timeval|, which is not 2038-clean on all platforms. 656*8fb009dcSAndroid Build Coastguard Worker 657*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DGRAM_GET_PEER 46 658*8fb009dcSAndroid Build Coastguard Worker 659*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 660*8fb009dcSAndroid Build Coastguard Worker 661*8fb009dcSAndroid Build Coastguard Worker 662*8fb009dcSAndroid Build Coastguard Worker // BIO Pairs. 663*8fb009dcSAndroid Build Coastguard Worker // 664*8fb009dcSAndroid Build Coastguard Worker // BIO pairs provide a "loopback" like system: a pair of BIOs where data 665*8fb009dcSAndroid Build Coastguard Worker // written to one can be read from the other and vice versa. 666*8fb009dcSAndroid Build Coastguard Worker 667*8fb009dcSAndroid Build Coastguard Worker // BIO_new_bio_pair sets |*out1| and |*out2| to two freshly created BIOs where 668*8fb009dcSAndroid Build Coastguard Worker // data written to one can be read from the other and vice versa. The 669*8fb009dcSAndroid Build Coastguard Worker // |writebuf1| argument gives the size of the buffer used in |*out1| and 670*8fb009dcSAndroid Build Coastguard Worker // |writebuf2| for |*out2|. It returns one on success and zero on error. 671*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_new_bio_pair(BIO **out1, size_t writebuf1, BIO **out2, 672*8fb009dcSAndroid Build Coastguard Worker size_t writebuf2); 673*8fb009dcSAndroid Build Coastguard Worker 674*8fb009dcSAndroid Build Coastguard Worker // BIO_ctrl_get_read_request returns the number of bytes that the other side of 675*8fb009dcSAndroid Build Coastguard Worker // |bio| tried (unsuccessfully) to read. 676*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t BIO_ctrl_get_read_request(BIO *bio); 677*8fb009dcSAndroid Build Coastguard Worker 678*8fb009dcSAndroid Build Coastguard Worker // BIO_ctrl_get_write_guarantee returns the number of bytes that |bio| (which 679*8fb009dcSAndroid Build Coastguard Worker // must have been returned by |BIO_new_bio_pair|) will accept on the next 680*8fb009dcSAndroid Build Coastguard Worker // |BIO_write| call. 681*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT size_t BIO_ctrl_get_write_guarantee(BIO *bio); 682*8fb009dcSAndroid Build Coastguard Worker 683*8fb009dcSAndroid Build Coastguard Worker // BIO_shutdown_wr marks |bio| as closed, from the point of view of the other 684*8fb009dcSAndroid Build Coastguard Worker // side of the pair. Future |BIO_write| calls on |bio| will fail. It returns 685*8fb009dcSAndroid Build Coastguard Worker // one on success and zero otherwise. 686*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_shutdown_wr(BIO *bio); 687*8fb009dcSAndroid Build Coastguard Worker 688*8fb009dcSAndroid Build Coastguard Worker 689*8fb009dcSAndroid Build Coastguard Worker // Custom BIOs. 690*8fb009dcSAndroid Build Coastguard Worker // 691*8fb009dcSAndroid Build Coastguard Worker // Consumers can create custom |BIO|s by filling in a |BIO_METHOD| and using 692*8fb009dcSAndroid Build Coastguard Worker // low-level control functions to set state. 693*8fb009dcSAndroid Build Coastguard Worker 694*8fb009dcSAndroid Build Coastguard Worker // BIO_get_new_index returns a new "type" value for a custom |BIO|. 695*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_new_index(void); 696*8fb009dcSAndroid Build Coastguard Worker 697*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_new returns a newly-allocated |BIO_METHOD| or NULL on allocation 698*8fb009dcSAndroid Build Coastguard Worker // error. The |type| specifies the type that will be returned by 699*8fb009dcSAndroid Build Coastguard Worker // |BIO_method_type|. If this is unnecessary, this value may be zero. The |name| 700*8fb009dcSAndroid Build Coastguard Worker // parameter is vestigial and may be NULL. 701*8fb009dcSAndroid Build Coastguard Worker // 702*8fb009dcSAndroid Build Coastguard Worker // Use the |BIO_meth_set_*| functions below to initialize the |BIO_METHOD|. The 703*8fb009dcSAndroid Build Coastguard Worker // function implementations may use |BIO_set_data| and |BIO_get_data| to add 704*8fb009dcSAndroid Build Coastguard Worker // method-specific state to associated |BIO|s. Additionally, |BIO_set_init| must 705*8fb009dcSAndroid Build Coastguard Worker // be called after an associated |BIO| is fully initialized. State set via 706*8fb009dcSAndroid Build Coastguard Worker // |BIO_set_data| may be released by configuring a destructor with 707*8fb009dcSAndroid Build Coastguard Worker // |BIO_meth_set_destroy|. 708*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT BIO_METHOD *BIO_meth_new(int type, const char *name); 709*8fb009dcSAndroid Build Coastguard Worker 710*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_free releases memory associated with |method|. 711*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_meth_free(BIO_METHOD *method); 712*8fb009dcSAndroid Build Coastguard Worker 713*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_create sets a function to be called on |BIO_new| for |method| 714*8fb009dcSAndroid Build Coastguard Worker // and returns one. The function should return one on success and zero on 715*8fb009dcSAndroid Build Coastguard Worker // error. 716*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_create(BIO_METHOD *method, 717*8fb009dcSAndroid Build Coastguard Worker int (*create_func)(BIO *)); 718*8fb009dcSAndroid Build Coastguard Worker 719*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_destroy sets a function to release data associated with a |BIO| 720*8fb009dcSAndroid Build Coastguard Worker // and returns one. The function's return value is ignored. 721*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_destroy(BIO_METHOD *method, 722*8fb009dcSAndroid Build Coastguard Worker int (*destroy_func)(BIO *)); 723*8fb009dcSAndroid Build Coastguard Worker 724*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_write sets the implementation of |BIO_write| for |method| and 725*8fb009dcSAndroid Build Coastguard Worker // returns one. |BIO_METHOD|s which implement |BIO_write| should also implement 726*8fb009dcSAndroid Build Coastguard Worker // |BIO_CTRL_FLUSH|. (See |BIO_meth_set_ctrl|.) 727*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_write(BIO_METHOD *method, 728*8fb009dcSAndroid Build Coastguard Worker int (*write_func)(BIO *, const char *, 729*8fb009dcSAndroid Build Coastguard Worker int)); 730*8fb009dcSAndroid Build Coastguard Worker 731*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_read sets the implementation of |BIO_read| for |method| and 732*8fb009dcSAndroid Build Coastguard Worker // returns one. 733*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_read(BIO_METHOD *method, 734*8fb009dcSAndroid Build Coastguard Worker int (*read_func)(BIO *, char *, int)); 735*8fb009dcSAndroid Build Coastguard Worker 736*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_gets sets the implementation of |BIO_gets| for |method| and 737*8fb009dcSAndroid Build Coastguard Worker // returns one. 738*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_gets(BIO_METHOD *method, 739*8fb009dcSAndroid Build Coastguard Worker int (*gets_func)(BIO *, char *, int)); 740*8fb009dcSAndroid Build Coastguard Worker 741*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_ctrl sets the implementation of |BIO_ctrl| for |method| and 742*8fb009dcSAndroid Build Coastguard Worker // returns one. 743*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_ctrl(BIO_METHOD *method, 744*8fb009dcSAndroid Build Coastguard Worker long (*ctrl_func)(BIO *, int, long, 745*8fb009dcSAndroid Build Coastguard Worker void *)); 746*8fb009dcSAndroid Build Coastguard Worker 747*8fb009dcSAndroid Build Coastguard Worker // BIO_set_data sets custom data on |bio|. It may be retried with 748*8fb009dcSAndroid Build Coastguard Worker // |BIO_get_data|. 749*8fb009dcSAndroid Build Coastguard Worker // 750*8fb009dcSAndroid Build Coastguard Worker // This function should only be called by the implementation of a custom |BIO|. 751*8fb009dcSAndroid Build Coastguard Worker // In particular, the data pointer of a built-in |BIO| is private to the 752*8fb009dcSAndroid Build Coastguard Worker // library. For other uses, see |BIO_set_ex_data| and |BIO_set_app_data|. 753*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_data(BIO *bio, void *ptr); 754*8fb009dcSAndroid Build Coastguard Worker 755*8fb009dcSAndroid Build Coastguard Worker // BIO_get_data returns custom data on |bio| set by |BIO_get_data|. 756*8fb009dcSAndroid Build Coastguard Worker // 757*8fb009dcSAndroid Build Coastguard Worker // This function should only be called by the implementation of a custom |BIO|. 758*8fb009dcSAndroid Build Coastguard Worker // In particular, the data pointer of a built-in |BIO| is private to the 759*8fb009dcSAndroid Build Coastguard Worker // library. For other uses, see |BIO_get_ex_data| and |BIO_get_app_data|. 760*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void *BIO_get_data(BIO *bio); 761*8fb009dcSAndroid Build Coastguard Worker 762*8fb009dcSAndroid Build Coastguard Worker // BIO_set_init sets whether |bio| has been fully initialized. Until fully 763*8fb009dcSAndroid Build Coastguard Worker // initialized, |BIO_read| and |BIO_write| will fail. 764*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_init(BIO *bio, int init); 765*8fb009dcSAndroid Build Coastguard Worker 766*8fb009dcSAndroid Build Coastguard Worker // BIO_get_init returns whether |bio| has been fully initialized. 767*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_init(BIO *bio); 768*8fb009dcSAndroid Build Coastguard Worker 769*8fb009dcSAndroid Build Coastguard Worker // These are values of the |cmd| argument to |BIO_ctrl|. 770*8fb009dcSAndroid Build Coastguard Worker 771*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_RESET implements |BIO_reset|. The arguments are unused. 772*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_RESET 1 773*8fb009dcSAndroid Build Coastguard Worker 774*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_EOF implements |BIO_eof|. The arguments are unused. 775*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_EOF 2 776*8fb009dcSAndroid Build Coastguard Worker 777*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_INFO is a legacy command that returns information specific to the 778*8fb009dcSAndroid Build Coastguard Worker // type of |BIO|. It is not safe to call generically and should not be 779*8fb009dcSAndroid Build Coastguard Worker // implemented in new |BIO| types. 780*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_INFO 3 781*8fb009dcSAndroid Build Coastguard Worker 782*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_GET_CLOSE returns the close flag set by |BIO_CTRL_SET_CLOSE|. The 783*8fb009dcSAndroid Build Coastguard Worker // arguments are unused. 784*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_GET_CLOSE 8 785*8fb009dcSAndroid Build Coastguard Worker 786*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_SET_CLOSE implements |BIO_set_close|. The |larg| argument is the 787*8fb009dcSAndroid Build Coastguard Worker // close flag. 788*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_SET_CLOSE 9 789*8fb009dcSAndroid Build Coastguard Worker 790*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_PENDING implements |BIO_pending|. The arguments are unused. 791*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_PENDING 10 792*8fb009dcSAndroid Build Coastguard Worker 793*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_FLUSH implements |BIO_flush|. The arguments are unused. 794*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_FLUSH 11 795*8fb009dcSAndroid Build Coastguard Worker 796*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_WPENDING implements |BIO_wpending|. The arguments are unused. 797*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_WPENDING 13 798*8fb009dcSAndroid Build Coastguard Worker 799*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_SET_CALLBACK sets an informational callback of type 800*8fb009dcSAndroid Build Coastguard Worker // int cb(BIO *bio, int state, int ret) 801*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_SET_CALLBACK 14 802*8fb009dcSAndroid Build Coastguard Worker 803*8fb009dcSAndroid Build Coastguard Worker // BIO_CTRL_GET_CALLBACK returns the callback set by |BIO_CTRL_SET_CALLBACK|. 804*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_GET_CALLBACK 15 805*8fb009dcSAndroid Build Coastguard Worker 806*8fb009dcSAndroid Build Coastguard Worker // The following are never used, but are defined to aid porting existing code. 807*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_SET 4 808*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_GET 5 809*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_PUSH 6 810*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_POP 7 811*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_DUP 12 812*8fb009dcSAndroid Build Coastguard Worker #define BIO_CTRL_SET_FILENAME 30 813*8fb009dcSAndroid Build Coastguard Worker 814*8fb009dcSAndroid Build Coastguard Worker 815*8fb009dcSAndroid Build Coastguard Worker // ex_data functions. 816*8fb009dcSAndroid Build Coastguard Worker // 817*8fb009dcSAndroid Build Coastguard Worker // See |ex_data.h| for details. 818*8fb009dcSAndroid Build Coastguard Worker 819*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_ex_new_index(long argl, void *argp, 820*8fb009dcSAndroid Build Coastguard Worker CRYPTO_EX_unused *unused, 821*8fb009dcSAndroid Build Coastguard Worker CRYPTO_EX_dup *dup_unused, 822*8fb009dcSAndroid Build Coastguard Worker CRYPTO_EX_free *free_func); 823*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_ex_data(BIO *bio, int idx, void *arg); 824*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void *BIO_get_ex_data(const BIO *bio, int idx); 825*8fb009dcSAndroid Build Coastguard Worker 826*8fb009dcSAndroid Build Coastguard Worker #define BIO_set_app_data(bio, arg) (BIO_set_ex_data(bio, 0, (char *)(arg))) 827*8fb009dcSAndroid Build Coastguard Worker #define BIO_get_app_data(bio) (BIO_get_ex_data(bio, 0)) 828*8fb009dcSAndroid Build Coastguard Worker 829*8fb009dcSAndroid Build Coastguard Worker 830*8fb009dcSAndroid Build Coastguard Worker // Deprecated functions. 831*8fb009dcSAndroid Build Coastguard Worker 832*8fb009dcSAndroid Build Coastguard Worker // BIO_f_base64 returns a filter |BIO| that base64-encodes data written into 833*8fb009dcSAndroid Build Coastguard Worker // it, and decodes data read from it. |BIO_gets| is not supported. Call 834*8fb009dcSAndroid Build Coastguard Worker // |BIO_flush| when done writing, to signal that no more data are to be 835*8fb009dcSAndroid Build Coastguard Worker // encoded. The flag |BIO_FLAGS_BASE64_NO_NL| may be set to encode all the data 836*8fb009dcSAndroid Build Coastguard Worker // on one line. 837*8fb009dcSAndroid Build Coastguard Worker // 838*8fb009dcSAndroid Build Coastguard Worker // Use |EVP_EncodeBlock| and |EVP_DecodeBase64| instead. 839*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT const BIO_METHOD *BIO_f_base64(void); 840*8fb009dcSAndroid Build Coastguard Worker 841*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_retry_special(BIO *bio); 842*8fb009dcSAndroid Build Coastguard Worker 843*8fb009dcSAndroid Build Coastguard Worker // BIO_set_write_buffer_size returns zero. 844*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_set_write_buffer_size(BIO *bio, int buffer_size); 845*8fb009dcSAndroid Build Coastguard Worker 846*8fb009dcSAndroid Build Coastguard Worker // BIO_set_shutdown sets a method-specific "shutdown" bit on |bio|. 847*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT void BIO_set_shutdown(BIO *bio, int shutdown); 848*8fb009dcSAndroid Build Coastguard Worker 849*8fb009dcSAndroid Build Coastguard Worker // BIO_get_shutdown returns the method-specific "shutdown" bit. 850*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_get_shutdown(BIO *bio); 851*8fb009dcSAndroid Build Coastguard Worker 852*8fb009dcSAndroid Build Coastguard Worker // BIO_meth_set_puts returns one. |BIO_puts| is implemented with |BIO_write| in 853*8fb009dcSAndroid Build Coastguard Worker // BoringSSL. 854*8fb009dcSAndroid Build Coastguard Worker OPENSSL_EXPORT int BIO_meth_set_puts(BIO_METHOD *method, 855*8fb009dcSAndroid Build Coastguard Worker int (*puts)(BIO *, const char *)); 856*8fb009dcSAndroid Build Coastguard Worker 857*8fb009dcSAndroid Build Coastguard Worker 858*8fb009dcSAndroid Build Coastguard Worker // Private functions 859*8fb009dcSAndroid Build Coastguard Worker 860*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_READ 0x01 861*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_WRITE 0x02 862*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_IO_SPECIAL 0x04 863*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_RWS (BIO_FLAGS_READ | BIO_FLAGS_WRITE | BIO_FLAGS_IO_SPECIAL) 864*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_SHOULD_RETRY 0x08 865*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_BASE64_NO_NL 0x100 866*8fb009dcSAndroid Build Coastguard Worker // BIO_FLAGS_MEM_RDONLY is used with memory BIOs. It means we shouldn't free up 867*8fb009dcSAndroid Build Coastguard Worker // or change the data in any way. 868*8fb009dcSAndroid Build Coastguard Worker #define BIO_FLAGS_MEM_RDONLY 0x200 869*8fb009dcSAndroid Build Coastguard Worker 870*8fb009dcSAndroid Build Coastguard Worker // BIO_TYPE_DESCRIPTOR denotes that the |BIO| responds to the |BIO_C_SET_FD| 871*8fb009dcSAndroid Build Coastguard Worker // (|BIO_set_fd|) and |BIO_C_GET_FD| (|BIO_get_fd|) control hooks. 872*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_DESCRIPTOR 0x0100 // socket, fd, connect or accept 873*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_FILTER 0x0200 874*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_SOURCE_SINK 0x0400 875*8fb009dcSAndroid Build Coastguard Worker 876*8fb009dcSAndroid Build Coastguard Worker // These are the 'types' of BIOs 877*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_NONE 0 878*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_MEM (1 | BIO_TYPE_SOURCE_SINK) 879*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_FILE (2 | BIO_TYPE_SOURCE_SINK) 880*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_FD (4 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) 881*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_SOCKET (5 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) 882*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_NULL (6 | BIO_TYPE_SOURCE_SINK) 883*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_SSL (7 | BIO_TYPE_FILTER) 884*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_MD (8 | BIO_TYPE_FILTER) 885*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_BUFFER (9 | BIO_TYPE_FILTER) 886*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_CIPHER (10 | BIO_TYPE_FILTER) 887*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_BASE64 (11 | BIO_TYPE_FILTER) 888*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_CONNECT (12 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) 889*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_ACCEPT (13 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) 890*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_PROXY_CLIENT (14 | BIO_TYPE_FILTER) 891*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_PROXY_SERVER (15 | BIO_TYPE_FILTER) 892*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_NBIO_TEST (16 | BIO_TYPE_FILTER) 893*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_NULL_FILTER (17 | BIO_TYPE_FILTER) 894*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_BER (18 | BIO_TYPE_FILTER) // BER -> bin filter 895*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_BIO (19 | BIO_TYPE_SOURCE_SINK) // (half a) BIO pair 896*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_LINEBUFFER (20 | BIO_TYPE_FILTER) 897*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_DGRAM (21 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) 898*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_ASN1 (22 | BIO_TYPE_FILTER) 899*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_COMP (23 | BIO_TYPE_FILTER) 900*8fb009dcSAndroid Build Coastguard Worker 901*8fb009dcSAndroid Build Coastguard Worker // BIO_TYPE_START is the first user-allocated |BIO| type. No pre-defined type, 902*8fb009dcSAndroid Build Coastguard Worker // flag bits aside, may exceed this value. 903*8fb009dcSAndroid Build Coastguard Worker #define BIO_TYPE_START 128 904*8fb009dcSAndroid Build Coastguard Worker 905*8fb009dcSAndroid Build Coastguard Worker struct bio_method_st { 906*8fb009dcSAndroid Build Coastguard Worker int type; 907*8fb009dcSAndroid Build Coastguard Worker const char *name; 908*8fb009dcSAndroid Build Coastguard Worker int (*bwrite)(BIO *, const char *, int); 909*8fb009dcSAndroid Build Coastguard Worker int (*bread)(BIO *, char *, int); 910*8fb009dcSAndroid Build Coastguard Worker // TODO(fork): remove bputs. 911*8fb009dcSAndroid Build Coastguard Worker int (*bputs)(BIO *, const char *); 912*8fb009dcSAndroid Build Coastguard Worker int (*bgets)(BIO *, char *, int); 913*8fb009dcSAndroid Build Coastguard Worker long (*ctrl)(BIO *, int, long, void *); 914*8fb009dcSAndroid Build Coastguard Worker int (*create)(BIO *); 915*8fb009dcSAndroid Build Coastguard Worker int (*destroy)(BIO *); 916*8fb009dcSAndroid Build Coastguard Worker long (*callback_ctrl)(BIO *, int, bio_info_cb); 917*8fb009dcSAndroid Build Coastguard Worker }; 918*8fb009dcSAndroid Build Coastguard Worker 919*8fb009dcSAndroid Build Coastguard Worker struct bio_st { 920*8fb009dcSAndroid Build Coastguard Worker const BIO_METHOD *method; 921*8fb009dcSAndroid Build Coastguard Worker CRYPTO_EX_DATA ex_data; 922*8fb009dcSAndroid Build Coastguard Worker 923*8fb009dcSAndroid Build Coastguard Worker // init is non-zero if this |BIO| has been initialised. 924*8fb009dcSAndroid Build Coastguard Worker int init; 925*8fb009dcSAndroid Build Coastguard Worker // shutdown is often used by specific |BIO_METHOD|s to determine whether 926*8fb009dcSAndroid Build Coastguard Worker // they own some underlying resource. This flag can often by controlled by 927*8fb009dcSAndroid Build Coastguard Worker // |BIO_set_close|. For example, whether an fd BIO closes the underlying fd 928*8fb009dcSAndroid Build Coastguard Worker // when it, itself, is closed. 929*8fb009dcSAndroid Build Coastguard Worker int shutdown; 930*8fb009dcSAndroid Build Coastguard Worker int flags; 931*8fb009dcSAndroid Build Coastguard Worker int retry_reason; 932*8fb009dcSAndroid Build Coastguard Worker // num is a BIO-specific value. For example, in fd BIOs it's used to store a 933*8fb009dcSAndroid Build Coastguard Worker // file descriptor. 934*8fb009dcSAndroid Build Coastguard Worker int num; 935*8fb009dcSAndroid Build Coastguard Worker CRYPTO_refcount_t references; 936*8fb009dcSAndroid Build Coastguard Worker void *ptr; 937*8fb009dcSAndroid Build Coastguard Worker // next_bio points to the next |BIO| in a chain. This |BIO| owns a reference 938*8fb009dcSAndroid Build Coastguard Worker // to |next_bio|. 939*8fb009dcSAndroid Build Coastguard Worker BIO *next_bio; // used by filter BIOs 940*8fb009dcSAndroid Build Coastguard Worker uint64_t num_read, num_write; 941*8fb009dcSAndroid Build Coastguard Worker }; 942*8fb009dcSAndroid Build Coastguard Worker 943*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_CONNECT 100 944*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_DO_STATE_MACHINE 101 945*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_NBIO 102 946*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_PROXY_PARAM 103 947*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_FD 104 948*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_FD 105 949*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_FILE_PTR 106 950*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_FILE_PTR 107 951*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_FILENAME 108 952*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_SSL 109 953*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_MD 111 954*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_MD 112 955*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_CIPHER_STATUS 113 956*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_BUF_MEM 114 957*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_BUF_MEM_PTR 115 958*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_BUFF_NUM_LINES 116 959*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_BUFF_SIZE 117 960*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_ACCEPT 118 961*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SSL_MODE 119 962*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_MD_CTX 120 963*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_PROXY_PARAM 121 964*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_BUFF_READ_DATA 122 // data to read first 965*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_ACCEPT 124 966*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_FILE_SEEK 128 967*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_CIPHER_CTX 129 968*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_BUF_MEM_EOF_RETURN 130 // return end of input value 969*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_BIND_MODE 131 970*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_BIND_MODE 132 971*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_FILE_TELL 133 972*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_SOCKS 134 973*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_SOCKS 135 974*8fb009dcSAndroid Build Coastguard Worker 975*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_WRITE_BUF_SIZE 136 // for BIO_s_bio 976*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_WRITE_BUF_SIZE 137 977*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_WRITE_GUARANTEE 140 978*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_READ_REQUEST 141 979*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SHUTDOWN_WR 142 980*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_NREAD0 143 981*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_NREAD 144 982*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_NWRITE0 145 983*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_NWRITE 146 984*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_RESET_READ_REQUEST 147 985*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_MD_CTX 148 986*8fb009dcSAndroid Build Coastguard Worker 987*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_PREFIX 149 988*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_PREFIX 150 989*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_SUFFIX 151 990*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_SUFFIX 152 991*8fb009dcSAndroid Build Coastguard Worker 992*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_SET_EX_ARG 153 993*8fb009dcSAndroid Build Coastguard Worker #define BIO_C_GET_EX_ARG 154 994*8fb009dcSAndroid Build Coastguard Worker 995*8fb009dcSAndroid Build Coastguard Worker 996*8fb009dcSAndroid Build Coastguard Worker #if defined(__cplusplus) 997*8fb009dcSAndroid Build Coastguard Worker } // extern C 998*8fb009dcSAndroid Build Coastguard Worker 999*8fb009dcSAndroid Build Coastguard Worker extern "C++" { 1000*8fb009dcSAndroid Build Coastguard Worker 1001*8fb009dcSAndroid Build Coastguard Worker BSSL_NAMESPACE_BEGIN 1002*8fb009dcSAndroid Build Coastguard Worker 1003*8fb009dcSAndroid Build Coastguard Worker BORINGSSL_MAKE_DELETER(BIO, BIO_free) 1004*8fb009dcSAndroid Build Coastguard Worker BORINGSSL_MAKE_UP_REF(BIO, BIO_up_ref) 1005*8fb009dcSAndroid Build Coastguard Worker BORINGSSL_MAKE_DELETER(BIO_METHOD, BIO_meth_free) 1006*8fb009dcSAndroid Build Coastguard Worker 1007*8fb009dcSAndroid Build Coastguard Worker BSSL_NAMESPACE_END 1008*8fb009dcSAndroid Build Coastguard Worker 1009*8fb009dcSAndroid Build Coastguard Worker } // extern C++ 1010*8fb009dcSAndroid Build Coastguard Worker 1011*8fb009dcSAndroid Build Coastguard Worker #endif 1012*8fb009dcSAndroid Build Coastguard Worker 1013*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_BAD_FOPEN_MODE 100 1014*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_BROKEN_PIPE 101 1015*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_CONNECT_ERROR 102 1016*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_ERROR_SETTING_NBIO 103 1017*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_INVALID_ARGUMENT 104 1018*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_IN_USE 105 1019*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_KEEPALIVE 106 1020*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_NBIO_CONNECT_ERROR 107 1021*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_NO_HOSTNAME_SPECIFIED 108 1022*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_NO_PORT_SPECIFIED 109 1023*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_NO_SUCH_FILE 110 1024*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_NULL_PARAMETER 111 1025*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_SYS_LIB 112 1026*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_UNABLE_TO_CREATE_SOCKET 113 1027*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_UNINITIALIZED 114 1028*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_UNSUPPORTED_METHOD 115 1029*8fb009dcSAndroid Build Coastguard Worker #define BIO_R_WRITE_TO_READ_ONLY_BIO 116 1030*8fb009dcSAndroid Build Coastguard Worker 1031*8fb009dcSAndroid Build Coastguard Worker #endif // OPENSSL_HEADER_BIO_H 1032