signed_web_bundle_utils.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/web_package/signed_web_bundles/signed_web_bundle_utils.h"
  5. #include "base/big_endian.h"
  6. namespace web_package {
  7. namespace {
  8. void AddItemToPayload(std::vector<uint8_t>& payload,
  9. base::span<const uint8_t> item) {
  10. // Each item that is part of the payload is prefixed with its length encoded
  11. // as a 64 bit unsigned integer.
  12. std::array<char, sizeof(uint64_t)> length;
  13. base::BigEndianWriter writer(length.data(), length.size());
  14. CHECK(writer.WriteU64(item.size()));
  15. payload.insert(payload.end(), length.begin(), length.end());
  16. payload.insert(payload.end(), item.begin(), item.end());
  17. }
  18. } // namespace
  19. std::vector<uint8_t> CreateSignaturePayload(
  20. base::span<const uint8_t> unsigned_bundle_hash,
  21. base::span<const uint8_t> integrity_block,
  22. base::span<const uint8_t> signature_stack_entry_attributes) {
  23. std::vector<uint8_t> payload;
  24. AddItemToPayload(payload, unsigned_bundle_hash);
  25. AddItemToPayload(payload, integrity_block);
  26. AddItemToPayload(payload, signature_stack_entry_attributes);
  27. return payload;
  28. }
  29. } // namespace web_package