當前位置: 首頁>>代碼示例>>C++>>正文


C++ BIO_set_flags函數代碼示例

本文整理匯總了C++中BIO_set_flags函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_set_flags函數的具體用法?C++ BIO_set_flags怎麽用?C++ BIO_set_flags使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BIO_set_flags函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: bio_rdp_tls_write

static int bio_rdp_tls_write(BIO* bio, const char* buf, int size)
{
	int status;
	BIO_RDP_TLS* tls = (BIO_RDP_TLS*) bio->ptr;

	if (!buf || !tls)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_WRITE | BIO_FLAGS_READ | BIO_FLAGS_IO_SPECIAL);

	status = SSL_write(tls->ssl, buf, size);

	if (status <= 0)
	{
		switch (SSL_get_error(tls->ssl, status))
		{
			case SSL_ERROR_NONE:
				BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
				break;

			case SSL_ERROR_WANT_WRITE:
				BIO_set_flags(bio, BIO_FLAGS_WRITE);
				break;

			case SSL_ERROR_WANT_READ:
				BIO_set_flags(bio, BIO_FLAGS_READ);
				break;

			case SSL_ERROR_WANT_X509_LOOKUP:
				BIO_set_flags(bio, BIO_FLAGS_IO_SPECIAL);
				bio->retry_reason = BIO_RR_SSL_X509_LOOKUP;
				break;

			case SSL_ERROR_WANT_CONNECT:
				BIO_set_flags(bio, BIO_FLAGS_IO_SPECIAL);
				bio->retry_reason = BIO_RR_CONNECT;
				break;

			case SSL_ERROR_SYSCALL:
				BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
				break;

			case SSL_ERROR_SSL:
				BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
				break;
		}
	}

	return status;
}
開發者ID:nayimsust,項目名稱:FreeRDP,代碼行數:50,代碼來源:tls.c

示例2: b64_encode

ustring
b64_encode (const char *buf, const size_t length)
{
   bool succeeded = false;
   ustring rv;

   auto_BIO mem    (BIO_new (BIO_s_mem ()));
   auto_BIO filter (BIO_new (BIO_f_base64()));

   if (!mem || !filter)
      throw SSL_ERROR;
   
   BIO_set_flags(((BIO *) filter), BIO_FLAGS_BASE64_NO_NL);
   BIO_push  (filter, mem);

   if ((BIO_write (filter, buf, length) >= 0)
       &&
       (1 == BIO_flush (filter)))
   {
      const int to_read = BIO_pending (mem);
      unsigned char *tmp_buf = (unsigned char *) VHTI_alloc (to_read + 1);
      if (BIO_read(mem, tmp_buf, to_read) >= 0)
      {
         tmp_buf[to_read] = '\0';
         rv.assign (tmp_buf);
         succeeded = true;
      }
      free (tmp_buf);
   }

   if (!succeeded)
      throw SSL_ERROR;

   return rv;
}
開發者ID:darg0001,項目名稱:evoting-systems,代碼行數:35,代碼來源:misc.cpp

示例3: s3_base64_encode

gchar*
s3_base64_encode(const GByteArray *to_enc) {
    BIO *bio_b64 = NULL, *bio_buff = NULL;
    long bio_b64_len;
    char *bio_b64_data = NULL, *ret = NULL;
    if (!to_enc) return NULL;

    /* Initialize base64 encoding filter */
    bio_b64 = BIO_new(BIO_f_base64());
    g_assert(bio_b64);
    BIO_set_flags(bio_b64, BIO_FLAGS_BASE64_NO_NL);

    /* Initialize memory buffer for the base64 encoding */
    bio_buff = BIO_new(BIO_s_mem());
    g_assert(bio_buff);
    bio_buff = BIO_push(bio_b64, bio_buff);

    /* Write the MD5 hash into the buffer to encode it in base64 */
    BIO_write(bio_buff, to_enc->data, to_enc->len);
    /* BIO_flush is a macro and GCC 4.1.2 complains without this cast*/
    (void) BIO_flush(bio_buff);

    /* Pull out the base64 encoding of the MD5 hash */
    bio_b64_len = BIO_get_mem_data(bio_buff, &bio_b64_data);
    g_assert(bio_b64_data);
    ret = g_strndup(bio_b64_data, bio_b64_len);

    /* If bio_b64 is freed separately, freeing bio_buff will
     * invalidly free memory and potentially segfault.
     */
    BIO_free_all(bio_buff);
    return ret;
}
開發者ID:TonyChiang,項目名稱:amanda,代碼行數:33,代碼來源:s3-util.c

示例4: transport_bio_simple_write

static int transport_bio_simple_write(BIO* bio, const char* buf, int size)
{
	int error;
	int status = 0;

	if (!buf)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_WRITE);

	status = _send((SOCKET) bio->num, buf, size, 0);

	if (status <= 0)
	{
		error = WSAGetLastError();

		if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
			(error == WSAEINPROGRESS) || (error == WSAEALREADY))
		{
			BIO_set_flags(bio, (BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY));
		}
		else
		{
			BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
		}
	}

	return status;
}
開發者ID:Auto-Droid,項目名稱:FreeRDP,代碼行數:29,代碼來源:tcp.c

示例5: encodeBase64

char* encodeBase64(const char *input, size_t length)
{
  if(length > 0) {
    BIO *bmem, *b64;
    BUF_MEM *bptr;

    b64 = BIO_new(BIO_f_base64());
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
    bmem = BIO_new(BIO_s_mem());
    b64 = BIO_push(b64, bmem);
    BIO_write(b64, input, length);
    BIO_flush(b64);
    BIO_get_mem_ptr(b64, &bptr);

    char *buff = (char *)NFCD_MALLOC(bptr->length+1);
    memcpy(buff, bptr->data, bptr->length);
    buff[bptr->length] = 0;
 
    BIO_free_all(b64);

    return buff;
  } else {
    return "";
  }
}
開發者ID:svic,項目名稱:b2g-nfcd,代碼行數:25,代碼來源:nfcd_util.cpp

示例6: malloc

/* caller must free the returned string */
char *base64_dec(unsigned char *in, int size)
{
  BIO *bio64, *biomem;
  char *buf=NULL;

  buf = malloc(sizeof(char) * size);
  bzero(buf, size);

  if ((bio64 = BIO_new(BIO_f_base64())) == NULL) {
    logprintfl(EUCAERROR, "BIO_new(BIO_f_base64()) failed\n");
  } else {
    BIO_set_flags (bio64, BIO_FLAGS_BASE64_NO_NL); /* no long-line wrapping */

    if ((biomem = BIO_new_mem_buf(in, size)) == NULL) {
      logprintfl(EUCAERROR, "BIO_new_mem_buf() failed\n");
    } else {
      biomem = BIO_push(bio64, biomem);

      if ((BIO_read(biomem, buf, size)) <= 0) {
        logprintfl(EUCAERROR, "BIO_read() read failed\n");
      }
      //      BIO_free_all(biomem);
    }
    BIO_free_all(bio64);
  }

  return buf;
}
開發者ID:chrkl,項目名稱:eucalyptus,代碼行數:29,代碼來源:euca_auth.c

示例7: OT_base64_decode

uint8_t* OT_base64_decode(const char *input, size_t* out_len, int bLineBreaks)
{
    BIO *bmem = NULL, *b64 = NULL;
	
	OT_ASSERT(NULL != input);
	
    int in_len = strlen(input);
    int out_max_len=(in_len*6+7)/8;
    unsigned char *buf = new unsigned char [out_max_len];
	
	OT_ASSERT(NULL != buf);
	
	memset(buf, 0, out_max_len);

	b64 = BIO_new(BIO_f_base64());
	
	if (b64) 
	{
		if (!bLineBreaks) 
		{
			BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
		}
		bmem = BIO_new_mem_buf((char*)input, in_len);
		b64 = BIO_push(b64, bmem);
		*out_len = BIO_read(b64, buf, out_max_len);
		BIO_free_all(b64);
	}
	else 
	{
		OT_ASSERT_MSG(false, "Failed creating new Bio in base64_decode.\n");
	}

    return buf;
}
開發者ID:DOUGLASMENDES,項目名稱:Open-Transactions,代碼行數:34,代碼來源:OTASCIIArmor.cpp

示例8: strlen

