将Boost路径向量项传递给Crypto ++ FileSource函数

时间:2019-05-02 20:33:38

标签: c++ boost crypto++

试图构建一个程序来扫描目录并为每个文件生成MD5哈希。在C ++ 14中使用boost和crypto ++

努力使我了解路径矢量,并将各个项目传递给crypto ++ FileSource函数。

请参阅以下带有固定路径的示例。如果有人能让我知道如何将目录元素转换为for循环中FileSource函数所接受的类型,那就太好了。

if (exists(p)) {                                             
  if (is_regular_file(p)) {     
    cout << "Please enter base path of directory only." << endl;
  }
  else if (is_directory(p)){           
    cout << "Scanning " << p << endl;

    typedef vector<path> vec;
    vec v;

    copy(directory_iterator(p), directory_iterator(), back_inserter(v));
    sort(v.begin(), v.end());

    for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
      {
        string result;
        Weak::MD5 hash;
        FileSource("/home/howard/Documents/projects/copy_project/MultiCopy/main.cpp", true, new HashFilter(hash, new HexEncoder(new StringSink(result), false)));
        cout << "   " << *it << " : "  << result << endl;
      }

这可以按预期工作,并打印出以下内容:

Scanning "/home/howard/Documents/projects/copy_project/"
   "/home/howard/Documents/projects/copy_project/MultiCopy" : e4e336e768990b515a573dc5f60e5b8b
   "/home/howard/Documents/projects/copy_project/cryptopp_example" : e4e336e768990b515a573dc5f60e5b8b
   "/home/howard/Documents/projects/copy_project/md5_example" : e4e336e768990b515a573dc5f60e5b8b
   "/home/howard/Documents/projects/copy_project/md5_from_file" : e4e336e768990b515a573dc5f60e5b8b
   "/home/howard/Documents/projects/copy_project/scan_dir" : e4e336e768990b515a573dc5f60e5b8b

在下面尝试过,但这不起作用。

FileSource(*it, true, new HashFilter(hash, new HexEncoder(new StringSink(result), false)));

0 个答案:

没有答案