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


C++ BIO_get_mem_ptr函數代碼示例

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


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

示例1: flatten_X509

struct X509_flat *
flatten_X509(X509 *x)
{
	struct X509_flat *out = NULL;
	int ret;
	BUF_MEM *bptr = NULL;
	BIO *mem = NULL;

	if (x == NULL) {
		return NULL;
	}

	mem = BIO_new(BIO_s_mem());
	if (mem == NULL) {
		return NULL;
	}
	ret = PEM_write_bio_X509(mem, x);
	if (ret == 0) {
		BIO_free(mem);
		return NULL;
	}
	out = new_X509_flat();
	if (out == NULL)  {
		BIO_free(mem);
		return NULL;
	}
	BIO_get_mem_ptr(mem, &bptr);
	assert(BIO_set_close(mem, BIO_NOCLOSE) == 1);
	BIO_free(mem);
	out->len = bptr->length;
	if (bptr->length != 0
	    && (size_t) bptr->length <= SIZE_MAX/sizeof(*(out->data))) {
		out->data = malloc(bptr->length*sizeof(*(out->data)));
	}
	if (out->data == NULL) {
		BUF_MEM_free(bptr);
		return NULL;
	}
	memcpy(out->data, bptr->data, bptr->length);
	BUF_MEM_free(bptr);

	return out;
}
開發者ID:Crashdowns,項目名稱:phantom,代碼行數:43,代碼來源:x509_flat.c

示例2: encode_base64

char* encode_base64(unsigned char* data, size_t length) {
    BIO *bmem, *b64;
    BUF_MEM *bufmem;

    b64 = BIO_new(BIO_f_base64());
    bmem = BIO_new(BIO_s_mem());

    b64 = BIO_push(b64, bmem);

    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
    BIO_write(b64, data, length);
    BIO_flush(b64);
    BIO_get_mem_ptr(b64, &bufmem);
    BIO_set_close(b64, BIO_NOCLOSE);
    BIO_free_all(b64);

    return bufmem->data;

}
開發者ID:sfelton,項目名稱:matasano,代碼行數:19,代碼來源:decode_encode.c

示例3: BIO_new

int utils::Base64Encode(const unsigned char* buffer, size_t length, char** b64text) { //Encodes a binary safe base 64 string
	BIO *bio, *b64;
	BUF_MEM *bufferPtr;

	b64 = BIO_new(BIO_f_base64());
	bio = BIO_new(BIO_s_mem());
	bio = BIO_push(b64, bio);

	BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); //Ignore newlines - write everything in one line
	BIO_write(bio, buffer, length);
	BIO_flush(bio);
	BIO_get_mem_ptr(bio, &bufferPtr);
	BIO_set_close(bio, BIO_NOCLOSE);
	BIO_free_all(bio);

	*b64text=(*bufferPtr).data;

	return (0); //success
}
開發者ID:athongintel,項目名稱:irm5-ec_crypto,代碼行數:19,代碼來源:utils.cpp

示例4: LUA_FUNCTION

static LUA_FUNCTION(openssl_pkcs7_decrypt)
{
  PKCS7 *p7 = CHECK_OBJECT(1, PKCS7, "openssl.pkcs7");
  X509 *cert = CHECK_OBJECT(2, X509, "openssl.x509");
  EVP_PKEY *key = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey");
  long flags = luaL_optint(L, 4, 0);
  BIO *out = BIO_new(BIO_s_mem());

  if (PKCS7_decrypt(p7, key, cert, out, flags))
  {
    BUF_MEM* mem;
    BIO_get_mem_ptr(out, &mem);
    lua_pushlstring(L, mem->data, mem->length);
  }
  else
    lua_pushnil(L);
  BIO_free(out);
  return 1;
}
開發者ID:Shaddy1884,項目名稱:lua-openssl,代碼行數:19,代碼來源:pkcs7.c

示例5: b64_encode

//------------------------------------------------------------------------------
// helper function to encode a vector of bytes to a base64 string:
static std::string b64_encode(const std::vector<unsigned char>& data) 
{
   BIO* b64 = BIO_new(BIO_f_base64());
   BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

   BIO* bmem = BIO_new(BIO_s_mem());
   b64 = BIO_push(b64, bmem);
   
   BIO_write(b64, data.data(), data.size());
   BIO_flush(b64);

   BUF_MEM* bptr = NULL;
   BIO_get_mem_ptr(b64, &bptr);
   
   std::string output(bptr->data, bptr->length);
   BIO_free_all(b64);

   return output;
}
開發者ID:CrazyCaptian,項目名稱:Test,代碼行數:21,代碼來源:kclient.cpp

