xref: /aosp_15_r20/external/cronet/net/test/key_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_TEST_KEY_UTIL_H_
6 #define NET_TEST_KEY_UTIL_H_
7 
8 #include "base/memory/scoped_refptr.h"
9 #include "third_party/boringssl/src/include/openssl/base.h"
10 
11 namespace base {
12 class FilePath;
13 }
14 
15 namespace net {
16 
17 class SSLPrivateKey;
18 
19 namespace key_util {
20 
21 // Loads a PEM-encoded private key file from |filepath| into an EVP_PKEY object.
22 // Returns the new EVP_PKEY or nullptr on error.
23 bssl::UniquePtr<EVP_PKEY> LoadEVP_PKEYFromPEM(const base::FilePath& filepath);
24 
25 // Returns a PEM-encoded string representing |key|.
26 std::string PEMFromPrivateKey(EVP_PKEY* key);
27 
28 // Loads a PEM-encoded private key file into a SSLPrivateKey object.
29 // |filepath| is the private key file path.
30 // Returns the new SSLPrivateKey.
31 scoped_refptr<SSLPrivateKey> LoadPrivateKeyOpenSSL(
32     const base::FilePath& filepath);
33 
34 }  // namespace key_util
35 
36 }  // namespace net
37 
38 #endif  // NET_TEST_KEY_UTIL_H_
39