本文整理汇总了C++中Blob::equals方法的典型用法代码示例。如果您正苦于以下问题:C++ Blob::equals方法的具体用法?C++ Blob::equals怎么用?C++ Blob::equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob::equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void
onConsumeComplete
(const ptr_lib::shared_ptr<Data>& contentData, const Blob& result,
int* finalCount)
{
(*finalCount) = 1;
ASSERT_TRUE(result.equals(Blob(DATA_CONTENT, sizeof(DATA_CONTENT))))
<< "consumeComplete";
}
示例2: encryptParams
TEST_F(TestAesAlgorithm, EncryptionDecryption)
{
EncryptParams encryptParams(ndn_EncryptAlgorithmType_AesEcb, 16);
Blob key(KEY, sizeof(KEY));
DecryptKey decryptKey(key);
EncryptKey encryptKey = AesAlgorithm::deriveEncryptKey(decryptKey.getKeyBits());
// Check key loading and key derivation.
ASSERT_TRUE(encryptKey.getKeyBits().equals(key));
ASSERT_TRUE(decryptKey.getKeyBits().equals(key));
Blob plainBlob(PLAINTEXT, sizeof(PLAINTEXT));
// Encrypt data in AES_ECB.
Blob cipherBlob = AesAlgorithm::encrypt
(encryptKey.getKeyBits(), plainBlob, encryptParams);
ASSERT_TRUE(cipherBlob.equals(Blob(CIPHERTEXT_ECB, sizeof(CIPHERTEXT_ECB))));
// Decrypt data in AES_ECB.
Blob receivedBlob = AesAlgorithm::decrypt
(decryptKey.getKeyBits(), cipherBlob, encryptParams);
ASSERT_TRUE(receivedBlob.equals(plainBlob));
// Encrypt/decrypt data in AES_CBC with auto-generated IV.
encryptParams.setAlgorithmType(ndn_EncryptAlgorithmType_AesCbc);
cipherBlob = AesAlgorithm::encrypt
(encryptKey.getKeyBits(), plainBlob, encryptParams);
receivedBlob = AesAlgorithm::decrypt
(decryptKey.getKeyBits(), cipherBlob, encryptParams);
ASSERT_TRUE(receivedBlob.equals(plainBlob));
// Encrypt data in AES_CBC with specified IV.
Blob initialVector(INITIAL_VECTOR, sizeof(INITIAL_VECTOR));
encryptParams.setInitialVector(initialVector);
cipherBlob = AesAlgorithm::encrypt
(encryptKey.getKeyBits(), plainBlob, encryptParams);
ASSERT_TRUE(cipherBlob.equals(Blob(CIPHERTEXT_CBC_IV, sizeof(CIPHERTEXT_CBC_IV))));
// Decrypt data in AES_CBC with specified IV.
receivedBlob = AesAlgorithm::decrypt
(decryptKey.getKeyBits(), cipherBlob, encryptParams);
ASSERT_TRUE(receivedBlob.equals(plainBlob));
}
示例3: keyParams
TEST_F(TestAesAlgorithm, KeyGeneration)
{
AesKeyParams keyParams(128);
DecryptKey decryptKey = AesAlgorithm::generateKey(keyParams);
EncryptKey encryptKey = AesAlgorithm::deriveEncryptKey(decryptKey.getKeyBits());
Blob plainBlob(PLAINTEXT, sizeof(PLAINTEXT));
// Encrypt/decrypt data in AES_CBC with auto-generated IV.
EncryptParams encryptParams(ndn_EncryptAlgorithmType_AesCbc, 16);
Blob cipherBlob = AesAlgorithm::encrypt
(encryptKey.getKeyBits(), plainBlob, encryptParams);
Blob receivedBlob = AesAlgorithm::decrypt
(decryptKey.getKeyBits(), cipherBlob, encryptParams);
ASSERT_TRUE(receivedBlob.equals(plainBlob));
}
示例4: database
TEST_F(TestConsumerDb, OperateAesDecryptionKey)
{
// Test construction.
Sqlite3ConsumerDb database(databaseFilePath);
// Generate key blobs.
Blob encryptionKeyBlob;
Blob decryptionKeyBlob;
generateAesKeys(encryptionKeyBlob, decryptionKeyBlob);
Name keyName
("/alice/health/samples/activity/steps/C-KEY/20150928080000/20150928090000!");
keyName.append(Name("FOR/alice/health/read/activity!"));
database.addKey(keyName, decryptionKeyBlob);
Blob resultBlob = database.getKey(keyName);
ASSERT_TRUE(decryptionKeyBlob.equals(resultBlob));
database.deleteKey(keyName);
resultBlob = database.getKey(keyName);
ASSERT_EQ(0, resultBlob.size());
}
示例5: onPlainText
void
onPlainText(const Blob& result, const Blob& expectedResult)
{
ASSERT_TRUE(result.equals(expectedResult));
}
示例6: prefix
//.........这里部分代码省略.........
Name::Component testTimeRounded2("20150101T110000");
Name::Component testTimeComponent2("20150101T110001");
// Create content keys required for this test case:
for (size_t i = 0; i < suffix.size(); ++i) {
createEncryptionKey(expectedInterest, timeMarker);
expectedInterest = expectedInterest.getPrefix(-2).append
(Encryptor::getNAME_COMPONENT_E_KEY());
}
int expressInterestCallCount = 0;
// Prepare a TestFace to instantly answer calls to expressInterest.
class TestFace : public Face {
public:
TestFace(TestProducer* parent, const Name& timeMarker,
int* expressInterestCallCount)
: Face("localhost"),
parent_(parent),
timeMarker_(timeMarker),
expressInterestCallCount_(expressInterestCallCount)
{}
virtual uint64_t
expressInterest
(const Interest& interest, const OnData& onData,
const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
{
++(*expressInterestCallCount_);
Name interestName(interest.getName());
interestName.append(timeMarker_);
if (parent_->encryptionKeys.find(interestName) == parent_->encryptionKeys.end())
throw runtime_error
("TestFace::expressInterest: Can't find " + interestName.toUri());
onData(ptr_lib::make_shared<Interest>(interest),
parent_->encryptionKeys[interestName]);
return 0;
}
private:
TestProducer* parent_;
Name timeMarker_;
int *expressInterestCallCount_;
};
TestFace face(this, timeMarker, &expressInterestCallCount);
// Verify that the content key is correctly encrypted for each domain, and
// the produce method encrypts the provided data with the same content key.
ptr_lib::shared_ptr<ProducerDb> testDb(new Sqlite3ProducerDb(databaseFilePath));
Producer producer(prefix, suffix, &face, keyChain.get(), testDb);
Blob contentKey;
// An initial test to confirm that keys are created for this time slot.
Name contentKeyName1 = producer.createContentKey
(testTime1,
bind(&TestProducer::checkEncryptionKeys, this, _1, testTime1,
testTimeRounded1, 3, &expressInterestCallCount, &contentKey, cKeyName,
testDb));
// Verify that we do not repeat the search for e-keys. The total
// expressInterestCallCount should be the same.
Name contentKeyName2 = producer.createContentKey
(testTime2,
bind(&TestProducer::checkEncryptionKeys, this, _1, testTime2,
testTimeRounded2, 3, &expressInterestCallCount, &contentKey, cKeyName,
testDb));
// Confirm content key names are correct
ASSERT_EQ(cKeyName, contentKeyName1.getPrefix(-1));
ASSERT_EQ(testTimeRounded1, contentKeyName1.get(6));
ASSERT_EQ(cKeyName, contentKeyName2.getPrefix(-1));
ASSERT_EQ(testTimeRounded2, contentKeyName2.get(6));
// Confirm that produce encrypts with the correct key and has the right name.
Data testData;
producer.produce(testData, testTime2, Blob(DATA_CONTENT, sizeof(DATA_CONTENT)));
const Name& producedName = testData.getName();
ASSERT_EQ(cKeyName.getPrefix(-1), producedName.getSubName(0, 5));
ASSERT_EQ(testTimeComponent2, producedName.get(5));
ASSERT_EQ(Encryptor::getNAME_COMPONENT_FOR(), producedName.get(6));
ASSERT_EQ(cKeyName, producedName.getSubName(7, 6));
ASSERT_EQ(testTimeRounded2, producedName.get(13));
const Blob& dataBlob = testData.getContent();
EncryptedContent dataContent;
dataContent.wireDecode(dataBlob);
const Blob& encryptedData = dataContent.getPayload();
const Blob& initialVector = dataContent.getInitialVector();
EncryptParams params(ndn_EncryptAlgorithmType_AesCbc, 16);
params.setInitialVector(initialVector);
Blob decryptTest = AesAlgorithm::decrypt(contentKey, encryptedData, params);
ASSERT_TRUE(decryptTest.equals(Blob(DATA_CONTENT, sizeof(DATA_CONTENT))));
}