示例6: BIO_new

char *base64(const unsigned char *input, int length)
{
	BIO *bmem, *b64;
	BUF_MEM *bptr;

	b64 = BIO_new(BIO_f_base64());
	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 *)malloc(bptr->length);
	memcpy(buff, bptr->data, bptr->length-1);
	buff[bptr->length-1] = 0;

	BIO_free_all(b64);
	return buff;
}
開發者ID:katmagic,項目名稱:perspectives-notary-server,代碼行數:19,代碼來源:notary_crypto.c

示例7: encode

passwand_error_t encode(const uint8_t *s, size_t len, char **e) {

    assert(s != NULL);
    assert(e != NULL);

    if (len > (size_t)INT_MAX)
        return PW_OVERFLOW;

    /* Create a base64 filter. */
    BIO *b64 __attribute__((cleanup(autobiofree))) = BIO_new(BIO_f_base64());
    if (b64 == NULL)
        return PW_NO_MEM;
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

    /* Create an in-memory sink to encode data into. */
    BIO *out = BIO_new(BIO_s_mem());
    if (out == NULL)
        return PW_NO_MEM;

    BIO *pipe __attribute__((cleanup(autobiofree))) = BIO_push(b64, out);
    b64 = NULL;

    /* Encode the data. */
    if (BIO_write(pipe, s, len) != (int)len)
        return PW_IO;
    BIO_flush(pipe);

    /* Extract it into a string. */
    BUF_MEM *bptr;
    BIO_get_mem_ptr(out, &bptr);

    if (SIZE_MAX - 1 < bptr->length)
        return PW_OVERFLOW;
    *e = malloc(bptr->length + 1);
    if (*e == NULL)
        return PW_NO_MEM;

    memcpy(*e, bptr->data, bptr->length);
    (*e)[bptr->length] = '\0';

    return PW_OK;
}
開發者ID:Smattr,項目名稱:passwand,代碼行數:42,代碼來源:encoding.c

示例8: base_64_encode

//Function to use openssl to do BASE64 encoding
static bool base_64_encode(const uint8_t *in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t *out_size)
{
    BIO* bioMem = NULL;
    bool ret = false;
    BIO *bio64 = NULL;
    BIO_METHOD *bm = BIO_f_base64();
    if(bm == NULL)
        goto ret_point;
    bio64 = BIO_new(bm);
    if(bio64 == NULL) 
        goto ret_point;
    BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
    bm = BIO_s_mem();
    if(bm == NULL)
        goto ret_point;
    bioMem = BIO_new(bm);
    if(bioMem == NULL)
        goto ret_point;
   (void)BIO_push(bio64, bioMem);

    if(BIO_write(bio64, in_buf, in_size) != (int)in_size){
        goto ret_point;
    }
    (void)BIO_flush(bio64);

    BUF_MEM *bptr;
    BIO_get_mem_ptr(bio64, &bptr);
    if(bptr==NULL){
        goto ret_point;
    }
    if(*out_size < bptr->length){
        goto ret_point;
    }
    if(memcpy_s(out_buf, *out_size,bptr->data, bptr->length)!=0)
        goto ret_point;
        
    *out_size = static_cast<uint32_t>(bptr->length);
    ret = true;
ret_point:
    BIO_free_all(bio64);//we need not free bioMem too because the free_all has free it.
    return ret;
}
開發者ID:0-T-0,項目名稱:linux-sgx,代碼行數:43,代碼來源:aesm_encode.cpp

示例9: BIO_new

// ============================================================================
std::string Crypto::base64(const std::vector<uint8_t>& input)
{
    BIO *bmem, *b64;
    BUF_MEM* bptr;
    std::string result;

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

    BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
    BIO_write(b64, input.data(), (int)input.size());
    BIO_flush(b64);
    BIO_get_mem_ptr(b64, &bptr);
    result.resize(bptr->length - 1);
    memcpy(&result[0], bptr->data, bptr->length - 1);
    BIO_free_all(b64);

    return result;
}   // base64
開發者ID:qwertychouskie,項目名稱:stk-code,代碼行數:21,代碼來源:crypto_openssl.cpp

