本文整理汇总了C++中Name::getPrefix方法的典型用法代码示例。如果您正苦于以下问题:C++ Name::getPrefix方法的具体用法?C++ Name::getPrefix怎么用?C++ Name::getPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Name
的用法示例。
在下文中一共展示了Name::getPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
inline size_t
calculateSkip(const Name& name,
const Name& hint, const Name& zone)
{
size_t skip = 0;
if (!hint.empty()) {
// These are only asserts. The caller should supply the right parameters
skip = hint.size() + 1 + zone.size();
BOOST_ASSERT(name.size() > skip);
BOOST_ASSERT(name.getPrefix(hint.size()) == hint);
BOOST_ASSERT(name.get(hint.size()) == FORWARDING_HINT_LABEL);
BOOST_ASSERT(name.getSubName(hint.size() + 1, zone.size()) == zone);
}
else {
skip = zone.size();
BOOST_ASSERT(name.size() > skip);
BOOST_ASSERT(name.getPrefix(zone.size()) == zone);
}
BOOST_ASSERT(name.get(skip) == NDNS_ITERATIVE_QUERY ||
name.get(skip) == NDNS_CERT_QUERY);
++skip;
return skip;
}
示例2: onValidationFailed
void
ValidatorInvitation::internalCheck(const uint8_t* buf, size_t size,
const Signature& signature,
const Name& keyLocatorName,
const Data& innerData,
const OnValidated& onValidated,
const OnValidationFailed& onValidationFailed)
{
Name signingKeyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
TrustAnchors::const_iterator keyIt = m_trustAnchors.find(signingKeyName);
if (keyIt == m_trustAnchors.end())
return onValidationFailed("Cannot reach any trust anchor");
if (!Validator::verifySignature(buf, size, signature, keyIt->second))
return onValidationFailed("Cannot verify outer signature");
// Temporarily disabled, we should get it back when we create a specific key for the chatroom.
// if(!Validator::verifySignature(innerData, m_trustAnchors[signingKeyName]))
// return onValidationFailed("Cannot verify inner signature");
if (!m_innerKeyRegex.match(innerData.getName()) ||
m_innerKeyRegex.expand() != signingKeyName.getPrefix(-1))
return onValidationFailed("Inner certificate does not comply with the rule");
return onValidated();
}
示例3:
inline void
CertificateCacheTtl::remove(const Name& certificateName)
{
Name name = certificateName.getPrefix(-1);
Cache::iterator it = m_cache.find(name);
if (it != m_cache.end())
m_cache.erase(it);
}
示例4:
void
setNameComponent(Name& name, ssize_t index, const A& ...a)
{
Name name2 = name.getPrefix(index);
name2.append(name::Component(a...));
name2.append(name.getSubName(name2.size()));
name = name2;
}
示例5: makeNack
shared_ptr<ndn::Data>
NdnDataManager::operator[]( shared_ptr<const ndn::Interest> interest )
{
Name subname = interest->getName();
auto it = subname.end()-1;
while( ( it->isVersion() || it->isSegment()
|| it->isSegmentOffset() || it->isTimestamp()
|| it->isSequenceNumber() ) && ( it-- ) != subname.begin() );
subname = subname.getPrefix( it - subname.begin() + 1 );
if( m_producers.find( subname ) != m_producers.end() )
{
// find data producer
auto producer = m_producers[subname];
// if access level is 0, no access needs to be provided
if( interest->getAuthTag().getAccessLevel() == 0 )
{
Coordinator::
producerSatisfiedRequest( interest->getName().getPrefix( 2 ),
interest->getName() );
return producer->makeData( interest );
}
// generate data packet
shared_ptr<Data> data = producer->makeData( interest );
// check that the interest's access rights
// satisfy the data's requirements
if( m_auth_manager->getTagAccess( interest->getAuthTag() )
< data->getAccessLevel() )
{
Coordinator::
producerDeniedRequest( interest->getName().getPrefix( 2 ),
interest->getName(),
"Insufficient Auth" );
return makeNack( *data );
}
// check that the data satisfies interest
if( interest->matchesData( *data ) )
{
Coordinator::
producerSatisfiedRequest( interest->getName().getPrefix(2),
interest->getName() );
return data;
}
}
Coordinator::producerOther( interest->getName().getPrefix( 2 ),
"No data matching "
+ interest->getName().toUri() );
return NULL;
};
示例6: subjectName
shared_ptr<IdentityCertificate>
Pib::prepareCertificate(const Name& keyName, const KeyParams& keyParams,
const time::system_clock::TimePoint& notBefore,
const time::system_clock::TimePoint& notAfter,
const Name& signerName)
{
// Generate mgmt key
m_tpm->generateKeyPairInTpm(keyName, keyParams);
shared_ptr<PublicKey> publicKey = m_tpm->getPublicKeyFromTpm(keyName);
// Set mgmt cert
auto certificate = make_shared<IdentityCertificate>();
Name certName = keyName.getPrefix(-1);
certName.append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion();
certificate->setName(certName);
certificate->setNotBefore(notBefore);
certificate->setNotAfter(notAfter);
certificate->setPublicKeyInfo(*publicKey);
CertificateSubjectDescription subjectName(oid::ATTRIBUTE_NAME, keyName.getPrefix(-1).toUri());
certificate->addSubjectDescription(subjectName);
certificate->encode();
Name signingKeyName;
KeyLocator keyLocator;
if (signerName == EMPTY_SIGNER_NAME) {
// Self-sign mgmt cert
keyLocator = KeyLocator(certificate->getName().getPrefix(-1));
signingKeyName = keyName;
}
else {
keyLocator = KeyLocator(signerName.getPrefix(-1));
signingKeyName = IdentityCertificate::certificateNameToPublicKeyName(signerName);
}
SignatureSha256WithRsa signature(keyLocator);
certificate->setSignature(signature);
EncodingBuffer encoder;
certificate->wireEncode(encoder, true);
Block signatureValue = m_tpm->signInTpm(encoder.buf(), encoder.size(),
signingKeyName, DIGEST_ALGORITHM_SHA256);
certificate->wireEncode(encoder, signatureValue);
return certificate;
}
示例7: addIdentity
void
SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
{
Name identityName = keyName.getPrefix(-1);
addIdentity(identityName);
m_keyStore[keyName.toUri()] = make_shared<KeyRecord>(keyType, publicKey);
}
示例8: PartialName
Strategy::ParsedInstanceName
Strategy::parseInstanceName(const Name& input)
{
for (ssize_t i = input.size() - 1; i > 0; --i) {
if (input[i].isVersion()) {
return {input.getPrefix(i + 1), input[i].toVersion(), input.getSubName(i + 1)};
}
}
return {input, nullopt, PartialName()};
}
示例9: addCertificate
inline void
SecPublicInfo::addCertificateAsSystemDefault(const IdentityCertificate& certificate)
{
addCertificate(certificate);
Name certName = certificate.getName();
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certName);
setDefaultIdentityInternal(keyName.getPrefix(-1));
setDefaultKeyNameForIdentityInternal(keyName);
setDefaultCertificateNameForKeyInternal(certName);
refreshDefaultCertificate();
}
示例10: return
shared_ptr<RibEntry>
Rib::findParent(const Name& prefix) const
{
for (int i = prefix.size() - 1; i >= 0; i--) {
RibTable::const_iterator it = m_rib.find(prefix.getPrefix(i));
if (it != m_rib.end()) {
return (it->second);
}
}
return shared_ptr<RibEntry>();
}
示例11: if
ptr_lib::shared_ptr<Signature>
IdentityManager::makeSignatureByCertificate
(const Name& certificateName, DigestAlgorithm& digestAlgorithm)
{
Name keyName = IdentityCertificate::certificateNameToPublicKeyName
(certificateName);
ptr_lib::shared_ptr<PublicKey> publicKey = privateKeyStorage_->getPublicKey
(keyName);
KeyType keyType = publicKey->getKeyType();
if (keyType == KEY_TYPE_RSA) {
ptr_lib::shared_ptr<Sha256WithRsaSignature> signature
(new Sha256WithRsaSignature());
digestAlgorithm = DIGEST_ALGORITHM_SHA256;
signature->getKeyLocator().setType(ndn_KeyLocatorType_KEYNAME);
signature->getKeyLocator().setKeyName(certificateName.getPrefix(-1));
// Ignore witness and leave the digestAlgorithm as the default.
signature->getPublisherPublicKeyDigest().setPublisherPublicKeyDigest
(publicKey->getDigest());
return signature;
}
else if (keyType == KEY_TYPE_ECDSA) {
ptr_lib::shared_ptr<Sha256WithEcdsaSignature> signature
(new Sha256WithEcdsaSignature());
digestAlgorithm = DIGEST_ALGORITHM_SHA256;
signature->getKeyLocator().setType(ndn_KeyLocatorType_KEYNAME);
signature->getKeyLocator().setKeyName(certificateName.getPrefix(-1));
return signature;
}
else
throw SecurityException("Key type is not recognized");
}
示例12:
shared_ptr<const Data>
ResponseCache::find(const Name& dataName, bool hasVersion) const
{
if (!hasVersion) {
Storage::const_iterator it = m_storage.find(dataName);
if (it != m_storage.end())
return it->second;
else
return shared_ptr<const Data>();
}
else {
Storage::const_iterator it = m_storage.find(dataName.getPrefix(-1));
if (it != m_storage.end() && it->second->getName() == dataName)
return it->second;
else
return shared_ptr<const Data>();
}
}
示例13: Error
uint64_t
RepoEnumerator::enumerate(bool showImplicitDigest)
{
sqlite3_stmt* m_stmt = 0;
int rc = SQLITE_DONE;
string sql = string("SELECT id, name, keylocatorHash FROM NDN_REPO;");
rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &m_stmt, 0);
if (rc != SQLITE_OK)
throw Error("Initiation Read Entries from Database Prepare error");
uint64_t entryNumber = 0;
while (true) {
rc = sqlite3_step(m_stmt);
if (rc == SQLITE_ROW) {
Name name;
name.wireDecode(Block(sqlite3_column_blob(m_stmt, 1),
sqlite3_column_bytes(m_stmt, 1)));
try {
if (showImplicitDigest) {
std::cout << name << std::endl;
}
else {
std::cout << name.getPrefix(-1) << std::endl;
}
}
catch (...){
sqlite3_finalize(m_stmt);
throw;
}
entryNumber++;
}
else if (rc == SQLITE_DONE) {
sqlite3_finalize(m_stmt);
break;
}
else {
sqlite3_finalize(m_stmt);
throw Error("Initiation Read Entries error");
}
}
return entryNumber;
}
示例14: fail
void
PipelineInterests::runWithExcludedSegment(const Data& data, DataCallback onData,
FailureCallback onFailure)
{
BOOST_ASSERT(onData != nullptr);
// record the start time of running pipeline
m_startTime = time::steady_clock::now();
m_onData = std::move(onData);
m_onFailure = std::move(onFailure);
m_numOfSegmentReceived++; // count the excluded segment
Name dataName = data.getName();
m_prefix = dataName.getPrefix(-1);
m_excludeSegmentNo = dataName[-1].toSegment();
if (!data.getFinalBlockId().empty()) {
m_hasFinalBlockId = true;
m_lastSegmentNo = data.getFinalBlockId().toSegment();
}
else { // Name must contain a final block ID so that consumer knows when download finishes
fail("Name of Data packet: " + data.getName().toUri() +
" must a final block ID!");
}
// schedule the event to check retransmission timer.
m_eventCheckRto = m_scheduler.scheduleEvent(time::milliseconds(m_options.rtoCheckInterval),
bind(&PipelineInterests::checkRto, this));
if (m_options.keepStats) {
// schedule the event to keep track the history of cwnd size
m_eventRecordCwnd =
m_scheduler.scheduleEvent(time::milliseconds(m_options.cwndRecordInterval),
bind(&PipelineInterests::recordCwnd, this));
}
sendFirstInterest();
}
示例15: SecurityException
ptr_lib::shared_ptr<IdentityCertificate>
IdentityManager::selfSign(const Name& keyName)
{
ptr_lib::shared_ptr<IdentityCertificate> certificate(new IdentityCertificate());
Blob keyBlob = identityStorage_->getKey(keyName);
ptr_lib::shared_ptr<PublicKey> publicKey(new PublicKey(keyBlob));
#if NDN_CPP_HAVE_GMTIME_SUPPORT
time_t nowSeconds = time(NULL);
struct tm current = *gmtime(&nowSeconds);
current.tm_hour = 0;
current.tm_min = 0;
current.tm_sec = 0;
MillisecondsSince1970 notBefore = timegm(¤t) * 1000.0;
current.tm_year = current.tm_year + 2;
MillisecondsSince1970 notAfter = timegm(¤t) * 1000.0;
certificate->setNotBefore(notBefore);
certificate->setNotAfter(notAfter);
#else
// Don't really expect this to happen.
throw SecurityException("selfSign: Can't set certificate validity because time functions are not supported by the standard library.");
#endif
Name certificateName = keyName.getPrefix(-1).append("KEY").append
(keyName.get(-1)).append("ID-CERT").append
(Name::Component::fromNumber((uint64_t)ndn_getNowMilliseconds()));
certificate->setName(certificateName);
certificate->setPublicKeyInfo(*publicKey);
certificate->addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri()));
certificate->encode();
signByCertificate(*certificate, certificate->getName());
return certificate;
}