mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
When no user-id is marked as primary: return first user-id
This commit is contained in:
parent
31c7ae245a
commit
56e60e88f4
1 changed files with 8 additions and 22 deletions
|
@ -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,
|
* 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
|
* @return primary user-id or null
|
||||||
*/
|
*/
|
||||||
private String findPrimaryUserId() {
|
private String findPrimaryUserId() {
|
||||||
String nonPrimaryUserId = null;
|
|
||||||
String primaryUserId = null;
|
String primaryUserId = null;
|
||||||
Date modificationDate = null;
|
Date currentModificationDate = null;
|
||||||
|
|
||||||
List<String> userIds = getUserIds();
|
List<String> userIds = getUserIds();
|
||||||
if (userIds.isEmpty()) {
|
if (userIds.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String firstUserId = userIds.get(0);
|
||||||
if (userIds.size() == 1) {
|
if (userIds.size() == 1) {
|
||||||
return userIds.get(0);
|
return firstUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String userId : userIds) {
|
for (String userId : userIds) {
|
||||||
|
@ -291,25 +291,11 @@ public class KeyRingInfo {
|
||||||
Date creationTime = certification.getCreationTime();
|
Date creationTime = certification.getCreationTime();
|
||||||
|
|
||||||
if (certification.getHashedSubPackets().isPrimaryUserID()) {
|
if (certification.getHashedSubPackets().isPrimaryUserID()) {
|
||||||
if (nonPrimaryUserId != null) {
|
if (currentModificationDate == null || creationTime.after(currentModificationDate)) {
|
||||||
nonPrimaryUserId = null;
|
|
||||||
modificationDate = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modificationDate == null || creationTime.after(modificationDate)) {
|
|
||||||
primaryUserId = userId;
|
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 primaryUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nonPrimaryUserId;
|
return firstUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue