bc-csharp icon indicating copy to clipboard operation
bc-csharp copied to clipboard

PgpPublicKey.RemoveCert can delete wrong items.

Open tohidemyname opened this issue 1 year ago • 0 comments

The code is as follows:

' private static PgpPublicKey RemoveCert(PgpPublicKey key, IUserDataPacket id) { PgpPublicKey returnKey = new PgpPublicKey(key); bool found = false;

 for (int i = 0; i <returnKey.ids.Count-1; i++) 
 {
     if (id.Equals(returnKey.ids[i]))
     {
         found = true;
         returnKey.ids.RemoveAt(i);
         returnKey.idTrusts.RemoveAt(i);
         returnKey.idSigs.RemoveAt(i);
     }
 }

 return found ? returnKey : null;

}' If returnKey.ids has more than one item, the first deletion will change the indexes of returnKey.*. The follow-up deletions will delete wrong items. My pull request is as follows:

https://github.com/bcgit/bc-csharp/pull/545

tohidemyname avatar Jun 21 '24 07:06 tohidemyname