gpt4 book ai didi

c++ - 使用 cryptopp 库编译时收到警告

转载 作者:行者123 更新时间:2023-11-30 05:22:11 27 4
gpt4 key购买 nike

我有一个在 CBC 模式下使用 AES 算法的加密文件。我有数据库中的 key 。我正在尝试使用 cryptopp 5.6.2 库编译以下代码。它在没有 -Wall 标志的情况下编译,但是当我在下面启用该标志时会出现警告。

#include <iostream>
#include <fstream>
#include <exception>
#include <sstream>

#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/filters.h"
#include "cryptopp/cryptlib.h"
#include "cryptopp/hex.h"
#include "cryptopp/filters.h"
#include "cryptopp/aes.h"
#include "cryptopp/ccm.h"
#include "cryptopp/files.h"

using namespace std;
using namespace CryptoPP;

int main(int argc, char* argv[])
{
try
{
byte no[16] ;
byte noiv[16];
std::string out;
std::string fileName("./encrypted.txt");
CBC_Mode<AES>::Decryption d;
d.SetKeyWithIV(no, sizeof(no), noiv);
CryptoPP::FileSource(fileName.c_str(), true, new StreamTransformationFilter(d, new CryptoPP::FileSink("decrypted.txt"), CryptoPP::StreamTransformationFilter::PKCS_PADDING));
}
catch (CryptoPP::Exception& e)
{
std::cout << std::endl << e.what() << std::endl;
}
return 0;
}

启用 -Wall 标志时出现以下错误

In file included from ./cryptopp_5.6.2/include/cryptopp/modes.h:12,
from poc.cpp:6:
./cryptopp_5.6.2/include/cryptopp/algparam.h: In constructor ‘CryptoPP::ConstByteArrayParameter::ConstByteArrayParameter(const T&, bool) [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’:
./cryptopp_5.6.2/include/cryptopp/filters.h:793: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:26: warning: unused variable ‘cryptopp_assert_26’
In file included from ./cryptopp_5.6.2/include/cryptopp/modes.h:12,
from poc.cpp:6:
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = std::ostream*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const wchar_t*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const char*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = std::istream*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const int*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = unsigned char]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = const byte*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/algparam.h: In member function ‘void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void*) const [with T = CryptoPP::RandomNumberGenerator*]’:
poc.cpp:36: instantiated from here
./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’
./cryptopp_5.6.2/include/cryptopp/misc.h: At global scope:
./cryptopp_5.6.2/include/cryptopp/misc.h:548: warning: ‘std::string CryptoPP::StringNarrow(const wchar_t*, bool)’ defined but not used

最佳答案

below code using cryptopp 5.6.2 library...

5.6.2 有点旧。我们正准备发布 Crypto++ 5.6.5。


It gets compiled without -Wall flag but when I enable that flag below warnings appears.

./cryptopp_5.6.2/include/cryptopp/algparam.h:322: warning: unused variable ‘p’

警告已在大约 18 个月前清除。它首次出现在 Crypto++ 5.6.3 的版本中。另见 Commit 5f25c736: Add CRYPTOPP_UNUSED to help supress unused variable warnings .


Gets below errors on enabling -Wall flag ...

Crypto++ 现在在 GCC 和兼容程序下的 -Wall -Wextra 是干净的。它也可以在 MSC 下使用 /W4 进行清理。最后,它在 Solaris 的 SunCC 下干净了。

如果有兴趣,这里是发布过程和我们需要通过的安全门(来自 Release Process | Analysis Tools):

  • 编译器警告
  • Clang 和 GCC sanitizer
  • Valgrind
  • 企业分析
  • 覆盖率

目前,Coverity 正在支持 5.6.5。我们最近将 Coverity 的覆盖范围扩大到 Linux, Unix, OS X, and Windows (以前仅限于 Linux)。 Coverity 正在产生调查结果,我们正在努力解决这些问题。

关于c++ - 使用 cryptopp 库编译时收到警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39770259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com