本文整理汇总了C++中read_binary_file函数的典型用法代码示例。如果您正苦于以下问题:C++ read_binary_file函数的具体用法?C++ read_binary_file怎么用?C++ read_binary_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_binary_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: gnutls_certificate_set_openpgp_key_file2
/**
* gnutls_certificate_set_openpgp_key_file2 - Used to set OpenPGP keys
* @res: the destination context to save the data.
* @certfile: the file that contains the public key.
* @keyfile: the file that contains the secret key.
* @subkey_id: a hex encoded subkey id
* @format: the format of the keys
*
* This funtion is used to load OpenPGP keys into the GnuTLS credential
* structure. The files should contain non encrypted keys.
*
* The special keyword "auto" is also accepted as @subkey_id. In that
* case the gnutls_openpgp_crt_get_auth_subkey() will be used to
* retrieve the subkey.
*
* Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
* negative error value.
*
* Since: 2.4.0
**/
int
gnutls_certificate_set_openpgp_key_file2 (gnutls_certificate_credentials_t res,
const char *certfile,
const char *keyfile,
const char *subkey_id,
gnutls_openpgp_crt_fmt_t format)
{
struct stat statbuf;
gnutls_datum_t key, cert;
int rc;
size_t size;
if (!res || !keyfile || !certfile)
{
gnutls_assert ();
return GNUTLS_E_INVALID_REQUEST;
}
if (stat (certfile, &statbuf) || stat (keyfile, &statbuf))
{
gnutls_assert ();
return GNUTLS_E_FILE_ERROR;
}
cert.data = read_binary_file (certfile, &size);
cert.size = (unsigned int) size;
if (cert.data == NULL)
{
gnutls_assert ();
return GNUTLS_E_FILE_ERROR;
}
key.data = read_binary_file (keyfile, &size);
key.size = (unsigned int) size;
if (key.data == NULL)
{
gnutls_assert ();
free (cert.data);
return GNUTLS_E_FILE_ERROR;
}
rc =
gnutls_certificate_set_openpgp_key_mem2 (res, &cert, &key, subkey_id,
format);
free (cert.data);
free (key.data);
if (rc < 0)
{
gnutls_assert ();
return rc;
}
return 0;
}
开发者ID:ystk,项目名称:debian-gnutls26,代码行数:76,代码来源:gnutls_openpgp.c
示例2: gnutls_x509_trust_list_add_trust_file
/**
* gnutls_x509_trust_list_add_trust_file:
* @list: The structure of the list
* @ca_file: A file containing a list of CAs (optional)
* @crl_file: A file containing a list of CRLs (optional)
* @type: The format of the certificates
* @tl_flags: GNUTLS_TL_*
* @tl_vflags: gnutls_certificate_verify_flags if flags specifies GNUTLS_TL_VERIFY_CRL
*
* This function will add the given certificate authorities
* to the trusted list. pkcs11 URLs are also accepted, instead
* of files, by this function.
*
* Returns: The number of added elements is returned.
*
* Since: 3.1
**/
int
gnutls_x509_trust_list_add_trust_file(gnutls_x509_trust_list_t list,
const char* ca_file,
const char* crl_file,
gnutls_x509_crt_fmt_t type,
unsigned int tl_flags,
unsigned int tl_vflags)
{
gnutls_datum_t cas = { NULL, 0 };
gnutls_datum_t crls = { NULL, 0 };
size_t size;
int ret;
#ifdef ENABLE_PKCS11
if (strncmp (ca_file, "pkcs11:", 7) == 0)
{
ret = import_pkcs11_url(list, ca_file, tl_flags);
if (ret < 0)
return gnutls_assert_val(ret);
}
else
#endif
{
cas.data = (void*)read_binary_file (ca_file, &size);
if (cas.data == NULL)
{
gnutls_assert ();
return GNUTLS_E_FILE_ERROR;
}
cas.size = size;
}
if (crl_file)
{
crls.data = (void*)read_binary_file (crl_file, &size);
if (crls.data == NULL)
{
gnutls_assert ();
return GNUTLS_E_FILE_ERROR;
}
crls.size = size;
}
ret = gnutls_x509_trust_list_add_trust_mem(list, &cas, &crls, type, tl_flags, tl_vflags);
free(crls.data);
free(cas.data);
return ret;
}
开发者ID:frankmorgner,项目名称:gnutls,代码行数:66,代码来源:verify-high2.c
示例3: load_ca_private_key
/* Load the CA's private key.
*/
gnutls_privkey_t
load_ca_private_key (common_info_st * info)
{
gnutls_privkey_t key;
gnutls_datum_t dat;
size_t size;
if (info->ca_privkey == NULL)
error (EXIT_FAILURE, 0, "missing --load-ca-privkey");
if (gnutls_url_is_supported(info->ca_privkey) != 0)
return _load_url_privkey(info->ca_privkey);
dat.data = (void*)read_binary_file (info->ca_privkey, &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-ca-privkey: %s",
info->ca_privkey);
key = _load_privkey(&dat, info);
free (dat.data);
return key;
}
开发者ID:nobled,项目名称:gnutls,代码行数:28,代码来源:certtool-common.c
示例4: verify_response
static void verify_response(gnutls_datum_t *nonce)
{
gnutls_datum_t dat;
size_t size;
gnutls_x509_crt_t signer;
int v;
if (HAVE_OPT(LOAD_RESPONSE))
dat.data =
(void *) read_binary_file(OPT_ARG(LOAD_RESPONSE),
&size);
else
dat.data = (void *) fread_file(infile, &size);
if (dat.data == NULL) {
fprintf(stderr, "error reading response\n");
exit(1);
}
dat.size = size;
signer = load_signer();
v = _verify_response(&dat, nonce, signer);
if (v && !HAVE_OPT(IGNORE_ERRORS))
exit(1);
}
开发者ID:ffmpeg-build-win,项目名称:gnutls,代码行数:25,代码来源:ocsptool.c
示例5: gnutls_certificate_set_openpgp_keyring_file
/**
* gnutls_certificate_set_openpgp_keyring_file - Sets a keyring file for OpenPGP
* @c: A certificate credentials structure
* @file: filename of the keyring.
* @format: format of keyring.
*
* The function is used to set keyrings that will be used internally
* by various OpenPGP functions. For example to find a key when it
* is needed for an operations. The keyring will also be used at the
* verification functions.
*
* Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
* negative error value.
**/
int
gnutls_certificate_set_openpgp_keyring_file (gnutls_certificate_credentials_t c,
const char *file,
gnutls_openpgp_crt_fmt_t format)
{
gnutls_datum_t ring;
size_t size;
int rc;
if (!c || !file)
{
gnutls_assert ();
return GNUTLS_E_INVALID_REQUEST;
}
ring.data = read_binary_file (file, &size);
ring.size = (unsigned int) size;
if (ring.data == NULL)
{
gnutls_assert ();
return GNUTLS_E_FILE_ERROR;
}
rc =
gnutls_certificate_set_openpgp_keyring_mem (c, ring.data, ring.size,
format);
free (ring.data);
return rc;
}
开发者ID:ystk,项目名称:debian-gnutls26,代码行数:45,代码来源:gnutls_openpgp.c
示例6: basepath
QueryEngine::QueryEngine(const char * filepath){
//Create filepaths
std::string basepath(filepath);
std::string path_to_hashtable = basepath + "/probing_hash.dat";
std::string path_to_data_bin = basepath + "/binfile.dat";
std::string path_to_vocabid = basepath + "/vocabid.dat";
//Read config file
std::string line;
std::ifstream config ((basepath + "/config").c_str());
getline(config, line);
int tablesize = atoi(line.c_str()); //Get tablesize.
getline(config, line);
largest_entry = atoi(line.c_str()); //Set largest_entry.
config.close();
//Mmap binary table
struct stat filestatus;
stat(path_to_data_bin.c_str(), &filestatus);
binary_filesize = filestatus.st_size;
binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);
//Read hashtable
size_t table_filesize = Table::Size(tablesize, 1.2);
mem = readTable(path_to_hashtable.c_str(), table_filesize);
Table table_init(mem, table_filesize);
table = table_init;
//Read vocabid
read_map(&vocabids, path_to_vocabid.c_str());
std::cout << "Initialized successfully! " << std::endl;
}
开发者ID:hieuhoang,项目名称:proj4,代码行数:35,代码来源:quering.cpp
示例7: load_cert
static gnutls_x509_crt_t
load_cert (const char *cert_file)
{
gnutls_x509_crt_t crt;
int ret;
gnutls_datum_t data;
size_t size;
ret = gnutls_x509_crt_init (&crt);
if (ret < 0)
exit (1);
data.data = (void *) read_binary_file (cert_file, &size);
data.size = size;
if (!data.data)
{
fprintf (stderr, "Cannot open file: %s\n", cert_file);
exit (1);
}
ret = gnutls_x509_crt_import (crt, &data, GNUTLS_X509_FMT_PEM);
free (data.data);
if (ret < 0)
{
fprintf (stderr, "Cannot import certificate in %s: %s\n",
cert_file, gnutls_strerror (ret));
exit (1);
}
return crt;
}
开发者ID:frankmorgner,项目名称:gnutls,代码行数:32,代码来源:ex-ocsp-client.c
示例8: load_ca_private_key
/* Load the CA's private key.
*/
gnutls_privkey_t
load_ca_private_key (common_info_st * info)
{
gnutls_privkey_t key;
gnutls_datum_t dat;
size_t size;
if (info->ca_privkey == NULL)
error (EXIT_FAILURE, 0, "missing --load-ca-privkey");
#ifdef ENABLE_PKCS11
if (strncmp(info->ca_privkey, "pkcs11:", 7) == 0)
return _load_pkcs11_privkey(info->ca_privkey);
#endif
dat.data = read_binary_file (info->ca_privkey, &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-ca-privkey: %s",
info->ca_privkey);
key = _load_privkey(&dat, info);
free (dat.data);
return key;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:30,代码来源:certtool-common.c
示例9: load_ca_cert
/* Loads the CA's certificate
*/
gnutls_x509_crt_t
load_ca_cert (common_info_st * info)
{
gnutls_x509_crt_t crt;
int ret;
gnutls_datum_t dat;
size_t size;
if (info->ca == NULL)
error (EXIT_FAILURE, 0, "missing --load-ca-certificate");
ret = gnutls_x509_crt_init (&crt);
if (ret < 0)
error (EXIT_FAILURE, 0, "crt_init: %s", gnutls_strerror (ret));
dat.data = read_binary_file (info->ca, &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-ca-certificate: %s",
info->ca);
ret = gnutls_x509_crt_import (crt, &dat, info->incert_format);
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing --load-ca-certificate: %s: %s",
info->ca, gnutls_strerror (ret));
return crt;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:32,代码来源:certtool-common.c
示例10: request_info
static void
request_info (void)
{
gnutls_ocsp_req_t req;
int ret;
gnutls_datum_t dat;
size_t size;
ret = gnutls_ocsp_req_init (&req);
if (ret < 0)
error (EXIT_FAILURE, 0, "ocsp_req_init: %s", gnutls_strerror (ret));
if (HAVE_OPT(LOAD_REQUEST))
dat.data = (void*)read_binary_file (OPT_ARG(LOAD_REQUEST), &size);
else
dat.data = (void*)fread_file (infile, &size);
if (dat.data == NULL)
error (EXIT_FAILURE, errno, "reading request");
dat.size = size;
ret = gnutls_ocsp_req_import (req, &dat);
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing request: %s", gnutls_strerror (ret));
ret = gnutls_ocsp_req_print (req, GNUTLS_OCSP_PRINT_FULL, &dat);
if (ret != 0)
error (EXIT_FAILURE, 0, "ocsp_req_print: %s", gnutls_strerror (ret));
printf ("%.*s", dat.size, dat.data);
gnutls_free (dat.data);
gnutls_ocsp_req_deinit (req);
}
开发者ID:frankmorgner,项目名称:gnutls,代码行数:34,代码来源:ocsptool.c
示例11: load_request
/* Load the Certificate Request.
*/
gnutls_x509_crq_t
load_request (common_info_st * info)
{
gnutls_x509_crq_t crq;
int ret;
gnutls_datum_t dat;
size_t size;
if (!info->request)
return NULL;
ret = gnutls_x509_crq_init (&crq);
if (ret < 0)
error (EXIT_FAILURE, 0, "crq_init: %s", gnutls_strerror (ret));
dat.data = read_binary_file (info->request, &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-request: %s", info->request);
ret = gnutls_x509_crq_import (crq, &dat, info->incert_format);
if (ret == GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR)
{
error (EXIT_FAILURE, 0,
"import error: could not find a valid PEM header");
}
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing --load-request: %s: %s",
info->request, gnutls_strerror (ret));
return crq;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:37,代码来源:certtool-common.c
示例12: load_ca_private_key
/* Load the CA's private key.
*/
gnutls_privkey_t load_ca_private_key(common_info_st * info)
{
gnutls_privkey_t key;
gnutls_datum_t dat;
size_t size;
if (info->ca_privkey == NULL) {
fprintf(stderr, "missing --load-ca-privkey\n");
exit(1);
}
if (gnutls_url_is_supported(info->ca_privkey) != 0)
return _load_url_privkey(info->ca_privkey);
dat.data = (void *) read_binary_file(info->ca_privkey, &size);
dat.size = size;
if (!dat.data) {
fprintf(stderr, "reading --load-ca-privkey: %s\n",
info->ca_privkey);
exit(1);
}
key = _load_privkey(&dat, info);
free(dat.data);
return key;
}
开发者ID:randombit,项目名称:hacrypto,代码行数:31,代码来源:certtool-common.c
示例13: load_cert
static gnutls_x509_crt_t
load_cert (void)
{
gnutls_x509_crt_t crt;
int ret;
gnutls_datum_t dat;
size_t size;
if (!HAVE_OPT(LOAD_CERT))
error (EXIT_FAILURE, 0, "missing --load-cert");
ret = gnutls_x509_crt_init (&crt);
if (ret < 0)
error (EXIT_FAILURE, 0, "crt_init: %s", gnutls_strerror (ret));
dat.data = (void*)read_binary_file (OPT_ARG(LOAD_CERT), &size);
dat.size = size;
if (!dat.data)
error (EXIT_FAILURE, errno, "reading --load-cert: %s", OPT_ARG(LOAD_CERT));
ret = gnutls_x509_crt_import (crt, &dat, encoding);
free (dat.data);
if (ret < 0)
error (EXIT_FAILURE, 0, "importing --load-cert: %s: %s",
OPT_ARG(LOAD_CERT), gnutls_strerror (ret));
return crt;
}
开发者ID:frankmorgner,项目名称:gnutls,代码行数:29,代码来源:ocsptool.c
示例14: us894_test27
/*
* Test the passing of bad userid/password values to est_proxy_init to make sure
* they're error checked.
*/
static void us894_test27 (void)
{
unsigned char *cacerts = NULL;
int cacerts_len = 0;
BIO *certin, *keyin;
X509 *x;
EVP_PKEY *priv_key;
int rv;
EST_CTX *ctx;
LOG_FUNC_NM;
/*
* Read in the CA certificates
*/
cacerts_len = read_binary_file(US894_CACERT, &cacerts);
CU_ASSERT(cacerts_len > 0);
/*
* Read the server cert
*/
certin = BIO_new(BIO_s_file_internal());
rv = BIO_read_filename(certin, US894_SERVER_CERT);
CU_ASSERT(rv > 0);
x = PEM_read_bio_X509(certin, NULL, NULL, NULL);
CU_ASSERT(x != NULL);
BIO_free(certin);
/*
* Read the server key
*/
keyin = BIO_new(BIO_s_file_internal());
rv = BIO_read_filename(keyin, US894_SERVER_KEY);
CU_ASSERT(rv > 0);
priv_key = PEM_read_bio_PrivateKey(keyin, NULL, NULL, NULL);
CU_ASSERT(priv_key != NULL);
BIO_free(keyin);
/*
* Attempt to init EST proxy using NULL userid
*/
est_init_logger(EST_LOG_LVL_INFO, NULL);
ctx = est_proxy_init(cacerts, cacerts_len, cacerts, cacerts_len,
EST_CERT_FORMAT_PEM,
"estrealm", x, priv_key,
NULL, "estpwd");
CU_ASSERT(ctx == NULL);
ctx = est_proxy_init(cacerts, cacerts_len, cacerts, cacerts_len,
EST_CERT_FORMAT_PEM,
"estrealm", x, priv_key,
"bad_userid_too_long_xxxxxxxxxxxx",
"estpwd");
CU_ASSERT(ctx == NULL);
X509_free(x);
EVP_PKEY_free(priv_key);
}
开发者ID:DDvO,项目名称:libest,代码行数:64,代码来源:us894.c
示例15: read_cert_file
/* Reads a certificate file
*/
static int
read_cert_file(gnutls_certificate_credentials_t res,
gnutls_privkey_t key,
const char *certfile, gnutls_x509_crt_fmt_t type)
{
int ret;
size_t size;
char *data;
if (gnutls_url_is_supported(certfile)) {
return read_cert_url(res, key, certfile);
}
data = read_binary_file(certfile, &size);
if (data == NULL) {
gnutls_assert();
return GNUTLS_E_FILE_ERROR;
}
ret = read_cert_mem(res, key, data, size, type);
free(data);
return ret;
}
开发者ID:gnutls,项目名称:gnutls,代码行数:28,代码来源:cert-cred-x509.c
示例16: pg_read_binary_file
/*
* Read a section of a file, returning it as bytea
*/
Datum
pg_read_binary_file(PG_FUNCTION_ARGS)
{
text *filename_t = PG_GETARG_TEXT_PP(0);
int64 seek_offset = 0;
int64 bytes_to_read = -1;
bool missing_ok = false;
char *filename;
bytea *result;
/* handle optional arguments */
if (PG_NARGS() >= 3)
{
seek_offset = PG_GETARG_INT64(1);
bytes_to_read = PG_GETARG_INT64(2);
if (bytes_to_read < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("requested length cannot be negative")));
}
if (PG_NARGS() >= 4)
missing_ok = PG_GETARG_BOOL(3);
filename = convert_and_check_filename(filename_t);
result = read_binary_file(filename, seek_offset,
bytes_to_read, missing_ok);
if (result)
PG_RETURN_BYTEA_P(result);
else
PG_RETURN_NULL();
}
开发者ID:RingsC,项目名称:postgres,代码行数:36,代码来源:genfile.c
示例17: get_container
static pskc_t *
get_container (const struct gengetopt_args_info *args_info)
{
const char *filename = args_info->inputs ? args_info->inputs[0] : NULL;
int strict = args_info->strict_flag;
pskc_t *container;
char *buffer;
size_t len;
int rc;
rc = pskc_init (&container);
if (rc != PSKC_OK)
error (EXIT_FAILURE, 0, "initializing PSKC structure: %s",
pskc_strerror (rc));
if (filename)
buffer = read_binary_file (filename, &len);
else
buffer = fread_file (stdin, &len);
if (buffer == NULL)
error (EXIT_FAILURE, errno, "read");
rc = pskc_parse_from_memory (container, len, buffer);
if (!strict && rc == PSKC_PARSE_ERROR)
fprintf (stderr, "warning: parse error (use -d to diagnose), output "
"may be incomplete\n");
else if (rc != PSKC_OK)
error (EXIT_FAILURE, 0, "parsing PSKC data: %s", pskc_strerror (rc));
free (buffer);
return container;
}
开发者ID:Fabian-Gruenbichler,项目名称:oath-toolkit,代码行数:33,代码来源:pskctool.c
示例18: decoder
QueryEngine::QueryEngine(const char * filepath) : decoder(filepath){
//Create filepaths
std::string basepath(filepath);
std::string path_to_hashtable = basepath + "/probing_hash.dat";
std::string path_to_data_bin = basepath + "/binfile.dat";
std::string path_to_source_vocabid = basepath + "/source_vocabids";
///Source phrase vocabids
read_map(&source_vocabids, path_to_source_vocabid.c_str());
//Target phrase vocabIDs
vocabids = decoder.get_target_lookup_map();
//Read config file
std::string line;
std::ifstream config ((basepath + "/config").c_str());
getline(config, line);
int tablesize = atoi(line.c_str()); //Get tablesize.
config.close();
//Mmap binary table
struct stat filestatus;
stat(path_to_data_bin.c_str(), &filestatus);
binary_filesize = filestatus.st_size;
binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize);
//Read hashtable
size_t table_filesize = Table::Size(tablesize, 1.2);
mem = readTable(path_to_hashtable.c_str(), table_filesize);
Table table_init(mem, table_filesize);
table = table_init;
std::cerr << "Initialized successfully! " << std::endl;
}
开发者ID:840462307cn,项目名称:mosesdecoder,代码行数:35,代码来源:quering.cpp
示例19: gnutls_x509_trust_list_remove_trust_file
/**
* gnutls_x509_trust_list_remove_trust_file:
* @list: The list
* @ca_file: A file containing a list of CAs
* @type: The format of the certificates
*
* This function will remove the given certificate authorities
* from the trusted list, and add them into a black list when needed.
* PKCS 11 URLs are also accepted, instead
* of files, by this function.
*
* See also gnutls_x509_trust_list_remove_cas().
*
* Returns: The number of added elements is returned.
*
* Since: 3.1.10
**/
int
gnutls_x509_trust_list_remove_trust_file(gnutls_x509_trust_list_t list,
const char *ca_file,
gnutls_x509_crt_fmt_t type)
{
gnutls_datum_t cas = { NULL, 0 };
size_t size;
int ret;
#ifdef ENABLE_PKCS11
if (strncmp(ca_file, "pkcs11:", 7) == 0) {
if (is_pkcs11_url_object(ca_file) != 0) {
return remove_pkcs11_object_url(list, ca_file);
} else { /* token */
return remove_pkcs11_url(list, ca_file);
}
} else
#endif
{
cas.data = (void *) read_binary_file(ca_file, &size);
if (cas.data == NULL) {
gnutls_assert();
return GNUTLS_E_FILE_ERROR;
}
cas.size = size;
}
ret = gnutls_x509_trust_list_remove_trust_mem(list, &cas, type);
free(cas.data);
return ret;
}
开发者ID:GostCrypt,项目名称:GnuTLS,代码行数:49,代码来源:verify-high2.c
示例20: read_text_file
std::string read_text_file(const std::string& path)
{
#if 1
const auto vec = read_binary_file(path);
return std::string(begin(vec), end(vec));
#else
ifstream file;
file.open(path.c_str());
std::string content = "";
std::string line;
if (!file.is_open()) {
ABORT_F("Failed to open '%s'", path.c_str());
}
while (!file.eof()) {
getline(file, line);
content += line + "\n";
}
file.close();
return content;
#endif
}
开发者ID:emilk,项目名称:emilib,代码行数:25,代码来源:file_system.cpp
注:本文中的read_binary_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论