I have a list and that list has an x509certificate
, which I use for storing in a cms package. All dandy, until I bump into the problem: I can't have the same person signing twice.
So, I know how to find that certificate by equals, so a linear search.
It may sound pure vanity, but I would rather use a binary search, using, obviously, comparable
.
How in heavens could i do that? (java or bouncyCastle).
Thanks
I want to thank Jens and dnault for guiding me to the answer:
I am going to sort and search the certificates using the (bigInteger) SerialNumber, which all certificates have, to compare and as soon as I find a similar serial, I am going to compare them in a DER encoded format.
Why did I not used the hash code approach, you may ask:
Not all the certificates and signatures will be in memory. Some, sometimes, will be in a PKCS7 (CMS), or a XMLDSig file. So The object's hashcode may differ, as physically they are different objects, but logically they refer to the same certificate.
Overriding getHashCode will only give half of the answer, as sometimes, not too often the serial number can occur twice, as it depends on the chain that it belongs to, among other factors.
Thank you for the info and the help.