• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // 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 #ifndef GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_H
18 #define GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_H
19 
20 #include <string>
21 #include <vector>
22 
23 #include "absl/strings/string_view.h"
24 #include "absl/types/variant.h"
25 #include "src/core/util/json/json.h"
26 #include "src/core/util/matchers.h"
27 #include "src/core/util/validation_errors.h"
28 
29 namespace grpc_core {
30 
31 struct CommonTlsContext {
32   struct CertificateProviderPluginInstance {
33     std::string instance_name;
34     std::string certificate_name;
35 
36     bool operator==(const CertificateProviderPluginInstance& other) const {
37       return instance_name == other.instance_name &&
38              certificate_name == other.certificate_name;
39     }
40 
41     std::string ToString() const;
42     bool Empty() const;
43   };
44 
45   struct CertificateValidationContext {
46     struct SystemRootCerts {
47       bool operator==(const SystemRootCerts&) const { return true; }
48     };
49     absl::variant<absl::monostate, CertificateProviderPluginInstance,
50                   SystemRootCerts>
51         ca_certs;
52     std::vector<StringMatcher> match_subject_alt_names;
53 
54     bool operator==(const CertificateValidationContext& other) const {
55       return ca_certs == other.ca_certs &&
56              match_subject_alt_names == other.match_subject_alt_names;
57     }
58 
59     std::string ToString() const;
60     bool Empty() const;
61   };
62 
63   CertificateValidationContext certificate_validation_context;
64   CertificateProviderPluginInstance tls_certificate_provider_instance;
65 
66   bool operator==(const CommonTlsContext& other) const {
67     return certificate_validation_context ==
68                other.certificate_validation_context &&
69            tls_certificate_provider_instance ==
70                other.tls_certificate_provider_instance;
71   }
72 
73   std::string ToString() const;
74   bool Empty() const;
75 };
76 
77 struct XdsExtension {
78   // The type, either from the top level or from inside the TypedStruct.
79   absl::string_view type;
80   // A Json object for a TypedStruct, or the serialized config otherwise.
81   absl::variant<absl::string_view /*serialized_value*/, Json /*typed_struct*/>
82       value;
83   // Validation fields that need to stay in scope until we're done
84   // processing the extension.
85   std::vector<ValidationErrors::ScopedField> validation_fields;
86 };
87 
88 }  // namespace grpc_core
89 
90 #endif  // GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_H
91