12
12
#include " base/check_op.h"
13
13
#include " base/notreached.h"
14
14
#include " base/strings/string_number_conversions.h"
15
- #include " base/values.h"
16
15
#include " bat/ads/internal/account/issuers/issuer_types.h"
17
16
#include " bat/ads/internal/account/issuers/public_key_alias.h"
18
17
@@ -48,8 +47,8 @@ absl::optional<std::string> GetNameForIssuerType(const IssuerType type) {
48
47
return absl::nullopt;
49
48
}
50
49
51
- absl::optional<IssuerType> ParseIssuerType (const base::Value& value) {
52
- const std::string* const name = value.FindStringKey (kNameKey );
50
+ absl::optional<IssuerType> ParseIssuerType (const base::Value::Dict & value) {
51
+ const std::string* const name = value.FindString (kNameKey );
53
52
if (!name) {
54
53
return absl::nullopt;
55
54
}
@@ -65,27 +64,27 @@ absl::optional<IssuerType> ParseIssuerType(const base::Value& value) {
65
64
return absl::nullopt;
66
65
}
67
66
68
- absl::optional<PublicKeyMap> ParsePublicKeys (const base::Value& value) {
69
- const base::Value* const public_keys_value =
70
- value.FindListKey (kPublicKeysKey );
67
+ absl::optional<PublicKeyMap> ParsePublicKeys (const base::Value::Dict & value) {
68
+ const base::Value::List * const public_keys_value =
69
+ value.FindList (kPublicKeysKey );
71
70
if (!public_keys_value) {
72
71
return absl::nullopt;
73
72
}
74
73
75
74
PublicKeyMap public_keys;
76
- for (const auto & public_key_value : public_keys_value-> GetList () ) {
75
+ for (const auto & public_key_value : * public_keys_value) {
77
76
if (!public_key_value.is_dict ()) {
78
77
return absl::nullopt;
79
78
}
79
+ const base::Value::Dict& dict = public_key_value.GetDict ();
80
80
81
- const std::string* const public_key =
82
- public_key_value.FindStringKey (kPublicKeyKey );
81
+ const std::string* const public_key = dict.FindString (kPublicKeyKey );
83
82
if (!public_key) {
84
83
return absl::nullopt;
85
84
}
86
85
87
86
const std::string* const associated_value =
88
- public_key_value. FindStringKey (kAssociatedValueKey );
87
+ dict. FindString (kAssociatedValueKey );
89
88
if (!associated_value) {
90
89
return absl::nullopt;
91
90
}
@@ -100,62 +99,51 @@ absl::optional<PublicKeyMap> ParsePublicKeys(const base::Value& value) {
100
99
101
100
} // namespace
102
101
103
- base::Value IssuerListToValue (const IssuerList& issuers) {
104
- base::Value issuers_list (base::Value::Type::LIST) ;
102
+ base::Value::List IssuerListToValue (const IssuerList& issuers) {
103
+ base::Value::List list ;
105
104
106
105
for (const auto & issuer : issuers) {
107
- base::Value issuer_dictionary (base::Value::Type::DICTIONARY);
108
-
109
- const absl::optional<std::string>& name_optional =
110
- GetNameForIssuerType (issuer.type );
111
- if (!name_optional) {
106
+ const absl::optional<std::string>& name = GetNameForIssuerType (issuer.type );
107
+ if (!name) {
112
108
continue ;
113
109
}
114
- const std::string& name = name_optional.value ();
115
110
116
- issuer_dictionary.SetStringKey (kNameKey , name);
111
+ base::Value::Dict dict;
112
+ dict.Set (kNameKey , *name);
117
113
118
- base::Value public_keys_list (base::Value::Type::LIST) ;
114
+ base::Value::List public_keys ;
119
115
for (const auto & public_key : issuer.public_keys ) {
120
- base::Value public_key_dictionary (base::Value::Type::DICTIONARY);
121
-
122
- public_key_dictionary.SetStringKey (kPublicKeyKey , public_key.first );
123
-
124
- public_key_dictionary.SetStringKey (
125
- kAssociatedValueKey , base::NumberToString (public_key.second ));
126
-
127
- public_keys_list.Append (std::move (public_key_dictionary));
116
+ base::Value::Dict public_key_dict;
117
+ public_key_dict.Set (kPublicKeyKey , public_key.first );
118
+ public_key_dict.Set (kAssociatedValueKey ,
119
+ base::NumberToString (public_key.second ));
120
+ public_keys.Append (std::move (public_key_dict));
128
121
}
129
- issuer_dictionary.SetKey (kPublicKeysKey , std::move (public_keys_list));
130
-
131
- issuers_list.Append (std::move (issuer_dictionary));
122
+ dict.Set (kPublicKeysKey , std::move (public_keys));
123
+ list.Append (std::move (dict));
132
124
}
133
125
134
- return issuers_list ;
126
+ return list ;
135
127
}
136
128
137
- absl::optional<IssuerList> ValueToIssuerList (const base::Value& value) {
138
- if (!value.is_list ()) {
139
- return absl::nullopt;
140
- }
141
-
129
+ absl::optional<IssuerList> ValueToIssuerList (const base::Value::List& value) {
142
130
IssuerList issuers;
143
131
144
- for (const auto & issuer_value : value. GetList () ) {
145
- if (!issuer_value .is_dict ()) {
132
+ for (const auto & item : value) {
133
+ if (!item .is_dict ()) {
146
134
return absl::nullopt;
147
135
}
148
136
149
- const absl::optional<IssuerType>& type_optional =
150
- ParseIssuerType (issuer_value );
137
+ const base::Value::Dict& dict = item. GetDict ();
138
+ const absl::optional<IssuerType>& type_optional = ParseIssuerType (dict );
151
139
if (!type_optional) {
152
140
return absl::nullopt;
153
141
}
154
142
const IssuerType& type = type_optional.value ();
155
143
DCHECK_NE (IssuerType::kUndefined , type);
156
144
157
145
const absl::optional<PublicKeyMap>& public_keys_optional =
158
- ParsePublicKeys (issuer_value );
146
+ ParsePublicKeys (dict );
159
147
if (!public_keys_optional) {
160
148
return absl::nullopt;
161
149
}
0 commit comments