cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chromeos / network / certificate_pattern.cc
blob7d2208867ab3b286608a34a4e48bb53db82f1c7c
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 #include "chromeos/network/certificate_pattern.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "components/onc/onc_constants.h"
11 namespace chromeos {
13 namespace {
15 bool GetAsListOfStrings(const base::Value& value,
16 std::vector<std::string>* result) {
17 const base::ListValue* list = NULL;
18 if (!value.GetAsList(&list))
19 return false;
20 result->clear();
21 result->reserve(list->GetSize());
22 for (size_t i = 0; i < list->GetSize(); i++) {
23 std::string item;
24 if (!list->GetString(i, &item))
25 return false;
26 result->push_back(item);
28 return true;
31 } // namespace
33 ////////////////////////////////////////////////////////////////////////////////
34 // IssuerSubjectPattern
35 IssuerSubjectPattern::IssuerSubjectPattern(
36 const std::string& common_name,
37 const std::string& locality,
38 const std::string& organization,
39 const std::string& organizational_unit)
40 : common_name_(common_name),
41 locality_(locality),
42 organization_(organization),
43 organizational_unit_(organizational_unit) {
46 IssuerSubjectPattern::IssuerSubjectPattern() {
49 IssuerSubjectPattern::~IssuerSubjectPattern() {
52 bool IssuerSubjectPattern::Empty() const {
53 return common_name_.empty() && locality_.empty() && organization_.empty() &&
54 organizational_unit_.empty();
57 void IssuerSubjectPattern::Clear() {
58 common_name_.clear();
59 locality_.clear();
60 organization_.clear();
61 organizational_unit_.clear();
64 void IssuerSubjectPattern::ReadFromONCDictionary(
65 const base::DictionaryValue& dict) {
66 Clear();
68 dict.GetStringWithoutPathExpansion(onc::client_cert::kCommonName,
69 &common_name_);
70 dict.GetStringWithoutPathExpansion(onc::client_cert::kLocality, &locality_);
71 dict.GetStringWithoutPathExpansion(onc::client_cert::kOrganization,
72 &organization_);
73 dict.GetStringWithoutPathExpansion(onc::client_cert::kOrganizationalUnit,
74 &organizational_unit_);
77 ////////////////////////////////////////////////////////////////////////////////
78 // CertificatePattern
80 CertificatePattern::CertificatePattern() {
83 CertificatePattern::~CertificatePattern() {
86 bool CertificatePattern::Empty() const {
87 return issuer_ca_pems_.empty() && issuer_.Empty() && subject_.Empty();
90 void CertificatePattern::Clear() {
91 issuer_ca_pems_.clear();
92 issuer_.Clear();
93 subject_.Clear();
94 enrollment_uri_list_.clear();
97 bool CertificatePattern::ReadFromONCDictionary(
98 const base::DictionaryValue& dict) {
99 Clear();
101 const base::DictionaryValue* child_dict = NULL;
102 const base::ListValue* child_list = NULL;
104 // All of these are optional.
105 if (dict.GetListWithoutPathExpansion(onc::client_cert::kIssuerCAPEMs,
106 &child_list) &&
107 child_list) {
108 if (!GetAsListOfStrings(*child_list, &issuer_ca_pems_))
109 return false;
111 if (dict.GetDictionaryWithoutPathExpansion(onc::client_cert::kIssuer,
112 &child_dict) &&
113 child_dict) {
114 issuer_.ReadFromONCDictionary(*child_dict);
116 child_dict = NULL;
117 if (dict.GetDictionaryWithoutPathExpansion(onc::client_cert::kSubject,
118 &child_dict) &&
119 child_dict) {
120 subject_.ReadFromONCDictionary(*child_dict);
122 child_list = NULL;
123 if (dict.GetListWithoutPathExpansion(onc::client_cert::kEnrollmentURI,
124 &child_list) &&
125 child_list) {
126 if (!GetAsListOfStrings(*child_list, &enrollment_uri_list_))
127 return false;
130 return true;
133 } // namespace chromeos