Skip to content

Commit

Permalink
avoid long type names
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyuan129 committed Jul 26, 2023
1 parent b9d494e commit 4cea89f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
5 changes: 2 additions & 3 deletions examples/kp-producer-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ class Producer
run()
{
const std::string plainText = "Hello world";
const std::vector<std::string> attributes = {"attribute"};

std::vector<std::shared_ptr<ndn::Data>> contentData, ckData;
const std::vector<std::string> attributes = {"attribute"};
ndn::nacabe::SPtrVector<ndn::Data> contentData, ckData;
std::tie(contentData, ckData) = m_producer.produce("/randomData", attributes,
{reinterpret_cast<const uint8_t*>(plainText.data()), plainText.size()},
m_signingInfo
Expand Down
2 changes: 1 addition & 1 deletion src/attribute-authority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AttributeAuthority : noncopyable
KeyChain& m_keyChain;
TrustConfig m_trustConfig;
ssize_t m_maxSegmentSize;
std::map<Name, std::vector<std::shared_ptr<Data>>> m_segmentMap;
std::map<Name, SPtrVector<ndn::Data>> m_segmentMap;
util::Segmenter m_segmenter{m_keyChain, signingByCertificate(m_cert)};

PUBLIC_WITH_TESTS_ELSE_PROTECTED:
Expand Down
8 changes: 4 additions & 4 deletions src/cache-producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CacheProducer::clearCache()
m_kpKeyCache.clear();
}

std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
CacheProducer::produce(const Name& dataName, const Policy& accessPolicy,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate, shared_ptr<Data> dataTemplate,
Expand All @@ -39,7 +39,7 @@ CacheProducer::produce(const Name& dataName, const Policy& accessPolicy,
if (m_cpKeyCache.count(accessPolicy) == 0) {
auto k = ckDataGen(accessPolicy, info, ckTemplate);
if (k.first == nullptr || k.second.size() == 0) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
m_cpKeyCache.emplace(accessPolicy, k);
}
Expand All @@ -50,7 +50,7 @@ CacheProducer::produce(const Name& dataName, const Policy& accessPolicy,
return std::make_tuple(data, key.second);
}

std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
CacheProducer::produce(const Name& dataName, const std::vector<std::string>& attributes,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate, shared_ptr<Data> dataTemplate,
Expand All @@ -62,7 +62,7 @@ CacheProducer::produce(const Name& dataName, const std::vector<std::string>& att
if (m_kpKeyCache.count(attStr) == 0) {
auto k = ckDataGen(attributes, info, ckTemplate);
if (k.first == nullptr || k.second.size() == 0) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
m_kpKeyCache.emplace(attStr, k);
}
Expand Down
8 changes: 4 additions & 4 deletions src/cache-producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CacheProducer : public Producer
* @param info The signing parameters
* @return The encrypted data and the encrypted CK data
*/
std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
produce(const Name& dataName, const Policy& accessPolicy,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate = getDefaultCkTemplate(),
Expand All @@ -70,16 +70,16 @@ class CacheProducer : public Producer
* @param info The signing parameters
* @return The encrypted data and the encrypted CK data
*/
std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
produce(const Name& dataName, const std::vector<std::string>& attributes,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate = getDefaultCkTemplate(),
shared_ptr<Data> dataTemplate = getDefaultEncryptedDataTemplate(),
size_t maxSegmentSize = 1500) override;

PUBLIC_WITH_TESTS_ELSE_PRIVATE:
std::map<std::string, std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>> m_cpKeyCache;
std::map<std::string, std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>> m_kpKeyCache;
std::map<std::string, std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>> m_cpKeyCache;
std::map<std::string, std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>> m_kpKeyCache;
};

} // namespace nacabe
Expand Down
2 changes: 2 additions & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static const std::string ABE_TYPE_KP_ABE = "KP-ABE";
*/
using Policy = std::string;

template<class T>
using SPtrVector = std::vector<std::shared_ptr<T>>;
} // namespace nacabe
} // namespace ndn

Expand Down
32 changes: 16 additions & 16 deletions src/producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Producer::Producer(Face& face, KeyChain& keyChain,

Producer::~Producer() = default;

std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
Producer::produce(const Name& dataNameSuffix, const std::string& accessPolicy,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate, shared_ptr<Data> dataTemplate,
Expand All @@ -83,7 +83,7 @@ Producer::produce(const Name& dataNameSuffix, const std::string& accessPolicy,

auto contentKey = ckDataGen(accessPolicy, info, std::move(ckTemplate), maxSegmentSize);
if (contentKey.first == nullptr) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
else {
// the last component should always be version number
Expand All @@ -94,7 +94,7 @@ Producer::produce(const Name& dataNameSuffix, const std::string& accessPolicy,
}
}

std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>
std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>
Producer::ckDataGen(const Policy& accessPolicy,
const security::SigningInfo& info,
std::shared_ptr<Data> dataTemplate,
Expand All @@ -103,11 +103,11 @@ Producer::ckDataGen(const Policy& accessPolicy,
// do encryption
if (m_paramFetcher.getPublicParams().m_pub == "") {
NDN_LOG_INFO("Public parameters doesn't exist" );
return std::make_pair(nullptr, std::vector<std::shared_ptr<Data>>());
return std::make_pair(nullptr, SPtrVector<Data>());
}
else if (m_paramFetcher.getAbeType() != ABE_TYPE_CP_ABE) {
NDN_LOG_INFO("Not a CP-ABE encrypted data" );
return std::make_pair(nullptr, std::vector<std::shared_ptr<Data>>());
return std::make_pair(nullptr, SPtrVector<Data>());
}
else {
NDN_LOG_INFO("CK data for:" << accessPolicy);
Expand All @@ -126,15 +126,15 @@ Producer::ckDataGen(const Policy& accessPolicy,
}
}

std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
Producer::produce(const Name& dataNameSuffix, const std::vector<std::string>& attributes,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate, shared_ptr<Data> dataTemplate,
size_t maxSegmentSize)
{
auto contentKey = ckDataGen(attributes, info, std::move(ckTemplate), maxSegmentSize);
if (contentKey.first == nullptr) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
else {
// the last component should always be version number
Expand All @@ -145,7 +145,7 @@ Producer::produce(const Name& dataNameSuffix, const std::vector<std::string>& at
}
}

std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>
std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>
Producer::ckDataGen(const std::vector<std::string>& attributes,
const security::SigningInfo& info,
std::shared_ptr<Data> dataTemplate,
Expand All @@ -154,11 +154,11 @@ Producer::ckDataGen(const std::vector<std::string>& attributes,
// do encryption
if (m_paramFetcher.getPublicParams().m_pub.empty()) {
NDN_LOG_INFO("Public parameters doesn't exist" );
return std::make_pair(nullptr, std::vector<std::shared_ptr<Data>>());
return std::make_pair(nullptr, SPtrVector<Data>());
}
else if (m_paramFetcher.getAbeType() != ABE_TYPE_KP_ABE) {
NDN_LOG_INFO("Not a KP-ABE encrypted data" );
return std::make_pair(nullptr, std::vector<std::shared_ptr<Data>>());
return std::make_pair(nullptr, SPtrVector<Data>());
}
else {
std::string s("|");
Expand All @@ -185,7 +185,7 @@ Producer::ckDataGen(const std::vector<std::string>& attributes,
}
}

std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
Producer::produce(const Name& dataNameSuffix, span<const uint8_t> content,
const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate, shared_ptr<Data> dataTemplate,
Expand All @@ -195,7 +195,7 @@ Producer::produce(const Name& dataNameSuffix, span<const uint8_t> content,
if (m_paramFetcher.getAbeType() == ABE_TYPE_CP_ABE) {
auto policy = findMatchedPolicy(dataNameSuffix);
if (policy.empty()) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
return produce(dataNameSuffix, policy, content, info,
std::move(ckTemplate), std::move(dataTemplate),
Expand All @@ -204,18 +204,18 @@ Producer::produce(const Name& dataNameSuffix, span<const uint8_t> content,
else if (m_paramFetcher.getAbeType() == ABE_TYPE_KP_ABE) {
auto attributes = findMatchedAttributes(dataNameSuffix);
if (attributes.empty()) {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
return produce(dataNameSuffix, attributes, content,
info, std::move(ckTemplate), std::move(dataTemplate),
maxSegmentSize);
}
else {
return std::make_tuple(std::vector<std::shared_ptr<Data>>(), std::vector<std::shared_ptr<Data>>());
return std::make_tuple(SPtrVector<Data>(), SPtrVector<Data>());
}
}

std::vector<std::shared_ptr<Data>>
SPtrVector<Data>
Producer::produce(std::shared_ptr<algo::ContentKey> key,
const Name& keyName, const Name& dataNameSuffix,
span<const uint8_t> content, const security::SigningInfo& info,
Expand Down Expand Up @@ -328,7 +328,7 @@ Producer::onPolicyInterest(const Interest& interest)
m_face.put(reply);
}

std::vector<std::shared_ptr<Data>>
SPtrVector<Data>
Producer::getCkEncryptedData(const Name& dataNameSuffix, const algo::CipherText& cipherText,
const Name& ckName, const security::SigningInfo& info,
shared_ptr<Data> dataTemplate, size_t maxSegmentSize)
Expand Down
15 changes: 7 additions & 8 deletions src/producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Producer : noncopyable
* @param content The payload
* @return The encrypted data and the encrypted CK data
*/
virtual std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
virtual std::tuple<SPtrVector<Data>, SPtrVector<Data>>
produce(const Name& dataNameSuffix, const Policy& accessPolicy,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate = getDefaultCkTemplate(),
Expand All @@ -88,8 +88,7 @@ class Producer : noncopyable
* @param accessPolicy The encryption policy, e.g., (ucla or mit) and professor
* @return The content key and the encrypted CK data
*/
// std::pair<std::shared_ptr<algo::ContentKey>, std::shared_ptr<Data>>
std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>
std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>
ckDataGen(const Policy& accessPolicy, const security::SigningInfo& info,
std::shared_ptr<Data> dataTemplate = getDefaultCkTemplate(),
size_t maxSegmentSize = 1500);
Expand All @@ -105,7 +104,7 @@ class Producer : noncopyable
* @param content The payload
* @return The encrypted data and the encrypted CK data
*/
virtual std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
virtual std::tuple<SPtrVector<Data>, SPtrVector<Data>>
produce(const Name& dataNameSuffix, const std::vector<std::string>& attributes,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate = getDefaultCkTemplate(),
Expand All @@ -120,7 +119,7 @@ class Producer : noncopyable
* @param attributes The encryption policy, e.g., (ucla or mit) and professor
* @return The content key and the encrypted CK data
*/
std::pair<std::shared_ptr<algo::ContentKey>, std::vector<std::shared_ptr<Data>>>
std::pair<std::shared_ptr<algo::ContentKey>, SPtrVector<Data>>
ckDataGen(const std::vector<std::string>& attributes, const security::SigningInfo& info,
std::shared_ptr<Data> dataTemplate = getDefaultCkTemplate(),
size_t maxSegmentSize = 1500);
Expand All @@ -135,7 +134,7 @@ class Producer : noncopyable
* @param info The signing parameters
* @return The encrypted data and the encrypted CK data
*/
std::tuple<std::vector<std::shared_ptr<Data>>, std::vector<std::shared_ptr<Data>>>
std::tuple<SPtrVector<Data>, SPtrVector<Data>>
produce(const Name& dataNameSuffix,
span<const uint8_t> content, const security::SigningInfo& info,
std::shared_ptr<Data> ckTemplate = getDefaultCkTemplate(),
Expand All @@ -152,7 +151,7 @@ class Producer : noncopyable
* @param info The signing parameters
* @return The encrypted data and the encrypted CK data
*/
std::vector<std::shared_ptr<Data>>
SPtrVector<Data>
produce(std::shared_ptr<algo::ContentKey> key,
const Name& keyName, const Name& dataNameSuffix,
span<const uint8_t> content, const security::SigningInfo& info,
Expand All @@ -169,7 +168,7 @@ class Producer : noncopyable
void
addNewAttributes(const Name& dataPrefix, const std::vector<std::string>& attributes);

std::vector<std::shared_ptr<Data>>
SPtrVector<Data>
getCkEncryptedData(const Name& dataNameSuffix, const algo::CipherText& cipherText,
const Name& ckName, const security::SigningInfo& info,
shared_ptr<Data> dataTemplate = getDefaultEncryptedDataTemplate(),
Expand Down
6 changes: 3 additions & 3 deletions tests/unit-tests/integrated-test.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(Cp)
advanceClocks(time::milliseconds(20), 60);
BOOST_CHECK(isPolicySet);

std::vector<std::shared_ptr<Data>> contentData, ckData;
SPtrVector<ndn::Data> contentData, ckData;
auto policyFound = producer.findMatchedPolicy(dataName);

std::tie(contentData, ckData) = producer.produce(dataName, policyFound, PLAIN_TEXT, signingInfo);
Expand Down Expand Up @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(Kp)
advanceClocks(time::milliseconds(20), 60);
BOOST_CHECK(isPolicySet);

std::vector<std::shared_ptr<Data>> contentData, ckData;
SPtrVector<ndn::Data> contentData, ckData;
auto attributeFound = producer.findMatchedAttributes(dataName);
std::tie(contentData, ckData) = producer.produce(dataName, attributeFound, PLAIN_TEXT, signingInfo);
BOOST_CHECK(contentData.size() > 0);
Expand Down Expand Up @@ -482,7 +482,7 @@ BOOST_AUTO_TEST_CASE(KpCache)
NDN_LOG_DEBUG("Before policy set");
advanceClocks(time::milliseconds(20), 60);
BOOST_CHECK(isPolicySet);
std::vector<std::shared_ptr<Data>> contentData, ckData;
SPtrVector<ndn::Data> contentData, ckData;
auto attributeFound = producer.findMatchedAttributes(dataName);
BOOST_CHECK(producer.m_kpKeyCache.size() == 0);
std::tie(contentData, ckData) = producer.produce(dataName, attributeFound, PLAIN_TEXT, signingInfo);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit-tests/producer.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(EncryptContent)
"attr6", "attr7", "attr8", "attr9", "attr10"};
algo::PrivateKey prvKey = algo::ABESupport::getInstance().cpPrvKeyGen(pubParams, masterKey, attrList);

std::vector<std::shared_ptr<Data>> data, ckData;
SPtrVector<ndn::Data> data, ckData;
std::tie(data, ckData) = producer.produce(Name("/dataset1/example/data1"), "attr1 or attr2", PLAIN_TEXT, signingInfo);
BOOST_CHECK(data.size() > 0);
BOOST_CHECK(ckData.size() > 0);
Expand All @@ -259,7 +259,7 @@ BOOST_AUTO_TEST_CASE(KpEncryptContent)
"attr6", "attr7", "attr8", "attr9", "attr10"};
algo::PrivateKey prvKey = algo::ABESupport::getInstance().kpPrvKeyGen(pubParams, masterKey, "attr1 or attr2");

std::vector<std::shared_ptr<Data>> data, ckData;
SPtrVector<ndn::Data> data, ckData;
std::tie(data, ckData) = producer.produce(Name("/dataset1/example/data1"), attrList, PLAIN_TEXT, signingInfo);
BOOST_CHECK(data.size() > 0);
BOOST_CHECK(ckData.size() > 0);
Expand All @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE(AccessPolicy)
"attr6", "attr7", "attr8", "attr9", "attr10"};
algo::PrivateKey prvKey = algo::ABESupport::getInstance().cpPrvKeyGen(pubParams, masterKey, attrList);

std::vector<std::shared_ptr<Data>> data, ckData;
SPtrVector<ndn::Data> data, ckData;
std::tie(data, ckData) = producer.produce(Name("/dataset1/example/data1"), "attr >= 629927339", PLAIN_TEXT, signingInfo);
BOOST_CHECK(data.size() > 0);
BOOST_CHECK(ckData.size() > 0);
Expand Down

0 comments on commit 4cea89f

Please sign in to comment.