From 56e60e88f468379985dbce1a307942aa7463810d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 22 Dec 2021 12:40:40 +0100 Subject: [PATCH] When no user-id is marked as primary: return first user-id --- .../org/pgpainless/key/info/KeyRingInfo.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java b/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java index 19e73220..f30c36da 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java @@ -262,25 +262,25 @@ public class KeyRingInfo { } /** - * Return the primary user-id of the key ring. + * Return the current primary user-id of the key ring. * * Note: If no user-id is marked as primary key using a {@link PrimaryUserID} packet, - * this method returns the latest added user-id, otherwise null. + * this method returns the first user-id on the key, otherwise null. * * @return primary user-id or null */ private String findPrimaryUserId() { - String nonPrimaryUserId = null; String primaryUserId = null; - Date modificationDate = null; + Date currentModificationDate = null; List userIds = getUserIds(); if (userIds.isEmpty()) { return null; } + String firstUserId = userIds.get(0); if (userIds.size() == 1) { - return userIds.get(0); + return firstUserId; } for (String userId : userIds) { @@ -291,25 +291,11 @@ public class KeyRingInfo { Date creationTime = certification.getCreationTime(); if (certification.getHashedSubPackets().isPrimaryUserID()) { - if (nonPrimaryUserId != null) { - nonPrimaryUserId = null; - modificationDate = null; - } - - if (modificationDate == null || creationTime.after(modificationDate)) { + if (currentModificationDate == null || creationTime.after(currentModificationDate)) { primaryUserId = userId; - modificationDate = creationTime; + currentModificationDate = creationTime; } - } else { - if (primaryUserId != null) { - continue; - } - - if (modificationDate == null || creationTime.after(modificationDate)) { - nonPrimaryUserId = userId; - modificationDate = creationTime; - } } } @@ -317,7 +303,7 @@ public class KeyRingInfo { return primaryUserId; } - return nonPrimaryUserId; + return firstUserId; } /**