xref: /aosp_15_r20/external/tink/cc/internal/key_info.cc (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #include "tink/internal/key_info.h"
18 
19 #include "proto/tink.pb.h"
20 
21 namespace crypto {
22 namespace tink {
23 
24 using ::google::crypto::tink::Keyset;
25 using ::google::crypto::tink::KeysetInfo;
26 
KeyInfoFromKey(const Keyset::Key & key)27 KeysetInfo::KeyInfo KeyInfoFromKey(const Keyset::Key& key) {
28   KeysetInfo::KeyInfo key_info;
29   key_info.set_key_id(key.key_id());
30   key_info.set_type_url(key.key_data().type_url());
31   key_info.set_output_prefix_type(key.output_prefix_type());
32   key_info.set_status(key.status());
33   return key_info;
34 }
35 
KeysetInfoFromKeyset(const Keyset & keyset)36 KeysetInfo KeysetInfoFromKeyset(const Keyset& keyset) {
37   KeysetInfo keyset_info;
38   keyset_info.set_primary_key_id(keyset.primary_key_id());
39   for (const Keyset::Key& key : keyset.key()) {
40     *keyset_info.add_key_info() = KeyInfoFromKey(key);
41   }
42   return keyset_info;
43 }
44 
45 }  // namespace tink
46 }  // namespace crypto
47