blob: 725e0c58698ae24a9096b3889cc1bfc4c3371319 [file]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "testing/create_test_crypto_write_handler.h"
#include <memory>
#include <utility>
#include "absl/base/no_destructor.h"
#include "absl/status/statusor.h"
#include "crypto/crypto_write_handler.h"
#include "testing/crypto_testing.h"
#include "testing/local_key_crypto_write_handler.h"
namespace credentio {
const TestPki& DefaultTestPki() {
static const absl::NoDestructor<TestPki> kPki(CreateTestPki());
return *kPki;
}
LocalKeyClaimSignerCredentials TestClaimSignerCredentials() {
const TestPki& pki = DefaultTestPki();
return LocalKeyClaimSignerCredentials{
.key_pem = pki.claim_signer.key_pem,
.certificate_chain = {pki.claim_signer.cert_der},
.ocsp_responses = {"test_ocsp_response"},
};
}
LocalKeyTsaCredentials TestTsaCredentials() {
const TestPki& pki = DefaultTestPki();
return LocalKeyTsaCredentials{
.key_pem = pki.tsa.key_pem,
.cert_pem = pki.tsa.cert_pem,
};
}
absl::StatusOr<std::unique_ptr<CryptoWriteHandler>>
CreateTestCryptoWriteHandler(TestCryptoWriteHandlerOptions options) {
return CreateLocalKeyCryptoWriteHandler({
.claim_signer = options.claim_signer.has_value()
? *std::move(options.claim_signer)
: TestClaimSignerCredentials(),
.tsa = options.tsa.has_value() ? *std::move(options.tsa)
: TestTsaCredentials(),
.clock = options.clock,
.disable_timestamping = options.disable_timestamping,
});
}
} // namespace credentio