• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ BIO_set_flags函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中BIO_set_flags函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_set_flags函数的具体用法?C++ BIO_set_flags怎么用?C++ BIO_set_flags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BIO_set_flags函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: memset

void LoginSession::StartSsoLogin(XMLPacket *Packet)
{
    rapidxml::xml_node<>* requestNode = Packet->m_XMLDocument.first_node("Request");

    char password[1024];
    memset(password, 0, 1024);
    int passwordLength = -1;

    char* username = nullptr;
    char* passwordBase64 = nullptr;

    try {
        username = requestNode->first_node("LoginName")->value();
        if (requestNode->first_node("Password") != nullptr) {
            passwordBase64 = requestNode->first_node("Password")->value();
            auto    bio = BIO_new_mem_buf(passwordBase64, -1);
            auto    b64 = BIO_new(BIO_f_base64());
                    bio = BIO_push(b64, bio);

            BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
            passwordLength = BIO_read(bio, password, strlen(passwordBase64));
            BIO_free_all(bio);
        }
    }
    catch(std::exception ex)
    {
        printf("Password tokens not supported.\n");
        return;
    }

    // TODO: add support for resume tokens
    if (passwordBase64 == nullptr) {
        printf("Resume tokens not supported yet\n");
        m_TSLReady = false;
        return;
    }

    printf("Login >> %s with %s\n", username, password);
    int sequence = Packet->m_Meta[2] - '0';

    const char* temporary_guid = "0687C32C-0331-E611-80C3-ECB1D78A5C75";
    const char* temporary_resumeToken = "22236HTR-CCCC-CCCC-CCCC-2310CCCCC93A";
    const char* temporary_username = "nomelx.devel";

    GW2Packet replyPacket("", sequence, PT_REPLY);
    replyPacket.AddElement("UserId", temporary_guid);
    replyPacket.AddElement("UserCenter", "5");
    replyPacket.AddElement("UserName", temporary_username);
    replyPacket.AddElement("Parts", "");
    replyPacket.AddElement("ResumeToken", temporary_resumeToken);
    replyPacket.AddElement("EmailVerified", "1");


    SessionSendPacket packet;
    memset(packet.m_TLSSendBuffer, 0, 4096);
    sprintf(packet.m_TLSSendBuffer, replyPacket.Payload());
    packet.m_TLSSendBufferLength = strlen(packet.m_TLSSendBuffer);
    packet.m_TLSSendNeeded = true;
    m_SendPackets.push_back(packet);
}
开发者ID:nomelx,项目名称:GW2SEX,代码行数:60,代码来源:loginsession.cpp


示例17: rd_base64_decode

/**
 * @brief Base64 decode input string \p in of size \p insize.
 * @returns -1 on invalid Base64, or 0 on successes in which case a
 *         newly allocated binary string is set in out (and size).
 */
static int rd_base64_decode (const rd_chariov_t *in, rd_chariov_t *out) {
        size_t asize;
        BIO *b64, *bmem;

        if (in->size == 0 || (in->size % 4) != 0)
                return -1;

        asize = (in->size * 3) / 4; /* allocation size */
        out->ptr = rd_malloc(asize+1);

        b64 = BIO_new(BIO_f_base64());
        BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

        bmem = BIO_new_mem_buf(in->ptr, (int)in->size);
        bmem = BIO_push(b64, bmem);

        out->size = BIO_read(bmem, out->ptr, (int)asize+1);
        assert(out->size <= asize);
        BIO_free_all(bmem);

#if ENABLE_DEVEL
        /* Verify that decode==encode */
        {
                char *encoded = rd_base64_encode(out);
                assert(strlen(encoded) == in->size);
                assert(!strncmp(encoded, in->ptr, in->size));
                rd_free(encoded);
        }
#endif

        return 0;
}
开发者ID:eugpermar,项目名称:librdkafka,代码行数:37,代码来源:rdkafka_sasl_scram.c


示例18: base64_encode

/*
 * des - base64编码,将二进制字符与64个可打印字符进行对应转化。 2^6 = 64,6bits对应一个字符,三个字节对应四个可见字符
 * param - str : 需编码的数据
 *		   str_len : str的长度
 *		   encode : 编码后数据存储
 *		   encode_len : encode缓冲区的长度,要求大小需大于str_len,建议为(str_len/3) * 4 + 8
 * ret - success : 编码后数据实际长度
 * 		 fail : -1
 */
int base64_encode(char *str,int str_len,char *encode, u_int encode_len)
{
	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, str, str_len); //encode
	BIO_flush(b64);
	BIO_get_mem_ptr(b64,&bptr);

//	printf("%d\n", bptr->length);

	if(bptr->length > encode_len){
		 printf("encode_len too small\n");
		 return -1; 
	}   

	encode_len=bptr->length;
	memcpy(encode,bptr->data,bptr->length);
	encode[bptr->length] = '\0';
	BIO_free_all(b64);

	return encode_len;
}
开发者ID:misslio,项目名称:lctools,代码行数:37,代码来源:aes_base64.c


示例19: base64_enc

/* caller must free the returned string */
char * base64_enc (unsigned char * in, int size)
{
  char * out_str = NULL;
  BIO * biomem, * bio64;
  
  if ( (bio64 = BIO_new (BIO_f_base64 ())) == NULL) {
    logprintfl (EUCAERROR, "error: 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 (BIO_s_mem ())) == NULL) {
      logprintfl (EUCAERROR, "error: BIO_new(BIO_s_mem()) failed\n");
    } else {
      bio64 = BIO_push (bio64, biomem);
      if ( BIO_write (bio64, in, size)!=size) {
	logprintfl (EUCAERROR, "error: BIO_write() failed\n");
      } else {
	BUF_MEM * buf;
	(void) BIO_flush (bio64);
	BIO_get_mem_ptr (bio64, &buf);
	if ( (out_str = malloc(buf->length+1)) == NULL ) {
	  logprintfl (EUCAERROR, "error: out of memory for Base64 buf\n");
	} else {
	  memcpy (out_str, buf->data, buf->length);
	  out_str [buf->length] = '\0';
	}
      }
    }
    BIO_free_all (bio64); /* frees both bio64 and biomem */
  }
  return out_str;
}
开发者ID:chrkl,项目名称:eucalyptus,代码行数:32,代码来源:euca_auth.c


示例20: BIO_new

static char *base64(const char *bytes, size_t len)
{
	BIO *memory, *b64;
	BUF_MEM *buffer;
	char *output;

	b64 = BIO_new(BIO_f_base64());
	BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
	memory = BIO_new(BIO_s_mem());
	if (!b64 || !memory)
		goto error;
	b64 = BIO_push(b64, memory);
	if (!b64)
		goto error;
	if (BIO_write(b64, bytes, len) < 0 || BIO_flush(b64) < 0)
		goto error;

	BIO_get_mem_ptr(b64, &buffer);
	output = xmalloc(buffer->length + 1);
	memcpy(output, buffer->data, buffer->length);
	output[buffer->length] = '\0';

	BIO_free_all(b64);
	return output;

error:
	die("Could not base64 the given bytes.");
}
开发者ID:TonyAbell,项目名称:lastpass-cli,代码行数:28,代码来源:cipher.c



注:本文中的BIO_set_flags函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BIO_set_fp函数代码示例发布时间:2022-05-30
下一篇:
C++ BIO_set_fd函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap