From dc8ea94ab33c0ad5521a98c6b2b74097104bb5c0 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Wed, 13 May 2020 16:20:37 +0200 Subject: openpgp: Set the primary User ID flag on the first User ID - The documentation for `CertBuilder` says that the first User ID that is added will be the primary User ID. - Make the implementation match the documentation by setting the primary User ID flag for the first User ID. --- openpgp/src/cert/builder.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'openpgp/src/cert/builder.rs') diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 35941c0c..1ef60e71 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -329,11 +329,14 @@ impl CertBuilder { let mut cert = Cert::try_from(packets)?; // Sign UserIDs. - for uid in self.userids.into_iter() { - let builder = sig.clone() + for (i, uid) in self.userids.into_iter().enumerate() { + let mut builder = sig.clone() .set_type(SignatureType::PositiveCertification) // GnuPG wants at least a 512-bit hash for P521 keys. .set_hash_algo(HashAlgorithm::SHA512); + if i == 0 { + builder = builder.set_primary_userid(true)?; + } let signature = uid.bind(&mut signer, &cert, builder)?; cert = cert.merge_packets( vec![Packet::from(uid), signature.into()])?; -- cgit v1.2.3