| 1 |
// |
| 2 |
// |
| 3 |
// Copyright 2020 gRPC authors. |
| 4 |
// |
| 5 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
// you may not use this file except in compliance with the License. |
| 7 |
// You may obtain a copy of the License at |
| 8 |
// |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
// |
| 11 |
// Unless required by applicable law or agreed to in writing, software |
| 12 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
// See the License for the specific language governing permissions and |
| 15 |
// limitations under the License. |
| 16 |
// |
| 17 |
// |
| 18 |
|
| 19 |
#include <grpc/support/port_platform.h> |
| 20 |
|
| 21 |
#include "src/core/lib/security/certificate_provider/certificate_provider_registry.h" |
| 22 |
|
| 23 |
#include <string.h> |
| 24 |
|
| 25 |
#include <algorithm> |
| 26 |
#include <utility> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
#include <grpc/support/log.h> |
| 30 |
|
| 31 |
namespace grpc_core { |
| 32 |
|
| 33 |
void CertificateProviderRegistry::Builder::RegisterCertificateProviderFactory( |
| 34 |
std::unique_ptr<CertificateProviderFactory> factory) { |
| 35 |
gpr_log(GPR_DEBUG, "registering certificate provider factory for \"%s\"", |
| 36 |
factory->name()); |
| 37 |
for (size_t i = 0; i < factories_.size(); ++i) { |
| 38 |
GPR_ASSERT(strcmp(factories_[i]->name(), factory->name()) != 0); |
| 39 |
} |
| 40 |
factories_.push_back(std::move(factory)); |
| 41 |
} |
| 42 |
|
| 43 |
CertificateProviderRegistry CertificateProviderRegistry::Builder::Build() { |
| 44 |
CertificateProviderRegistry r; |
| 45 |
r.factories_ = std::move(factories_); |
| 46 |
return r; |
| 47 |
} |
| 48 |
|
| 49 |
CertificateProviderFactory* |
| 50 |
CertificateProviderRegistry::LookupCertificateProviderFactory( |
| 51 |
absl::string_view name) const { |
| 52 |
for (size_t i = 0; i < factories_.size(); ++i) { |
| 53 |
if (name == factories_[i]->name()) { |
| 54 |
return factories_[i].get(); |
| 55 |
} |
| 56 |
} |
| 57 |
return nullptr; |
| 58 |
} |
| 59 |
|
| 60 |
} // namespace grpc_core |