1 // Copyright 2022 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 #ifndef TINK_PROTO_KEYSET_FORMAT_H_ 18 #define TINK_PROTO_KEYSET_FORMAT_H_ 19 20 #include <string> 21 22 #include "absl/strings/string_view.h" 23 #include "tink/keyset_handle.h" 24 #include "tink/secret_key_access_token.h" 25 #include "tink/util/secret_data.h" 26 27 namespace crypto { 28 namespace tink { 29 30 // Serializes a keyset into a binary string in "ProtoKeysetFormat". 31 // This function can serialize both keyset with or without secret key material. 32 crypto::tink::util::StatusOr<util::SecretData> 33 SerializeKeysetToProtoKeysetFormat(const KeysetHandle& keyset_handle, 34 SecretKeyAccessToken token); 35 36 // Parses a keyset from a binary string in "ProtoKeysetFormat". 37 // This function can parse both keyset with or without secret key material. 38 crypto::tink::util::StatusOr<KeysetHandle> ParseKeysetFromProtoKeysetFormat( 39 absl::string_view serialized_keyset, SecretKeyAccessToken token); 40 41 // Serializes a keyset into a binary string in "ProtoKeysetFormat". 42 // This function will fail if the keyset contains secret key material. 43 crypto::tink::util::StatusOr<std::string> 44 SerializeKeysetWithoutSecretToProtoKeysetFormat( 45 const KeysetHandle& keyset_handle); 46 47 // Parses a keyset from a binary string in "ProtoKeysetFormat". 48 // This function will fail if the keyset contains secret key material. 49 crypto::tink::util::StatusOr<KeysetHandle> 50 ParseKeysetWithoutSecretFromProtoKeysetFormat( 51 absl::string_view serialized_keyset); 52 53 54 } // namespace tink 55 } // namespace crypto 56 #endif // TINK_PROTO_KEYSET_FORMAT_H_ 57