/*! @file @id $Id$ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #include #include #include #include #include #include #include #include #include #include #include unsigned long r(1); std::string txt("This is an example."); std::string lib("libcvP11.so"); std::string slot; std::string cert; typedef std::map > Args; Args args = { // option 2 3 4 description {"-h", Args::mapped_type(0, 0, 0, "same as --help")}, {"--help", Args::mapped_type(0, 0, 0, "show help")}, {"-r", Args::mapped_type(0, &r, 0, "same as --repeat")}, {"--repeat", Args::mapped_type(0, &r, 0, " of repetitions")}, {"-t", Args::mapped_type(0, 0, &txt, "same as --text")}, {"--text", Args::mapped_type(0, 0, &txt, " with text to sign")}, {"-l", Args::mapped_type(&lib, 0, 0, "same as --library")}, {"--library", Args::mapped_type(&lib, 0, 0, " cryptoki to load")}, {"-s", Args::mapped_type(&slot, 0, 0, "same as --slot")}, {"--slot", Args::mapped_type(&slot, 0, 0, " of slot")}, {"-c", Args::mapped_type(&cert, 0, 0, "same as --certificae")}, {"--certificate", Args::mapped_type(&cert, 0, 0, " name to use")} // 2: read string from command line // 3: read unsigned long integer from command line // 4: read string from file given on command line }; int main(int argc, char** argv) try { for (auto arg(argv+1); arg(it->second)!=0 || std::get<1>(it->second)!=0 || std::get<2>(it->second)!=0) && arg+1(it->second)) { *std::get<0>(it->second) = *++arg; } else if (std::get<1>(it->second)) { ((std::stringstream&)(std::stringstream()<<*++arg)) >>*std::get<1>(it->second); } else if (std::get<2>(it->second)) { std::ifstream t(*++arg); *std::get<2>(it->second) = std::string (std::istreambuf_iterator(t), std::istreambuf_iterator()); } } else { // argument type 0 or wrong parameter displays help std::cerr<<"SYNOPSIS"<(v.second) <(CKO_CERTIFICATE))); std::for_each(certs.begin(), certs.end(), [&session](cryptoki::Object c){ std::string label(c.attribute(CKA_LABEL).value); if (cert.size()&&cert!=label) return; cryptoki::Attribute id(c.attribute(CKA_ID)); cryptoki::ObjectList keys (session.find(cryptoki::Attribute(CKA_CLASS) .from(CKO_PUBLIC_KEY), id)); if (!keys.size()) return; std::cout<<"Found Certificate: " <>pin; cryptoki::Session::Login l(session, pin); keys = session.find(cryptoki::Attribute(CKA_CLASS) .from(CKO_PRIVATE_KEY), id); if (keys.size()!=1) { std::cerr<<"**** ERROR: No private key: "<(end - start); std::cout<<"Done in "<