1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 
21 #include <openssl/evp.h>
22 
23 #include "key_type.pb.h"
24 
25 namespace adb {
26 namespace crypto {
27 
28 // Class that represents a public/private key pair.
29 class Key {
30   public:
Key(bssl::UniquePtr<EVP_PKEY> && pkey,adb::proto::KeyType type)31     explicit Key(bssl::UniquePtr<EVP_PKEY>&& pkey, adb::proto::KeyType type)
32         : pkey_(std::move(pkey)), key_type_(type) {}
33     Key(Key&&) = default;
34     Key& operator=(Key&&) = default;
35 
GetEvpPkey()36     EVP_PKEY* GetEvpPkey() const { return pkey_.get(); }
GetKeyType()37     adb::proto::KeyType GetKeyType() const { return key_type_; }
38     static std::string ToPEMString(EVP_PKEY* pkey);
39 
40   private:
41     bssl::UniquePtr<EVP_PKEY> pkey_;
42     adb::proto::KeyType key_type_;
43 };  // Key
44 
45 }  // namespace crypto
46 }  // namespace adb
47