@@ -30,26 +30,6 @@ using namespace std;
3030
3131namespace libcdoc {
3232
33- /* *
34- * @brief Prefix with what starts machine generated Lock's label.
35- */
36- constexpr string_view LABELPREFIX{" data:" };
37-
38- /* *
39- * @brief String after label prefix indicating, the rest of the label is Base64 encoded.
40- */
41- constexpr string_view LABELBASE64IND{" ;base64," };
42-
43- /* *
44- * @brief EID type values for machine-readable label
45- */
46- static constexpr std::string_view eid_strs[] = {
47- " Unknown" ,
48- " ID-card" ,
49- " Digi-ID" ,
50- " Digi-ID E-RESIDENT"
51- };
52-
5333Recipient
5434Recipient::makeSymmetric (std::string label, int32_t kdf_iter)
5535{
@@ -143,7 +123,7 @@ Recipient::isTheSameRecipient(const std::vector<uint8_t>& public_key) const
143123static void
144124buildLabel (std::ostream& ofs, std::string_view type, std::initializer_list<std::pair<std::string_view, std::string_view>> components)
145125{
146- ofs << LABELPREFIX;
126+ ofs << CDoc2:: LABELPREFIX;
147127 ofs << " v" << ' =' << std::to_string (CDoc2::KEYLABELVERSION) << ' &'
148128 << " type" << ' =' << type;
149129 for (const auto & [key, value] : components) {
@@ -155,7 +135,7 @@ buildLabel(std::ostream& ofs, std::string_view type, std::initializer_list<std::
155135static void
156136BuildLabelEID (std::ostream& ofs, Certificate::EIDType type, const Certificate& x509)
157137{
158- buildLabel (ofs, eid_strs[type], {
138+ buildLabel (ofs, CDoc2:: eid_strs[type], {
159139 {" cn" , x509.getCommonName ()},
160140 {" serial_number" , x509.getSerialNumber ()},
161141 {" last_name" , x509.getSurname ()},
@@ -238,59 +218,5 @@ Recipient::getLabel(const std::vector<std::pair<std::string_view, std::string_vi
238218 return ofs.str ();
239219}
240220
241- map<string, string> Recipient::parseLabel (const string& label)
242- {
243- map<string, string> parsed_label;
244- // Check if provided label starts with the machine generated label prefix.
245- if (!label.starts_with (LABELPREFIX))
246- {
247- return parsed_label;
248- }
249-
250- string label_wo_prefix (label.substr (LABELPREFIX.size ()));
251-
252- // Label to be processed
253- string label_to_prcss;
254-
255- // We ignore mediatype part
256-
257- // Check, if the label is Base64 encoded
258- string::size_type base64IndPos = label_wo_prefix.find (LABELBASE64IND);
259- if (base64IndPos == string::npos)
260- {
261- if (label_wo_prefix.starts_with (" ," )) {
262- label_to_prcss = label_wo_prefix.substr (1 );
263- } else {
264- label_to_prcss = std::move (label_wo_prefix);
265- }
266- }
267- else
268- {
269- string base64_label (label_wo_prefix.substr (base64IndPos + LABELBASE64IND.size ()));
270- vector<uint8_t > decodedLabel (fromBase64 (base64_label));
271- label_to_prcss.assign (decodedLabel.cbegin (), decodedLabel.cend ());
272- }
273-
274- vector<string> label_parts (split (label_to_prcss, ' &' ));
275- for (vector<string>::const_reference part : label_parts)
276- {
277- vector<string> label_data_parts (split (part, ' =' ));
278- if (label_data_parts.size () != 2 )
279- {
280- // Invalid label data. We just ignore them.
281- LOG_ERROR (" The label '{}' is invalid" , label);
282- }
283- else
284- {
285- std::string key = urlDecode (label_data_parts[0 ]);
286- std::string value = urlDecode (label_data_parts[1 ]);
287- std::transform (key.begin (), key.end (), key.begin (), [](unsigned char c){ return std::tolower (c); });
288- parsed_label[key] = value;
289- }
290- }
291-
292- return parsed_label;
293- }
294-
295221} // namespace libcdoc
296222
0 commit comments