uint8_t *base64_dec(char *input, int *outlen) {
  BIO *bmem, *b64;
  int inlen = strlen(input);

  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bmem = BIO_new(BIO_s_mem());
  b64 = BIO_push(b64, bmem);

  // Apple cut the padding off their challenges; restore it
  BIO_write(bmem, input, inlen);
  while (inlen++ & 3)
    BIO_write(bmem, "=", 1);
  BIO_flush(bmem);

  int bufsize = strlen(input) * 3 / 4 + 1;
  uint8_t *buf = malloc(bufsize);
  int nread;

  nread = BIO_read(b64, buf, bufsize);

  BIO_free_all(bmem);

  *outlen = nread;
  return buf;
}
開發者ID:Havelock-Vetinari,項目名稱:shairport-sync,代碼行數:26,代碼來源:common.c

示例9: transport_bio_simple_read

static int transport_bio_simple_read(BIO* bio, char* buf, int size)
{
	int error;
	int status = 0;

	if (!buf)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_READ);

	status = _recv((SOCKET) bio->num, buf, size, 0);
	if (status > 0)
		return status;

	if (status == 0)
	{
		BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
		return 0;
	}

	error = WSAGetLastError();

	if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
		(error == WSAEINPROGRESS) || (error == WSAEALREADY))
	{
		BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
	}
	else
	{
		BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
	}

	return -1;
}
開發者ID:CoryXie,項目名稱:FreeRDP,代碼行數:34,代碼來源:tcp.c

示例10: encode

            void encode(const type& ascii, type& base64) {
                BIO *bio, *b64;
                BUF_MEM *bptr;

                b64 = BIO_new(BIO_f_base64());
                BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
                bio = BIO_new(BIO_s_mem());
                BIO_push(b64, bio);
                BIO_get_mem_ptr(b64, &bptr);

                //Write directly to base64-buffer to avoid copy
                int base64_length=static_cast<int>(round(4*ceil((double)ascii.size()/3.0)));
                base64.resize(base64_length);
                bptr->length=0;
                bptr->max=base64_length+1;
                bptr->data=(char*)&base64[0];

                BIO_write(b64, &ascii[0], static_cast<int>(ascii.size()));
                BIO_flush(b64);

                //To keep &base64[0] through BIO_free_all(b64)
                bptr->length=0;
                bptr->max=0;
                bptr->data=nullptr;

                BIO_free_all(b64);
            }
開發者ID:ddslot-pp2,項目名稱:pay2.io,代碼行數:27,代碼來源:crypto.hpp

示例11: BIO_new

char *base64_decode(const char *str) {

    BIO *bio, *base64_filter, *bio_out;
    char inbuf[512];
    int inlen;
    base64_filter = BIO_new(BIO_f_base64());
    BIO_set_flags(base64_filter, BIO_FLAGS_BASE64_NO_NL);

    bio = BIO_new_mem_buf((void*)str, strlen(str));

    bio = BIO_push(base64_filter, bio);

    bio_out = BIO_new(BIO_s_mem());

    while((inlen = BIO_read(bio, inbuf, 512)) > 0 ) {
        BIO_write(bio_out, inbuf, inlen);
    }

    BIO_flush(bio_out);

    char *new_data;
    long bytes_written = BIO_get_mem_data(bio_out, &new_data);

    BIO_free_all(bio);
    BIO_free_all(bio_out);

    return new_data;
}
開發者ID:linanfang,項目名稱:usage,代碼行數:28,代碼來源:base64.c

示例12: encode

      static std::string encode(const std::string &ascii) noexcept {
        std::string base64;

        BIO *bio, *b64;
        BUF_MEM *bptr = BUF_MEM_new();

        b64 = BIO_new(BIO_f_base64());
        BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
        bio = BIO_new(BIO_s_mem());
        BIO_push(b64, bio);
        BIO_set_mem_buf(b64, bptr, BIO_CLOSE);

        // Write directly to base64-buffer to avoid copy
        auto base64_length = static_cast<size_t>(round(4 * ceil(static_cast<double>(ascii.size()) / 3.0)));
        base64.resize(base64_length);
        bptr->length = 0;
        bptr->max = base64_length + 1;
        bptr->data = &base64[0];

        if(BIO_write(b64, &ascii[0], static_cast<int>(ascii.size())) <= 0 || BIO_flush(b64) <= 0)
          base64.clear();

        // To keep &base64[0] through BIO_free_all(b64)
        bptr->length = 0;
        bptr->max = 0;
        bptr->data = nullptr;

        BIO_free_all(b64);

        return base64;
      }
