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


C++ THROW_IOEXCEPTION函数代码示例

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


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

示例1: throw

/**
 * Check if X509Cert is signed by trusted issuer
 * @return 0 or openssl error_code. Get human readable cause with X509_verify_cert_error_string(code)
 * @throw IOException if error
 */
int digidoc::X509Cert::verify() const throw(IOException)
{
    X509_STORE_CTX *csc = X509_STORE_CTX_new(); X509_STORE_CTX_scope csct(&csc);
    if (!csc)
        THROW_IOEXCEPTION("Failed to create X509_STORE_CTX %s",ERR_reason_error_string(ERR_get_error()));

    X509_STORE *store = digidoc::X509CertStore::getInstance()->getCertStore();
    X509* x = getX509(); X509_scope xt(&x);
    if(!X509_STORE_CTX_init(csc, store, x, NULL))
        THROW_IOEXCEPTION("Failed to init X509_STORE_CTX %s",ERR_reason_error_string(ERR_get_error()));

    int ok = X509_verify_cert(csc);

    if(!ok)
    {
        int err = X509_STORE_CTX_get_error(csc);
        X509Cert cause(X509_STORE_CTX_get_current_cert (csc));
        std::ostringstream s;
        s << "Unable to verify " << cause.getSubject();
        s << ". Cause: " << X509_verify_cert_error_string(err);
        switch(err)
        {
        case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
        {
            IOException e(__FILE__, __LINE__, s.str());
            e.setCode( Exception::CertificateIssuerMissing );
            throw e;
            break;
        }
        default: THROW_IOEXCEPTION(s.str().c_str()); break;
        }
    }

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

示例2: throw

/**
 * Parses X.509 PEM formatted certificate from file.
 * NB! This struct must be freed using X509_free() function from OpenSSL or
 * with X509_scope struct.
 *
 * @param path PEM formatted X.509 certificate file path.
 * @return returns certificate parsed from file.
 * @throws IOException throws exception if the file does not contain X.509
 *         PEM formatted certificate.
 */
X509* digidoc::X509Cert::loadX509(const std::string& path) throw(IOException)
{
    // Initialize OpenSSL file.
    BIO* file = BIO_new(BIO_s_file()); BIO_scope fileScope(&file);
    if(file == NULL)
    {
        THROW_IOEXCEPTION("Failed to open X.509 certificate file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    if(BIO_read_filename(file, path.c_str()) <= 0)
    {
        THROW_IOEXCEPTION("Failed to open X.509 certificate file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    // Parse X.509 certificate from file.
    X509* cert = PEM_read_bio_X509(file, NULL, NULL, NULL);
    if(cert == NULL)
    {
        THROW_IOEXCEPTION("Failed to load X.509 certificate from file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

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

示例3: throw

/**
 * Add data for digest calculation. After calling <code>getDigest()</code> SHA context
 * is uninitialized and this method should not be called.
 *
 * @param data data to add for digest calculation.
 * @param length length of the data.
 * @throws IOException throws exception if update failed.
 * @see getDigest()
 */
void digidoc::Digest::update(const unsigned char *data, unsigned long length) throw(IOException)
{
    if(data == NULL)
        THROW_IOEXCEPTION("Can not update digest value from NULL pointer.");

    if(!d->digest.empty())
        THROW_IOEXCEPTION("Digest is already finalized, can not update it.");

    int result = 1;
    switch(d->method)
    {
    case NID_sha1:
        result = SHA1_Update(&d->sha1, static_cast<const void*>(data), length);
        break;
    case NID_sha224:
        result = SHA224_Update(&d->sha256, static_cast<const void*>(data), length);
        break;
    case NID_sha256:
        result = SHA256_Update(&d->sha256, static_cast<const void*>(data), length);
        break;
    case NID_sha384:
        result = SHA384_Update(&d->sha512, static_cast<const void*>(data), length);
        break;
    case NID_sha512:
        result = SHA512_Update(&d->sha512, static_cast<const void*>(data), length);
        break;
    default:
        break;
    }
    if(result != 1)
        THROW_IOEXCEPTION("Failed to update %s digest value: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:41,代码来源:Digest.cpp

示例4: throw

/**
 * Copies file from source <code>srcPath</code> to destination <code>destPath</code>.
 *
 * @param srcPath source full file path.
 * @param destPath destination full file path.
 * @param overwrite whether to overwrite existing file.
 * @throws IOException exception is thrown if overwrite flag is set to false and destination file already exists.
 *         Or the file copy operation failed.
 */
void digidoc::util::File::copyFile(const std::string& srcPath, const std::string& destPath, bool overwrite) throw(IOException)
{
    if(!fileExists(srcPath))
    {
        THROW_IOEXCEPTION("Source file '%s' does not exist.", srcPath.c_str());
    }

    if(!overwrite && fileExists(destPath))
    {
        THROW_IOEXCEPTION("Destination file exists '%s' can not copy to there. Overwrite flag is set to false.", destPath.c_str());
    }

    // Copy file.
    std::ifstream ifs(encodeName(srcPath).c_str(), std::ios::binary);
    std::ofstream ofs(encodeName(destPath).c_str(), std::ios::binary | std::ios::trunc);

    ofs << ifs.rdbuf();

    ifs.close();
    ofs.close();

    if(ifs.fail() || ofs.fail())
    {
        THROW_IOEXCEPTION("Failed to copy file '%s' to '%s'.", srcPath.c_str(), destPath.c_str());
    }
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:35,代码来源:File.cpp

示例5: throw

/**
 * Signs the digest with provided RSA private key.
 *
 * @param digestMethod digest method (e.g NID_sha1 for SHA1, see openssl/obj_mac.h).
 * @param digest digest value, this value is signed with the private RSA key.
 * @return returns signature.
 * @throws IOException
 */
std::vector<unsigned char> digidoc::RSACrypt::sign(const Signer::Digest& digest) throw(IOException)
{
    // Calculate memory needed for signature.
    unsigned int blockSize = RSA_size(privateKey);
    unsigned int neededSize = blockSize;
    if(digest.length > blockSize)
    {
        if(digest.length % blockSize == 0)
            neededSize = digest.length;
        else
            neededSize = ((digest.length / blockSize) + 1) * blockSize;
    }

    // Allocate memory for the signature.
    std::vector<unsigned char> signature(neededSize, 0);

    // Sign the digest with private RSA key.
    unsigned int signatureLength = 0;
    int result = RSA_sign(digest.type, digest.digest, digest.length, &signature[0], &signatureLength, privateKey);

    // Check that signing was successful.
    if(result != 1)
    {
        THROW_IOEXCEPTION("Failed to sign the digest: %s", ERR_reason_error_string(ERR_get_error()));
    }

    if(signatureLength != neededSize)
    {
        THROW_IOEXCEPTION("Failed to sign the digest.");
    }

    return signature;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:41,代码来源:RSACrypt.cpp

示例6: throw

/**
 * Converts individual X.509 subject entry to string.
 *
 * @param ln Long name of the requested entry (see openssl/objects.h)
 * @return subject name entry converted to string.
 * @throws IOException exception is throws if the conversion failed.
 */
std::string digidoc::X509Cert::getSubjectInfo(const std::string& ln) const throw(IOException)
{
    X509_NAME* name = X509_get_subject_name(cert);
    if(name == NULL)
    {
       THROW_IOEXCEPTION("Failed to convert X.509 certificate subject: %s", ERR_reason_error_string(ERR_get_error()));
    }
    int idx = X509_NAME_get_index_by_NID(name, OBJ_ln2nid(ln.c_str()), -1);
    if(idx < 0)
    {
       THROW_IOEXCEPTION("Failed to retrieve X.509 certificate info: field '%s' not found", ln.c_str());
    }
    X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, idx);
    if(!entry)
    {
       THROW_IOEXCEPTION("Failed to convert X.509 certificate field: %s", ERR_reason_error_string(ERR_get_error()));
    }
    ASN1_STRING *asnstr = X509_NAME_ENTRY_get_data(entry);

    unsigned char *data = NULL;
    int len = ASN1_STRING_to_UTF8(&data, asnstr);
    if(len < 0)
    {
       THROW_IOEXCEPTION("Failed to convert X.509 certificate field: %s", ERR_reason_error_string(ERR_get_error()));
    }
    std::string result(reinterpret_cast<const char *>(data));
    OPENSSL_free(data);

    return result;
}
开发者ID:tixsys,项目名称:esteid,代码行数:37,代码来源:X509Cert.cpp

示例7: throw

/**
 * Reads and parses container mimetype. Checks that the mimetype is supported.
 *
 * @param path path to container directory.
 * @throws IOException exception is thrown if there was error reading mimetype file from disk.
 * @throws BDocException exception is thrown if the parsed mimetype is incorrect.
 */
void digidoc::BDoc::readMimetype(const std::string &path) throw(IOException, BDocException)
{
    DEBUG("BDoc::readMimetype(path = '%s')", path.c_str());
    // Read mimetype from file.
    std::string fileName = util::File::path(path, "mimetype");
    std::ifstream ifs(util::File::encodeName(fileName).c_str(), std::ios::binary);

    unsigned char bom[] = { 0, 0, 0 };
    ifs.read((char*)bom, sizeof(bom));
    // Contains UTF-16 BOM
    if((bom[0] == 0xFF && bom[1] == 0xEF) ||
       (bom[0] == 0xEF && bom[1] == 0xFF))
        THROW_IOEXCEPTION("Mimetype file must be UTF-8 format.", fileName.c_str());
    // does not contain UTF-8 BOM reset pos
    if(!(bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF))
        ifs.seekg(0, std::ios::beg);

    std::string mimetype;
    ifs >> mimetype;
    ifs.close();

    if(ifs.fail())
        THROW_IOEXCEPTION("Failed to read mimetype file from '%s'.", fileName.c_str());

    // Check that mimetype version is correct.
    DEBUG("mimetype = '%s'", mimetype.c_str());
    if(getMimeType() != mimetype)
        THROW_BDOCEXCEPTION("Incorrect mimetype '%s', expecting '%s'", mimetype.c_str(), getMimeType().c_str());
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:36,代码来源:BDoc.cpp

示例8: throw

/**
 * Tries to initialize XmlConf by using file defined in DIGIDOCPP_OVERRIDE_CONF environment variable.
 * If this is undefined, tries to load configuration from defined Default and user configuration file
 */
digidoc::XmlConf::XmlConf() throw(IOException)
{

    if (!DEFAULT_CONF_LOC.size())
        THROW_IOEXCEPTION("XmlConf not initialized!");
    if(util::File::fileExists(DEFAULT_CONF_LOC))
        init(DEFAULT_CONF_LOC);
    else
        THROW_IOEXCEPTION("Error loading xml configuration from '%s' file",DEFAULT_CONF_LOC.c_str());
    
    if( !getenv("DIGIDOCPP_OVERRIDE_CONF") && util::File::fileExists(USER_CONF_LOC))
    {
        try
        {
            init(USER_CONF_LOC);
        }
        catch(const IOException &)
        {
            // remove invalid user home config (wrong schema location, etc.)
            try
            {
                util::File::removeFile(USER_CONF_LOC);
            }
            catch(const IOException &)
            {
                THROW_IOEXCEPTION("Failed to remove invalid user home configuration '%s' file",USER_CONF_LOC.c_str());
            }
        }
    }
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:34,代码来源:XmlConf.cpp

示例9: throw

/**
 * Creates BDoc container manifest file and returns its path.
 * 
 * Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly
 * (see iconv --list for the list of supported encoding values for libiconv).
 *
 *
 * @return returns created manifest file path.
 * @throws IOException exception is thrown if manifest file creation failed.
 */
std::string digidoc::BDoc::createManifest() throw(IOException)
{
    DEBUG("digidoc::BDoc::createManifest()");

    std::string fileName = util::File::tempFileName();

    try
    {
        manifest::Manifest manifest;

        // Add container file entry with mimetype.
        manifest.file_entry().push_back(manifest::File_entry("/", getMimeType()));

        // Add documents with mimetypes.
        for(std::vector<Document>::const_iterator iter = documents.begin(); iter != documents.end(); iter++)
        {
            manifest::File_entry fileEntry(util::File::fileName(iter->getPath()), iter->getMediaType());
            manifest.file_entry().push_back(fileEntry);
        }

        // Add signatures with mimetypes.
        unsigned int i = 0;
        for(std::vector<Signature*>::const_iterator iter = signatures.begin(); iter != signatures.end(); iter++)
        {
            manifest::File_entry fileEntry(util::String::format("META-INF/signature%u.xml", i++), (*iter)->getMediaType());
            manifest.file_entry().push_back(fileEntry);
        }

        // Serialize XML to file.
        xml_schema::NamespaceInfomap map;
        map["manifest"].name = MANIFEST_NAMESPACE;
        DEBUG("Serializing manifest XML to '%s'", fileName.c_str());
        // all XML data must be in UTF-8
        std::ofstream ofs(digidoc::util::File::fstreamName(fileName).c_str());
        manifest::manifest(ofs, manifest, map, "", xml_schema::Flags::dont_initialize);
        ofs.close();

        if(ofs.fail())
        {
            THROW_IOEXCEPTION("Failed to create manifest XML file to '%s'.", fileName.c_str());
        }
    }
    catch(const xml_schema::Exception& e)
    {
        std::ostringstream oss;
        oss << e;
        THROW_IOEXCEPTION("Failed to create manifest XML file. Error: %s", oss.str().c_str());
    }

    return fileName;
}
开发者ID:tixsys,项目名称:esteid,代码行数:61,代码来源:BDoc.cpp

示例10: STACK_OF

/**
 * Parses X.509 PEM formatted certificates from file. The file can contain multiple
 * certificates. You can just use 'cat' command in linux to add multiple PEM formatted
 * X.509 certificates to one file (e.g. <code>cat cert1.pem cert2.pem > certs.pem</code>).
 * NB! This struct must be freed using sk_X509_free() function from OpenSSL or
 * with X509Stack_scope struct.
 *
 * @param path PEM formatted X.509 certificates file path.
 * @return returns stack of parsed X.509 certificates.
 * @throws IOException throws exception if the file does not contain X.509
 *         PEM formatted certificate(s).
 */
STACK_OF(X509)* digidoc::X509Cert::loadX509Stack(const std::string& path) throw(IOException)
{
    // Create an empty X.509 stack.
    STACK_OF(X509)* stack = sk_X509_new_null();
    if(stack == NULL)
    {
        THROW_IOEXCEPTION("Failed to create X.509 certificate stack.");
    }

    // Initialize OpenSSL file.
    BIO* file = BIO_new(BIO_s_file()); BIO_scope fileScope(&file);
    if(file == NULL)
    {
        THROW_IOEXCEPTION("Failed to open X.509 certificates file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    // Open file, which can contain multiple X.509 certificates.
    if(BIO_read_filename(file, path.c_str()) <= 0)
    {
        THROW_IOEXCEPTION("Failed to open X.509 certificates file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    // Read certificates info from the file.
    STACK_OF(X509_INFO)* certsInfo = PEM_X509_INFO_read_bio(file, NULL, NULL, NULL);
    if(certsInfo == NULL)
    {
        THROW_IOEXCEPTION("Failed to read X.509 certificates from file '%s': %s",
                path.c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    // Put all found certificates to the stack.
    for(int i = 0; i < sk_X509_INFO_num(certsInfo); i++)
    {
        X509_INFO* xi = sk_X509_INFO_value(certsInfo, i);
        if(xi->x509 != NULL)
        {
            sk_X509_push(stack, xi->x509);
            xi->x509 = NULL;
        }
    }

    // Release resources.
    sk_X509_INFO_pop_free(certsInfo, X509_INFO_free);

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

示例11: throw

/**
 * Calculate message digest. SHA context will be invalid after this call.
 * For calculating an other digest you must create new SHA1Digest class.
 *
 * @return returns the calculated digest.
 * @throws IOException throws exception if update failed.
 */
std::vector<unsigned char> digidoc::Digest::getDigest() throw(IOException)
{
    // If digest is already calculated return it.
    if(!d->digest.empty())
        return d->digest;

    int result = 1;
    unsigned char *buf = new unsigned char[getSize()];
    switch(d->method)
    {
    case NID_sha1: result = SHA1_Final(buf, &d->sha1); break;
    case NID_sha224: result = SHA224_Final(buf, &d->sha256); break;
    case NID_sha256: result = SHA256_Final(buf, &d->sha256); break;
    case NID_sha384: result = SHA384_Final(buf, &d->sha512); break;
    case NID_sha512: result = SHA512_Final(buf, &d->sha512); break;
    default:
        break;
    }
    if(result != 1)
    {
        delete[] buf;
        THROW_IOEXCEPTION("Failed to create %s digest: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    for(unsigned int i = 0; i < getSize(); i++)
        d->digest.push_back(buf[i]);
    delete[] buf;
    return d->digest;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:36,代码来源:Digest.cpp

示例12: throw

/**
 * Set OCSP connection URL.
 *
 * @param url full OCSP URL (e.g. http://www.openxades.org/cgi-bin/ocsp.cgi).
 * @throws IOException exception is thrown if provided OCSP URL is in incorrect format.
 */
void digidoc::OCSP::setUrl( const std::string& _url ) throw(IOException)
{
    url = _url;
    // Parse OCSP connection URL.
    char *_host = NULL, *_port = NULL, *_path = NULL;
    int sslFlag = 0;
    if(!OCSP_parse_url(const_cast<char*>(url.c_str()), &_host, &_port, &_path, &sslFlag))
        THROW_IOEXCEPTION("Incorrect OCSP URL provided: '%s'.", url.c_str());
    ssl = sslFlag != 0;
    connhost = _host ? _host : "";
    connport = _port ? _port : "";

    // proxy host
    digidoc::Conf *c = digidoc::Conf::getInstance();
    if(!c->getProxyHost().empty())
    {
        connhost = c->getProxyHost();
        connport = c->getProxyPort();
    }

    host = connhost;
    if(!connport.empty())
        host += ":" + connport;

    OPENSSL_free(_host);
    OPENSSL_free(_port);
    OPENSSL_free(_path);
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:34,代码来源:OCSP.cpp

示例13: throw

digidoc::Conf* digidoc::Conf::getInstance() throw(IOException)
{
    if (INSTANCE == NULL)
    {
        THROW_IOEXCEPTION("Conf is not initialized");
    }
	return INSTANCE;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:8,代码来源:Conf.cpp

示例14: throw

/**
 * @return returns the X.509 certificate store implementation.
 */
digidoc::X509CertStore* digidoc::X509CertStore::getInstance() throw(IOException)
{
    if (INSTANCE == NULL)
    {
        THROW_IOEXCEPTION("X509CertStore is not initialized");
    }
    return INSTANCE;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:11,代码来源:X509CertStore.cpp

示例15: _wtempnam

/**
 * @return returns temporary filename.
 */
std::string digidoc::util::File::tempFileName()
{
#ifdef _WIN32
    // requires TMP environment variable to be set
    wchar_t *fileName = _wtempnam(0, 0); // TODO: static buffer, not thread-safe
    if ( !fileName )
        THROW_IOEXCEPTION("Failed to create a temporary file name.");
#else
    char *fileName = tempnam(0, 0);
    if ( !fileName )
        THROW_IOEXCEPTION("Failed to create a temporary file name.");
#endif
    std::string path = decodeName(fileName);
    free(fileName);
    tempFiles.push(path);
    return path;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:20,代码来源:File.cpp


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