本文整理汇总了C++中KeyChain::getDefaultCertificateNameForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyChain::getDefaultCertificateNameForKey方法的具体用法?C++ KeyChain::getDefaultCertificateNameForKey怎么用?C++ KeyChain::getDefaultCertificateNameForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyChain
的用法示例。
在下文中一共展示了KeyChain::getDefaultCertificateNameForKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: description
int
ndnsec_get_default(int argc, char** argv)
{
using namespace ndn;
namespace po = boost::program_options;
bool isGetDefaultId = true;
bool isGetDefaultKey = false;
bool isGetDefaultCert = false;
bool isQuiet = false;
std::string identityString;
std::string keyName;
po::options_description description("General Usage\n ndnsec get-default [-h] [-k|c] [-i identity|-K key] [-q]\nGeneral options");
description.add_options()
("help,h", "produce help message")
("default_key,k", "get default key")
("default_cert,c", "get default certificate")
("identity,i", po::value<std::string>(&identityString), "target identity")
("key,K", po::value<std::string>(&keyName), "target key")
("quiet,q", "don't output trailing newline")
;
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, description), vm);
po::notify(vm);
}
catch (const std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
std::cerr << description << std::endl;
return 1;
}
if (vm.count("help") != 0)
{
std::cerr << description << std::endl;;
return 0;
}
if (vm.count("default_cert") != 0)
{
isGetDefaultCert = true;
isGetDefaultId = false;
}
else if (vm.count("default_key") != 0)
{
isGetDefaultKey = true;
isGetDefaultId = false;
}
if (vm.count("quiet") != 0)
{
isQuiet = true;
}
KeyChain keyChain;
if (vm.count("key") != 0)
{
Name keyNdnName(keyName);
if (isGetDefaultCert)
{
std::cout << keyChain.getDefaultCertificateNameForKey(keyNdnName);
if (!isQuiet) std::cout << std::endl;
return 0;
}
return 1;
}
else if (vm.count("identity") != 0)
{
Name identity(identityString);
if (isGetDefaultKey)
{
std::cout << keyChain.getDefaultKeyNameForIdentity(identity);
if (!isQuiet)
std::cout << std::endl;
return 0;
}
if (isGetDefaultCert)
{
std::cout << keyChain.getDefaultCertificateNameForIdentity(identity);
if (!isQuiet)
std::cout << std::endl;
return 0;
}
return 1;
}
else
{
Name identity = keyChain.getDefaultIdentity();
if (isGetDefaultId)
{
std::cout << identity;
if (!isQuiet) std::cout << std::endl;
//.........这里部分代码省略.........
示例2: description
//.........这里部分代码省略.........
}
else if (vm.count("identity") != 0)
{
isCertName = false;
isIdentityName = true;
}
else if (vm.count("file") != 0)
{
isCertName = false;
// isFileName = true;
}
if (vm.count("pretty") != 0)
isPretty = true;
if (vm.count("repo-output") != 0)
{
isRepoOut = true;
isStdOut = false;
}
else if (vm.count("dns-output") != 0)
{
// isDnsOut = true;
isStdOut = false;
std::cerr << "Error: DNS output is not supported yet!" << std::endl;
return 1;
}
if (isPretty && !isStdOut)
{
std::cerr << "Error: pretty option can only be specified when other "
<< "output option is specified" << std::endl;
return 1;
}
shared_ptr<IdentityCertificate> certificate;
KeyChain keyChain;
if (isIdentityName || isKeyName || isCertName)
{
if (isIdentityName)
{
Name certName = keyChain.getDefaultCertificateNameForIdentity(name);
certificate = keyChain.getCertificate(certName);
}
else if (isKeyName)
{
Name certName = keyChain.getDefaultCertificateNameForKey(name);
certificate = keyChain.getCertificate(certName);
}
else
certificate = keyChain.getCertificate(name);
if (!static_cast<bool>(certificate))
{
std::cerr << "No certificate found!" << std::endl;
return 1;
}
}
else
{
certificate = getIdentityCertificate(name);
if (!static_cast<bool>(certificate))
{
std::cerr << "No certificate read!" << std::endl;
return 1;
}
}
if (isPretty)
{
std::cout << *certificate << std::endl;
}
else
{
if (isStdOut)
{
io::save(*certificate, std::cout);
return 0;
}
if (isRepoOut)
{
using namespace boost::asio::ip;
tcp::iostream request_stream;
request_stream.expires_from_now(boost::posix_time::milliseconds(3000));
request_stream.connect(repoHost, repoPort);
if (!request_stream)
{
std::cerr << "fail to open the stream!" << std::endl;
return 1;
}
request_stream.write(reinterpret_cast<const char*>(certificate->wireEncode().wire()),
certificate->wireEncode().size());
return 0;
}
}
return 0;
}