Get keyrings from keyring collections in the original order

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get keyrings from keyring collections in the original order

Ivan Pizhenko
Hi, I am trying to use JcaPGPPublicKeyRingCollection and JcaPGPSecretKeyRingCollection in Java. According to sources, they both have member "order" which store keyrings in the order they've appeared. But there's no possibility to get them out in that order - iterators use map. I understand that this might have been done for a purpose, but I have a need to get the keyrings in the original order. I was thinking I could solve this by inheriting from that class, but they are private and thus are inaccessible derived class. Now I ended up with using reflection to access them, but that's obviously a hack.  I'd like to have these classes extended with a method which will makes possible to extract keyrings from the "order" into an external collection. This will let to get keyrings in the original order and prevent decreasing access level of the "order" to say "protected". Just something simple like this:

void extractInOrder(Collection<PGPPublicKeyRing> dest)
{
  dest.addAll(order);
}

and

void extractInOrder(Collection<PGPSecretKeyRing> dest)
{
  dest.addAll(order);
}

Can you please add something like this?

I declare the above code as public domain and you can include it as is or with any suitable modifications - under conditions:
I do not provide any warranty of any kind regarding the above code, and in no event I will be responsible for any damages or losses of any kind raised from use of that code.

WBW, Ivan.

Reply | Threaded
Open this post in threaded view
|

Re: Get keyrings from keyring collections in the original order

Ivan Pizhenko
Just noticed that "order" contains key ids.

then code to extract keys becomes something like this:

void extractInOrder(Collection<PGPPublicKeyRing> dest)
{
  for (final Long keyId: order) {
     dest.add(pubRings.get(keyId));
  }
}


void extractInOrder(Collection<PGPSecretKeyRing> dest)
{
  for (final Long keyId: order) {
     dest.add(secretRings.get(keyId));
  }
}



--- Оригінальне повідомлення ---
Від кого: "Ivan Pizhenko" <[hidden email]>
Дата: 18 березня 2021, 20:46:37

Hi, I am trying to use JcaPGPPublicKeyRingCollection and JcaPGPSecretKeyRingCollection in Java. According to sources, they both have member "order" which store keyrings in the order they've appeared. But there's no possibility to get them out in that order - iterators use map. I understand that this might have been done for a purpose, but I have a need to get the keyrings in the original order. I was thinking I could solve this by inheriting from that class, but they are private and thus are inaccessible derived class. Now I ended up with using reflection to access them, but that's obviously a hack.  I'd like to have these classes extended with a method which will makes possible to extract keyrings from the "order" into an external collection. This will let to get keyrings in the original order and prevent decreasing access level of the "order" to say "protected". Just something simple like this:

void extractInOrder(Collection<PGPPublicKeyRing> dest)
{
  dest.addAll(order);
}

and

void extractInOrder(Collection<PGPSecretKeyRing> dest)
{
  dest.addAll(order);
}

Can you please add something like this?

I declare the above code as public domain and you can include it as is or with any suitable modifications - under conditions:
I do not provide any warranty of any kind regarding the above code, and in no event I will be responsible for any damages or losses of any kind raised from use of that code.

WBW, Ivan.