当前位置: 首页>>代码示例>>C++>>正文


C++ BIO_gets函数代码示例

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


在下文中一共展示了BIO_gets函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: check_padding_and_structure

int check_padding_and_structure(out, length)
{
    pad = out[length - 1];
    if(pad > 16) return -1; // Bad padding byte
    n = length - pad;
    for(i = n; i < length; i++) // check padding
        if(out[i] != pad) return -1;

    /* match structure with known standard structure */
    outfile = BIO_new(BIO_s_mem());
    ASN1_parse(outfile, out, legnth, 0);
    BIO_gets(outfile, (char*)output, N);
    res = memem(output, 128, "SEQUENCE", 8);
    if (!res) goto bad;
    BIO_gets(outfile, (char*)output, N);
    res = memem(output, 128, ":00", 3);
    if (!res) goto bad;
    res = memem(output, 128, "INTEGER", 7);
    if (!res) goto bad;
    BIO_gets(outfile, (char*)output, N);
    res = memem(output, 128, "INTEGER", 7);
    if (!res) goto bad;
    /* now this integer has to be big, check minimum length */
    ul = strlen((char*)res);
    p = res;
    while(*p) {
        if (isspace(*p))
            ul--;
        p++;
    }
    if (ul < 32) goto bad;
    return 0;
bad:
    return -1;
}
开发者ID:kholia,项目名称:thesis,代码行数:35,代码来源:ssh_algorithm.c

示例2: genHumanReadableDateTime

std::string genHumanReadableDateTime(ASN1_TIME* time) {
  BIO* bio_stream = BIO_new(BIO_s_mem());
  if (bio_stream == nullptr) {
    return "";
  }

  // ANS1_TIME_print's format is: Mon DD HH:MM:SS YYYY GMT
  // e.g. Jan 1 00:00:00 1970 GMT (always GMT)
  auto buffer_size = 32;
  char buffer[32] = {0};
  if (!ASN1_TIME_print(bio_stream, time)) {
    BIO_free(bio_stream);
    return "";
  }

  // BIO_gets() returns amount of data successfully read or written
  // (if the return value is positive) or that no data was successfully
  // read or written if the result is 0 or -1.
  if (BIO_gets(bio_stream, buffer, buffer_size) <= 0) {
    BIO_free(bio_stream);
    return "";
  }
  BIO_free(bio_stream);
  return std::string(buffer);
}
开发者ID:huamichaelchen,项目名称:osquery,代码行数:25,代码来源:keychain_utils.cpp

示例3: asn1_bio_gets

static int asn1_bio_gets(BIO *b, char *str, int size)
{
    BIO *next = BIO_next(b);
    if (next == NULL)
        return 0;
    return BIO_gets(next, str, size);
}
开发者ID:Bilibili,项目名称:openssl,代码行数:7,代码来源:bio_asn1.c

示例4: main

int main(int argc, char *argv[]) {
  BIO *bio_stdin, *bio_md5;
  unsigned char buf[512], mdBuf[EVP_MAX_MD_SIZE];
  int i, mdLength;

  /* Create a BIO objects */
  bio_stdin  = BIO_new_fp(stdin,  BIO_NOCLOSE);

  /* Create a base64 filter and connect it to the bio_stdin */
  bio_md5 = BIO_new(BIO_f_md());
  BIO_set_md(bio_md5, EVP_md5());
  bio_stdin = BIO_push(bio_md5, bio_stdin);

  /* Read from bio_stdin, and compute the hash as a side effect. */
  while(BIO_read(bio_stdin, buf, 512) > 0) {
  } /* end while */

  /* Now extract the hash via BIO_gets (which is kinda odd really). */
  mdLength = BIO_gets(bio_md5, (char *)mdBuf, EVP_MAX_MD_SIZE);
  for(i=0; i<mdLength; i++) 
    printf("%02x", (unsigned int)(mdBuf[i]));
  printf("\n");

  BIO_free_all(bio_stdin);    

  return 0;
} /* end func main */
开发者ID:Wushaowei001,项目名称:CodeExamples,代码行数:27,代码来源:bio_dgst.c

示例5: throw

/**
 * Converts X509_NAME struct to string.
 *
 * @param name X509_NAME struct that is converted to string.
 * @return converted value of X509_NAME.
 * @throws IOException throws exception if conversion failed.
 */
