chromium/components/web_package/test_support/signed_web_bundles/web_bundle_signer.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/web_package/test_support/signed_web_bundles/web_bundle_signer.h"

#include <limits>

#include "base/check_is_test.h"
#include "base/containers/extend.h"
#include "base/containers/to_vector.h"
#include "base/functional/overloaded.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/types/expected_macros.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "components/web_package/signed_web_bundles/constants.h"
#include "components/web_package/signed_web_bundles/ecdsa_p256_public_key.h"
#include "components/web_package/signed_web_bundles/ed25519_public_key.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_id.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_utils.h"
#include "components/web_package/signed_web_bundles/types.h"
#include "crypto/secure_hash.h"

namespace web_package::test {

namespace {

IntegrityBlockErrorForTesting;
IntegritySignatureErrorForTesting;
IntegritySignatureErrorsForTesting;

cbor::Value CreateSignatureStackEntryAttributes(
    const PublicKey& public_key,
    IntegritySignatureErrorsForTesting errors_for_testing = {}

cbor::Value CreateSignatureStackEntry(
    const PublicKey& public_key,
    std::vector<uint8_t> signature,
    IntegritySignatureErrorsForTesting errors_for_testing = {}

cbor::Value CreateIntegrityBlock(
    const cbor::Value::ArrayValue& signature_stack,
    const std::optional<WebBundleSigner::IntegrityBlockAttributes>&
        ib_attributes,
    WebBundleSigner::IntegrityBlockErrorsForTesting errors_for_testing) {}

cbor::Value CreateIntegrityBlockForBundle(
    base::span<const uint8_t> unsigned_bundle,
    const KeyPairs& key_pairs,
    const std::optional<WebBundleSigner::IntegrityBlockAttributes>&
        ib_attributes,
    WebBundleSigner::ErrorsForTesting errors_for_testing) {}

// If `web_bundle_id` is not provided explicitly, infer it from the first
// public key.
void FillIdAttributesIfPossibleAndNecessary(
    const KeyPairs& key_pairs,
    std::optional<WebBundleSigner::IntegrityBlockAttributes>& ib_attributes,
    const WebBundleSigner::IntegrityBlockErrorsForTesting& errors_for_testing) {}
}  // namespace

WebBundleSigner::ErrorsForTesting::ErrorsForTesting(
    IntegrityBlockErrorsForTesting bundle_errors,
    const std::vector<IntegritySignatureErrorsForTesting>& signatures_errors)
    :{}

WebBundleSigner::ErrorsForTesting::ErrorsForTesting(
    const ErrorsForTesting& other) = default;
WebBundleSigner::ErrorsForTesting& WebBundleSigner::ErrorsForTesting::operator=(
    const ErrorsForTesting& other) = default;
WebBundleSigner::ErrorsForTesting::~ErrorsForTesting() = default;

std::vector<uint8_t> WebBundleSigner::SignBundle(
    base::span<const uint8_t> unsigned_bundle,
    const KeyPair& key_pair,
    ErrorsForTesting errors_for_testing) {}

std::vector<uint8_t> WebBundleSigner::SignBundle(
    base::span<const uint8_t> unsigned_bundle,
    const KeyPairs& key_pairs,
    std::optional<IntegrityBlockAttributes> ib_attributes,
    ErrorsForTesting errors_for_testing) {}

}  // namespace web_package::test