@@ -121,12 +121,17 @@ Recipient::isTheSameRecipient(const std::vector<uint8_t>& public_key) const
121121}
122122
123123static void
124- buildLabel (std::ostream& ofs, std::string_view type, std::initializer_list<std::pair<std::string_view, std::string_view>> components)
124+ buildLabel (std::ostream& ofs, std::string_view type,
125+ std::initializer_list<std::pair<std::string_view, std::string_view>> components,
126+ std::initializer_list<std::pair<std::string_view, std::string_view>> optional)
125127{
126128 ofs << CDoc2::LABELPREFIX;
127129 ofs << " v" << ' =' << std::to_string (CDoc2::KEYLABELVERSION) << ' &'
128130 << " type" << ' =' << type;
129131 for (const auto & [key, value] : components) {
132+ ofs << ' &' << urlEncode (key) << ' =' << urlEncode (value);
133+ }
134+ for (const auto & [key, value] : optional) {
130135 if (!value.empty ())
131136 ofs << ' &' << urlEncode (key) << ' =' << urlEncode (value);
132137 }
@@ -138,6 +143,7 @@ BuildLabelEID(std::ostream& ofs, Certificate::EIDType type, const Certificate& x
138143 buildLabel (ofs, CDoc2::eid_strs[type], {
139144 {" cn" , x509.getCommonName ()},
140145 {" serial_number" , x509.getSerialNumber ()},
146+ }, {
141147 {" last_name" , x509.getSurname ()},
142148 {" first_name" , x509.getGivenName ()},
143149 });
@@ -146,7 +152,7 @@ BuildLabelEID(std::ostream& ofs, Certificate::EIDType type, const Certificate& x
146152static void
147153BuildLabelCertificate (std::ostream &ofs, const std::string& file, const Certificate& x509)
148154{
149- buildLabel (ofs, " cert" , {
155+ buildLabel (ofs, " cert" , {}, {
150156 {" file" , file},
151157 {" cn" , x509.getCommonName ()},
152158 {" cert_sha1" , toHex (x509.getDigest ())}
@@ -156,7 +162,7 @@ BuildLabelCertificate(std::ostream &ofs, const std::string& file, const Certific
156162static void
157163BuildLabelPublicKey (std::ostream &ofs, const std::string& file)
158164{
159- buildLabel (ofs, " pub_key" , {
165+ buildLabel (ofs, " pub_key" , {}, {
160166 {" file" , file}
161167 });
162168}
@@ -166,6 +172,7 @@ BuildLabelSymmetricKey(std::ostream &ofs, const std::string& label, const std::s
166172{
167173 buildLabel (ofs, " secret" , {
168174 {" label" , label},
175+ }, {
169176 {" file" , file}
170177 });
171178}
@@ -175,7 +182,7 @@ BuildLabelPassword(std::ostream &ofs, const std::string& label)
175182{
176183 buildLabel (ofs, " pw" , {
177184 {" label" , label}
178- });
185+ }, {} );
179186}
180187
181188std::string
@@ -185,30 +192,27 @@ Recipient::getLabel(const std::vector<std::pair<std::string_view, std::string_vi
185192 if (!label.empty ()) return label;
186193 std::ostringstream ofs;
187194 switch (type) {
188- case NONE:
189- LOG_DBG (" The recipient is not initialized" );
190- break ;
191- case SYMMETRIC_KEY:
192- if (kdf_iter > 0 ) {
193- BuildLabelPassword (ofs, key_name);
194- } else {
195- BuildLabelSymmetricKey (ofs, key_name, file_name);
196- }
197- break ;
198- case PUBLIC_KEY:
199- if (!cert.empty ()) {
200- Certificate x509 (cert);
201- if (auto eid = x509.getEIDType (); eid != Certificate::Unknown) {
202- BuildLabelEID (ofs, eid, x509);
203- } else {
204- BuildLabelCertificate (ofs, file_name, x509);
205- }
206- } else {
207- BuildLabelPublicKey (ofs, file_name);
208- }
209- break ;
210- case KEYSHARE:
211- break ;
195+ case NONE:
196+ LOG_DBG (" The recipient is not initialized" );
197+ break ;
198+ case SYMMETRIC_KEY:
199+ if (kdf_iter > 0 ) {
200+ BuildLabelPassword (ofs, key_name);
201+ } else {
202+ BuildLabelSymmetricKey (ofs, key_name, file_name);
203+ }
204+ break ;
205+ case PUBLIC_KEY:
206+ if (Certificate x509 (cert); !x509) {
207+ BuildLabelPublicKey (ofs, file_name);
208+ } else if (auto eid = x509.getEIDType (); eid != Certificate::Unknown) {
209+ BuildLabelEID (ofs, eid, x509);
210+ } else {
211+ BuildLabelCertificate (ofs, file_name, x509);
212+ }
213+ break ;
214+ case KEYSHARE:
215+ break ;
212216 }
213217 for (const auto & [key, value] : extra) {
214218 if (!value.empty ())
0 commit comments