1 // Copyright 2018 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 
5 #include "content/browser/ssl_private_key_impl.h"
6 
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 
11 namespace content {
12 
SSLPrivateKeyImpl(scoped_refptr<net::SSLPrivateKey> ssl_private_key)13 SSLPrivateKeyImpl::SSLPrivateKeyImpl(
14     scoped_refptr<net::SSLPrivateKey> ssl_private_key)
15     : ssl_private_key_(std::move(ssl_private_key)) {}
16 
17 SSLPrivateKeyImpl::~SSLPrivateKeyImpl() = default;
18 
Sign(uint16_t algorithm,const std::vector<uint8_t> & input,network::mojom::SSLPrivateKey::SignCallback callback)19 void SSLPrivateKeyImpl::Sign(
20     uint16_t algorithm,
21     const std::vector<uint8_t>& input,
22     network::mojom::SSLPrivateKey::SignCallback callback) {
23   base::span<const uint8_t> input_span(input);
24   ssl_private_key_->Sign(
25       algorithm, input_span,
26       base::BindOnce(&SSLPrivateKeyImpl::Callback, base::Unretained(this),
27                      std::move(callback)));
28 }
29 
Callback(network::mojom::SSLPrivateKey::SignCallback callback,net::Error net_error,const std::vector<uint8_t> & signature)30 void SSLPrivateKeyImpl::Callback(
31     network::mojom::SSLPrivateKey::SignCallback callback,
32     net::Error net_error,
33     const std::vector<uint8_t>& signature) {
34   std::move(callback).Run(static_cast<int32_t>(net_error), signature);
35 }
36 
37 }  // namespace content
38