blob: 51f029cf711f04b66ab1ad27b28c96b2fec72d81 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2018 The Chromium Authors
Jun Cai9409ded2018-01-30 00:19:462// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/ssl_private_key_impl.h"
6
Avi Drissmanadac21992023-01-11 23:46:397#include "base/functional/bind.h"
8#include "base/functional/callback.h"
9#include "base/functional/callback_helpers.h"
David Benjamin168681a2025-05-14 21:13:3210#include "mojo/public/cpp/bindings/callback_helpers.h"
11#include "net/base/net_errors.h"
Jun Cai9409ded2018-01-30 00:19:4612
13namespace content {
14
15SSLPrivateKeyImpl::SSLPrivateKeyImpl(
16 scoped_refptr<net::SSLPrivateKey> ssl_private_key)
17 : ssl_private_key_(std::move(ssl_private_key)) {}
18
19SSLPrivateKeyImpl::~SSLPrivateKeyImpl() = default;
20
21void SSLPrivateKeyImpl::Sign(
22 uint16_t algorithm,
23 const std::vector<uint8_t>& input,
24 network::mojom::SSLPrivateKey::SignCallback callback) {
David Benjamin168681a2025-05-14 21:13:3225 // In some cases, `ssl_private_key_` may abandon the callback. See
26 // https://crbug.com/40651689.
27 callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun(
28 std::move(callback), int32_t{net::ERR_FAILED}, std::vector<uint8_t>());
Jun Cai9409ded2018-01-30 00:19:4629 ssl_private_key_->Sign(
David Benjamin168681a2025-05-14 21:13:3230 algorithm, input,
31 base::BindOnce(&SSLPrivateKeyImpl::Callback, std::move(callback)));
Jun Cai9409ded2018-01-30 00:19:4632}
33
34void SSLPrivateKeyImpl::Callback(
35 network::mojom::SSLPrivateKey::SignCallback callback,
36 net::Error net_error,
37 const std::vector<uint8_t>& signature) {
38 std::move(callback).Run(static_cast<int32_t>(net_error), signature);
39}
40
41} // namespace content