std::string digidoc::X509Cert::toString(X509_NAME* name) throw(IOException)
{
    BIO* mem = BIO_new(BIO_s_mem()); BIO_scope memScope(&mem);
    if(mem == NULL)
    {
        THROW_IOEXCEPTION("Failed to allocate memory for X509_NAME conversion: %s", ERR_reason_error_string(ERR_get_error()));
    }

    // Convert the X509_NAME struct to string.
    if(X509_NAME_print_ex(mem, name, 0, XN_FLAG_RFC2253) < 0)
    {
        THROW_IOEXCEPTION("Failed to convert X509_NAME struct to string: %s", ERR_reason_error_string(ERR_get_error()));
    }

    // Read the converted string from buffer.
    char buf[128];
    int bytesRead;
    std::string str;
    while((bytesRead = BIO_gets(mem, &buf[0], sizeof(buf))) > 0)
    {
        str.append(buf);
    }

    return str;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:32,代码来源:X509Cert.cpp

示例6: linebuffer_gets

static int
linebuffer_gets(BIO *b, char *buf, int size)
{
	if (b->next_bio == NULL)
		return (0);
	return (BIO_gets(b->next_bio, buf, size));
}
开发者ID:jmhodges,项目名称:libssl,代码行数:7,代码来源:bf_lbuf.c

示例7: LUA_FUNCTION

static LUA_FUNCTION(openssl_bio_gets)
{
  BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio");
  int len = luaL_optint(L, 2, BIO_pending(bio));
  char* buf;
  int ret = 1;
  len = len > 0 ? len : 1024;

  buf = malloc(len);
  len = BIO_gets(bio, buf, len);
  if (len > 0)
  {
    lua_pushlstring(L, buf, len);
    ret = 1;
  }
  else if (BIO_should_retry(bio))
  {
    lua_pushstring(L, "");
    ret = 1;
  }
  else
  {
    lua_pushnil(L);
    lua_pushinteger(L, len);
    ret = 2;
  };
  free(buf);
  return ret;
}
开发者ID:Shaddy1884,项目名称:lua-openssl,代码行数:29,代码来源:bio.c

示例8: nullf_gets

static int
nullf_gets(BIO *bp, char *buf, int size)
{
	if (bp->next_bio == NULL)
		return (0);
	return (BIO_gets(bp->next_bio, buf, size));
}
开发者ID:awakecoding,项目名称:libressl,代码行数:7,代码来源:bf_null.c

示例9: convertAsn1ToString

int convertAsn1ToString(ASN1_TIME *notAfter, char buffer[]) {
	BIO *bio = BIO_new(BIO_s_mem());
	ASN1_TIME_print(bio, notAfter);
	BIO_gets(bio, buffer, BUFLEN);
	BIO_free(bio);
	return 0;
}
开发者ID:alexanderteves,项目名称:sslexpiry,代码行数:7,代码来源:main.c

示例10: receiveFile

int receiveFile(char *socket, char *outfile)
{
  BIO *receive = BIO_new_accept(socket);
  BIO *fileout = BIO_new_file(outfile,"w");
  
  // it seems you need to do this twice.. not sure why, but we do
  // guess I'll try figure out why at some point
  if (BIO_do_accept(receive) <= 0) {
    fprintf(stderr, "Error setting up accept\n");
    exit(0);
  }
  if (BIO_do_accept(receive) <= 0) {
    fprintf(stderr, "Error setting up accept\n");
    exit(0);
  }


  char tmpbuf[BUFSIZ];

  // magic wrapper
  BIO *bufbio = BIO_new(BIO_f_buffer());
  BIO_push(bufbio, receive);

  //read in the file length and store
  BIO_gets(bufbio, tmpbuf, BUFSIZ);
  printf("Getting file length: %s\n", tmpbuf);

  unsigned int size = atoi(tmpbuf);

  transmit(bufbio, fileout, size);

  BIO_flush(fileout);
  BIO_free(bufbio);
  return 1;
}
开发者ID:eltommo,项目名称:licenceliber,代码行数:35,代码来源:transmit.c

示例11: replace_gets

static int replace_gets(BIO *bp, char *buf, int size) {
   //DEBUG_MSG(D_DEBUG, "%s", __FUNCTION__);

   if (bp->next_bio == NULL)
      return (0);

   return (BIO_gets(bp->next_bio, buf, size));
}
开发者ID:BwRy,项目名称:vector-ipa,代码行数:8,代码来源:bio_replacer.c

示例12: rsa_privatekey_to_pem

/* 
 * Takes in an RSA object and PEM encodes it in out
 * @param key: the RSA private key
 * @param out: the string the PEM encoding goes to
 * @param pem_password: the password to unlock the pem encoding
 * @return: the length of the PEM encoding
 */
unsigned int rsa_privatekey_to_pem(RSA *key, unsigned char **out, unsigned char *password) {
    BIO *pubKey = BIO_new(BIO_s_mem());

    PEM_write_bio_RSAPrivateKey(pubKey, key, NULL, NULL, 0, NULL, NULL);

    unsigned char line[65];
    int len = 0;
    unsigned char *pem = NULL;
    unsigned char *new_pem = NULL;

    if (!BIO_eof(pubKey)) {
        BIO_gets(pubKey, line, sizeof *pubKey);

        len += strlen(line);

        new_pem = (unsigned char *)realloc(pem, len*sizeof(unsigned char));
        if (!new_pem) {
            printf("realloc failed at length:%d\n", len);
        } else {
            memcpy(new_pem, "-----BEGIN PRIVATE KEY-----\n", (size_t)len);
            pem = new_pem;
        }
    }

    while (!BIO_eof(pubKey)) {
        BIO_gets(pubKey, line, sizeof *pubKey);

        //  current length of PEM (including newlines)
        len += strlen(line);

        new_pem = (unsigned char *)realloc(pem, len*sizeof(unsigned char));
        if (!new_pem) {
            printf("realloc failed at length:%d\n", len);
            exit(EXIT_FAILURE);
        } else {
            memcpy(new_pem, strcat(new_pem, line), (size_t)len);
            pem = new_pem;
        }
    }

    *out = pem;

    return len;
}
开发者ID:mroseman95,项目名称:Crypto-Plugin,代码行数:51,代码来源:encrypt.c

示例13: do_fp

void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
			EVP_PKEY *key, unsigned char *sigin, int siglen)
	{
	int len;
	int i;

	for (;;)
		{
		i=BIO_read(bp,(char *)buf,BUFSIZE);
		if (i <= 0) break;
		}
	if(sigin)
		{
		EVP_MD_CTX *ctx;
		BIO_get_md_ctx(bp, &ctx);
		i = EVP_VerifyFinal(ctx, sigin, (unsigned int)siglen, key); 
		if(i > 0) BIO_printf(out, "Verified OK\n");
		else if(i == 0) BIO_printf(out, "Verification Failure\n");
		else
			{
			BIO_printf(bio_err, "Error Verifying Data\n");
			ERR_print_errors(bio_err);
			}
		return;
		}
	if(key)
		{
		EVP_MD_CTX *ctx;
		BIO_get_md_ctx(bp, &ctx);
		if(!EVP_SignFinal(ctx, buf, (unsigned int *)&len, key)) 
			{
			BIO_printf(bio_err, "Error Signing Data\n");
			ERR_print_errors(bio_err);
			return;
			}
		}
	else
		len=BIO_gets(bp,(char *)buf,BUFSIZE);

	if(binout) BIO_write(out, buf, len);
	else 
		{
		for (i=0; i<len; i++)
			{
			if (sep && (i != 0))
				BIO_printf(out, ":");
			BIO_printf(out, "%02x",buf[i]);
			}
		BIO_printf(out, "\n");
		}
	}
开发者ID:jhbsz,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:51,代码来源:dgst.c

示例14: main

main() {
BIO *mem;
int ret;

ERR_load_BIO_strings();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();

mem = BIO_new(BIO_s_mem());

// Example - 1: Write into Buffer
// BIO_puts writes a NULL terminated string into memory
BIO_puts(mem, "Hello Aseem Sethi");  // BIO_puts points to mem_write

// Read the buffer back via BIO_gets()
BUF_MEM *bufMem;
char data[100], data1[100];
ret = BIO_gets(mem, data, 100);  // points to mem_gets =>mem_read
printf("\nBuffer Read Data: ret=%d: %s", ret, data);

//Try to Read the data again. Data once read is deleted
ret = BIO_gets(mem, data1, 100); // result is always null terminated
printf("\nBuffer Read Data Again: ret=%d: %s", ret, data1);
printf("\n..........................");

// Example - 2: Write into Buffer
BIO_puts(mem, "Bye..");  // points to mem_write

// Read the buffer back via BIO_get_mem_data()
// This is not null terminated. Read only what you need.
char *buff = NULL;
size_t len = BIO_get_mem_data(mem, &buff);
printf("\nBuffer Read Data via get_mem_data: length=%d: %.*s", len, len, buff);
printf("\n strlen: %d", strlen(buff));
printf("\n..........................\n");
}
开发者ID:aseemsethi,项目名称:openssl-api,代码行数:36,代码来源:mem.c

示例15: _mongoc_ssl_extract_subject

char *
_mongoc_ssl_extract_subject (const char *filename)
{
   X509_NAME *subject = NULL;
   X509 *cert = NULL;
   BIO *certbio = NULL;
   BIO *strbio = NULL;
   char *str = NULL;
   int ret;

   if (!filename) {
      return NULL;
   }

   certbio = BIO_new (BIO_s_file ());
   strbio = BIO_new (BIO_s_mem ());;

   BSON_ASSERT (certbio);
   BSON_ASSERT (strbio);

   BIO_read_filename (certbio, filename);

   if ((cert = PEM_read_bio_X509 (certbio, NULL, 0, NULL))) {
      if ((subject = X509_get_subject_name (cert))) {
         ret = X509_NAME_print_ex (strbio, subject, 0, XN_FLAG_RFC2253);

         if ((ret > 0) && (ret < INT_MAX)) {
            str = bson_malloc (ret + 2);
            BIO_gets (strbio, str, ret + 1);
            str [ret] = '\0';
         }
      }
   }

   if (cert) {
      X509_free (cert);
   }

   if (certbio) {
      BIO_free (certbio);
   }

   if (strbio) {
      BIO_free (strbio);
   }

   return str;
}
开发者ID:TylerBrock,项目名称:mongo-c-driver,代码行数:48,代码来源:mongoc-ssl.c


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