aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/core/manifest_inline.h
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/core/manifest_inline.h')
-rw-r--r--libtransport/src/core/manifest_inline.h37
1 files changed, 32 insertions, 5 deletions
diff --git a/libtransport/src/core/manifest_inline.h b/libtransport/src/core/manifest_inline.h
index dedf82b45..fcb1d214f 100644
--- a/libtransport/src/core/manifest_inline.h
+++ b/libtransport/src/core/manifest_inline.h
@@ -30,8 +30,12 @@ class ManifestInline
: public Manifest<Base, FormatTraits, ManifestInline<Base, FormatTraits>> {
using ManifestBase =
Manifest<Base, FormatTraits, ManifestInline<Base, FormatTraits>>;
+
+ using Hash = typename FormatTraits::Hash;
using HashType = typename FormatTraits::HashType;
+ using Suffix = typename FormatTraits::Suffix;
using SuffixList = typename FormatTraits::SuffixList;
+ using HashEntry = std::pair<auth::CryptoHashType, std::vector<uint8_t>>;
public:
ManifestInline() : ManifestBase() {}
@@ -44,7 +48,7 @@ class ManifestInline
static TRANSPORT_ALWAYS_INLINE ManifestInline *createManifest(
const core::Name &manifest_name, ManifestVersion version,
- ManifestType type, utils::CryptoHashType algorithm, bool is_last,
+ ManifestType type, auth::CryptoHashType algorithm, bool is_last,
const Name &base_name, NextSegmentCalculationStrategy strategy,
std::size_t signature_size) {
auto manifest = new ManifestInline(manifest_name, signature_size);
@@ -84,7 +88,7 @@ class ManifestInline
const Name &getBaseName() { return base_name_; }
- ManifestInline &addSuffixHash(uint32_t suffix, const HashType &hash) {
+ ManifestInline &addSuffixHash(Suffix suffix, const Hash &hash) {
ManifestBase::encoder_.addSuffixAndHash(suffix, hash);
return *this;
}
@@ -104,12 +108,35 @@ class ManifestInline
return next_segment_strategy_;
}
+ // Convert several manifests into a single map from suffixes to packet hashes.
+ // All manifests must have been decoded beforehand.
+ static std::unordered_map<Suffix, HashEntry> getSuffixMap(
+ const std::vector<ManifestInline *> &manifests) {
+ std::unordered_map<Suffix, HashEntry> suffix_map;
+
+ for (auto manifest_ptr : manifests) {
+ HashType hash_algorithm = manifest_ptr->getHashAlgorithm();
+ SuffixList suffix_list = manifest_ptr->getSuffixList();
+
+ for (auto it = suffix_list.begin(); it != suffix_list.end(); ++it) {
+ std::vector<uint8_t> hash(
+ it->second, it->second + auth::hash_size_map[hash_algorithm]);
+ suffix_map[it->first] = {hash_algorithm, hash};
+ }
+ }
+
+ return suffix_map;
+ }
+ static std::unordered_map<Suffix, HashEntry> getSuffixMap(
+ ManifestInline *manifest) {
+ return getSuffixMap(std::vector<ManifestInline *>{manifest});
+ }
+
private:
core::Name base_name_;
NextSegmentCalculationStrategy next_segment_strategy_;
SuffixList suffix_hash_map_;
};
-} // end namespace core
-
-} // end namespace transport \ No newline at end of file
+} // namespace core
+} // namespace transport