1 // Copyright 2017 Google Inc. 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/aead/aead_factory.h" 18 19 #include <memory> 20 21 #include "absl/memory/memory.h" 22 #include "tink/aead.h" 23 #include "tink/aead/aead_wrapper.h" 24 #include "tink/key_manager.h" 25 #include "tink/keyset_handle.h" 26 #include "tink/registry.h" 27 #include "tink/util/status.h" 28 #include "tink/util/statusor.h" 29 30 namespace crypto { 31 namespace tink { 32 33 // static GetPrimitive(const KeysetHandle & keyset_handle)34util::StatusOr<std::unique_ptr<Aead>> AeadFactory::GetPrimitive( 35 const KeysetHandle& keyset_handle) { 36 util::Status status = 37 Registry::RegisterPrimitiveWrapper(absl::make_unique<AeadWrapper>()); 38 if (!status.ok()) { 39 return status; 40 } 41 return keyset_handle.GetPrimitive<Aead>(); 42 } 43 44 // static GetPrimitive(const KeysetHandle & keyset_handle,const KeyManager<Aead> * custom_key_manager)45util::StatusOr<std::unique_ptr<Aead>> AeadFactory::GetPrimitive( 46 const KeysetHandle& keyset_handle, 47 const KeyManager<Aead>* custom_key_manager) { 48 util::Status status = 49 Registry::RegisterPrimitiveWrapper(absl::make_unique<AeadWrapper>()); 50 if (!status.ok()) { 51 return status; 52 } 53 return keyset_handle.GetPrimitive<Aead>(custom_key_manager); 54 } 55 56 } // namespace tink 57 } // namespace crypto 58