開發者ID:breezechen,項目名稱:Simple-Web-Server,代碼行數:31,代碼來源:crypto.hpp

示例13: b64_decode

ustring
b64_decode (const ustring &message)
{
   bool succeeded = false;
   auto_BIO mem    (BIO_new (BIO_s_mem ()));
   auto_BIO filter (BIO_new (BIO_f_base64()));
   ustring rv;

   BIO_set_flags(((BIO *) filter), BIO_FLAGS_BASE64_NO_NL);
   BIO_push  (filter, mem);

   if ((BIO_write (mem,
                   message.data (),
                   message.size ()) >= 0)
       &&
       (1 == BIO_flush (mem)))
   {
      const unsigned int Length = BIO_pending (filter);
      {
         unsigned char *tmp_buf = (unsigned char *) VHTI_alloc (Length);
         const int nread = BIO_read(filter, tmp_buf, Length);
         if (nread >= 0)
         {
            succeeded = true;
            rv.assign (tmp_buf, nread);
         }
         free (tmp_buf);
      }
   }

   if (!succeeded)
      throw SSL_ERROR;

   return rv;
}
開發者ID:darg0001,項目名稱:evoting-systems,代碼行數:35,代碼來源:misc.cpp

示例14: rdg_bio_read

static int rdg_bio_read(BIO* bio, char* buf, int size)
{
	int status;
	rdpRdg* rdg = (rdpRdg*) bio->ptr;

	status = rdg_read_data_packet(rdg, (BYTE*) buf, size);

	if (status < 0)
	{
		BIO_clear_retry_flags(bio);
		return -1;
	}
	else if (status == 0)
	{
		BIO_set_retry_read(bio);
		WSASetLastError(WSAEWOULDBLOCK);
		return -1;
	}
	else
	{
		BIO_set_flags(bio, BIO_FLAGS_READ);
	}

	return status;
}
開發者ID:BrianChangchien,項目名稱:FiWoRDC,代碼行數:25,代碼來源:rdg.c

示例15: dtls1_read_failed

int dtls1_read_failed(SSL *s, int code)
	{
	DTLS1_STATE *state;
	BIO *bio;
	int send_alert = 0;

	if ( code > 0)
		{
		fprintf( stderr, "invalid state reached %s:%d", __FILE__, __LINE__);
		return 1;
		}

	bio = SSL_get_rbio(s);
	if ( ! BIO_dgram_recv_timedout(bio))
		{
		/* not a timeout, none of our business, 
		   let higher layers handle this.  in fact it's probably an error */
		return code;
		}

	if ( ! SSL_in_init(s))  /* done, no need to send a retransmit */
		{
		BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);
		return code;
		}

	state = s->d1;
	state->timeout.num_alerts++;
	if ( state->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT)
		{
		/* fail the connection, enough alerts have been sent */
		SSLerr(SSL_F_DTLS1_READ_FAILED,SSL_R_READ_TIMEOUT_EXPIRED);
		return 0;
		}

	state->timeout.read_timeouts++;
	if ( state->timeout.read_timeouts > DTLS1_TMO_READ_COUNT)
		{
		send_alert = 1;
		state->timeout.read_timeouts = 1;
		}


#if 0 /* for now, each alert contains only one record number */
	item = pqueue_peek(state->rcvd_records);
	if ( item )
		{
		/* send an alert immediately for all the missing records */
		}
	else
#endif

#if 0  /* no more alert sending, just retransmit the last set of messages */
		if ( send_alert)
			ssl3_send_alert(s,SSL3_AL_WARNING,
				DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);
#endif

	return dtls1_retransmit_buffered_messages(s) ;
	}
開發者ID:mxOBS,項目名稱:debian_openssl,代碼行數:60,代碼來源:d1_both.c


注:本文中的BIO_set_flags函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。