mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
KeyRingCertificateStore: Allow for multiple PGPPublicKeyRingCollections as input
This commit is contained in:
parent
b1f33080e0
commit
34f706191d
1 changed files with 15 additions and 7 deletions
|
@ -15,24 +15,32 @@ import pgp.certificate_store.exception.BadNameException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of [PGPCertificateStore] which is based on a [PGPPublicKeyRingCollection].
|
* Implementation of [PGPCertificateStore] which is based on one or more [PGPPublicKeyRingCollection].
|
||||||
* During initialization, all items in the [PGPPublicKeyRingCollection] are converted into [Certificates][Certificate]
|
* During initialization, all items in the [PGPPublicKeyRingCollection]s are converted into [Certificates][Certificate]
|
||||||
* and stored in a map keyed by their fingerprints.
|
* and stored in a map keyed by their fingerprints.
|
||||||
|
*
|
||||||
|
* In case of fingerprint collisions across certificates from different collections, [Certificate] objects
|
||||||
|
* from a [PGPPublicKeyRingCollection] instance with a higher list index take precedence.
|
||||||
|
*
|
||||||
* [Certificates][Certificate] being inserted using [insertCertificate] or [insertCertificateBySpecialName] are also
|
* [Certificates][Certificate] being inserted using [insertCertificate] or [insertCertificateBySpecialName] are also
|
||||||
* stored in that map, but are not being written into the [PGPPublicKeyRingCollection].
|
* stored in that map, but are not being written into the [PGPPublicKeyRingCollection].
|
||||||
*/
|
*/
|
||||||
class KeyRingCertificateStore(baseKeyRing: PGPPublicKeyRingCollection) : PGPCertificateStore {
|
class KeyRingCertificateStore(baseKeyRings: List<PGPPublicKeyRingCollection>) : PGPCertificateStore {
|
||||||
|
|
||||||
// Keep certificates inserted only in memory
|
// Keep certificates inserted only in memory
|
||||||
private val certificates = mutableMapOf<String, Certificate>()
|
private val certificates = mutableMapOf<String, Certificate>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (publicKeyRing in baseKeyRing) {
|
baseKeyRings.forEach { store ->
|
||||||
val fingerprint = OpenPgpFingerprint.of(publicKeyRing).toString()
|
store.forEach {
|
||||||
val certificate = CertificateFactory.certificateFromPublicKeyRing(publicKeyRing, null)
|
val fingerprint = OpenPgpFingerprint.of(it).toString()
|
||||||
|
val certificate = CertificateFactory.certificateFromPublicKeyRing(it, null)
|
||||||
certificates[fingerprint] = certificate
|
certificates[fingerprint] = certificate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(baseKeyRing: PGPPublicKeyRingCollection): this(listOf(baseKeyRing))
|
||||||
|
|
||||||
override fun getCertificate(identifier: String?): Certificate {
|
override fun getCertificate(identifier: String?): Certificate {
|
||||||
if (identifier == null) {
|
if (identifier == null) {
|
||||||
|
|
Loading…
Reference in a new issue