Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / network / certificate_pattern.h
blobb0eb29c8c0fe51a9b0b32d450e8318512132631b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_
6 #define CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_
8 #include <string>
9 #include <vector>
11 #include "chromeos/chromeos_export.h"
13 namespace base {
14 class DictionaryValue;
17 namespace chromeos {
19 // Class to represent the DER fields of an issuer or a subject in a
20 // certificate and compare them.
21 class CHROMEOS_EXPORT IssuerSubjectPattern {
22 public:
23 IssuerSubjectPattern();
24 IssuerSubjectPattern(const std::string& common_name,
25 const std::string& locality,
26 const std::string& organization,
27 const std::string& organizational_unit);
28 ~IssuerSubjectPattern();
30 // Returns true if all fields in the pattern are empty.
31 bool Empty() const;
33 // Clears out all values in this pattern (so Empty returns true).
34 void Clear();
36 void set_common_name(const std::string& name) { common_name_ = name; }
37 void set_locality(const std::string& locality) { locality_ = locality; }
38 void set_organization(const std::string& organization) {
39 organization_ = organization;
41 void set_organizational_unit(const std::string& unit) {
42 organizational_unit_ = unit;
45 const std::string& common_name() const {
46 return common_name_;
48 const std::string& locality() const {
49 return locality_;
51 const std::string& organization() const {
52 return organization_;
54 const std::string& organizational_unit() const {
55 return organizational_unit_;
58 // Creates a new dictionary with the issuer subject pattern as its contents.
59 // Caller assumes ownership.
60 base::DictionaryValue* CreateAsDictionary() const;
62 bool CopyFromDictionary(const base::DictionaryValue& dictionary);
64 private:
65 std::string common_name_;
66 std::string locality_;
67 std::string organization_;
68 std::string organizational_unit_;
71 // A class to contain a certificate pattern and find existing matches to the
72 // pattern in the certificate database.
73 class CHROMEOS_EXPORT CertificatePattern {
74 public:
75 CertificatePattern();
76 ~CertificatePattern();
78 // Returns true if this pattern has nothing set (and so would match
79 // all certs). Ignores enrollment_uri_;
80 bool Empty() const;
82 // Clears out all the values in this pattern (so Empty returns true).
83 void Clear();
85 void set_issuer_ca_ref_list(const std::vector<std::string>& ref_list) {
86 issuer_ca_ref_list_ = ref_list;
88 void set_issuer(const IssuerSubjectPattern& issuer) { issuer_ = issuer; }
89 void set_subject(const IssuerSubjectPattern& subject) { subject_ = subject; }
90 void set_enrollment_uri_list(const std::vector<std::string>& uri_list) {
91 enrollment_uri_list_ = uri_list;
94 const IssuerSubjectPattern& issuer() const {
95 return issuer_;
97 const IssuerSubjectPattern& subject() const {
98 return subject_;
100 const std::vector<std::string>& issuer_ca_ref_list() const {
101 return issuer_ca_ref_list_;
103 const std::vector<std::string>& enrollment_uri_list() const {
104 return enrollment_uri_list_;
107 // Creates a new dictionary containing the data in the certificate pattern.
108 base::DictionaryValue* CreateAsDictionary() const;
110 // Replaces the contents of this CertificatePattern object with
111 // the values in the dictionary. Returns false if the dictionary is
112 // malformed.
113 bool CopyFromDictionary(const base::DictionaryValue& dictionary);
115 private:
116 std::vector<std::string> issuer_ca_ref_list_;
117 IssuerSubjectPattern issuer_;
118 IssuerSubjectPattern subject_;
119 std::vector<std::string> enrollment_uri_list_;
122 } // namespace chromeos
124 #endif // CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_