示例10: base64_encode

static int base64_encode(char *str,int str_len,char *encode,int encode_len)
{
      BIO *bmem,*b64;
      BUF_MEM *bptr;
      b64=BIO_new(BIO_f_base64());
      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);
     if(bptr->length>encode_len){
         oss_log_write("encode_len too small\n");
         return -1; 
     }   
     encode_len=bptr->length;
     memcpy(encode,bptr->data,bptr->length);
 //  write(1,encode,bptr->length);
     BIO_free_all(b64);
     return encode_len;
}
開發者ID:xuanya4202,項目名稱:aliyun_oss,代碼行數:20,代碼來源:oss_http_request.c

示例11: encodeBase64

gchar* encodeBase64(gchar *input, gint length) {
    BIO *b64 = BIO_new(BIO_f_base64());
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
    BIO *bmem = BIO_new(BIO_s_mem());

    b64 = BIO_push(b64, bmem);

    BIO_write(b64, input, length);
    BIO_flush(b64);
    BUF_MEM *buffer;
    BIO_get_mem_ptr(b64, &buffer);

    gchar *data = g_malloc(buffer->length);
    memcpy(data, buffer->data, buffer->length - 1);
    data[buffer->length - 1] = 0;

    BIO_free_all(b64);

    return data;
}
開發者ID:houzhenggang,項目名稱:openwrt-ar9331,代碼行數:20,代碼來源:ssl.c

示例12: BIO_new

char *Base64::encode(const char *input, int size)
{
    BIO *bmem, *b64;
    BUF_MEM *bptr;

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

    char *buff = (char *)Memory::Alloc(bptr->length);
    memcpy(buff, bptr->data, bptr->length-1);
    buff[bptr->length-1] = 0;

    BIO_free_all(b64);

    return buff;
}
開發者ID:WizKid,項目名稱:FriBID-windows,代碼行數:20,代碼來源:base64.cpp

示例13: BIO_new

static char *base64(char *str, size_t *len) {
        BIO *b64, *bmem;
        BUF_MEM *bptr;


        b64 = BIO_new(BIO_f_base64());
        bmem = BIO_new(BIO_s_mem());
        b64 = BIO_push(b64, bmem);
        BIO_write(b64, str, *len);
        BIO_flush(b64);
        BIO_get_mem_ptr(b64, &bptr);

        char *buf = malloc(bptr->length-1);
        memcpy(buf, bptr->data, bptr->length-1);
        *len = bptr->length-1;
        BIO_free_all(b64);


        return buf;
}
開發者ID:20tab,項目名稱:blastbeat,代碼行數:20,代碼來源:websocket.c

示例14: SSL_write

std::streamsize Connection::write(const char* buf, std::size_t n)
{
    std::streambuf* sb = _ios->rdbuf();
    if( ! sb)
        return 0;

    std::streamsize written = SSL_write(_ssl, buf, n);
    log_debug("encrypted " << written << " bytes");

    BUF_MEM* bm = 0;
    BIO_get_mem_ptr(_out, &bm);
    if(bm->length > 0)
    {
        sb->sputn(bm->data, bm->length);
        log_debug("wrote " << bm->length << " bytes to output");
        bm->length = 0;
    }

    return written;
}
開發者ID:3Nigma,項目名稱:frayon,代碼行數:20,代碼來源:Connection.cpp

示例15: codec_base64_encode

/**
 * BASE64編碼
 *
 * LUA示例:
 * local codec = require('codec')
 * local bs = [[...]] --源內容
 * local result = codec.base64_encode(bs)
 */
static int codec_base64_encode(lua_State *L)
{
    size_t len;
    const char *bs = luaL_checklstring(L, 1, &len);
    BIO *b64 = BIO_new(BIO_f_base64());
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
    BIO *bio = BIO_new(BIO_s_mem());
    bio = BIO_push(b64, bio);
    BIO_write(bio, bs, len);
    BIO_flush(bio);
    BUF_MEM *p;
    BIO_get_mem_ptr(bio, &p);
    int n = p->length;
    char dst[n];
    memcpy(dst, p->data, n);
    BIO_free_all(bio);

    lua_pushlstring(L, dst, n);
    return 1;
}
開發者ID:mashijie,項目名稱:lua-codec,代碼行數:28,代碼來源:codec.c


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