mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Rename and document members of SubkeyIdentifier
This commit is contained in:
parent
5265dcdfeb
commit
94dc25aa8b
2 changed files with 110 additions and 34 deletions
|
@ -11,59 +11,135 @@ import org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey
|
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tuple class used to identify a subkey by fingerprints of the primary key of the subkeys key ring,
|
* Tuple class used to identify a subkey (component key) by fingerprints of the certificate,
|
||||||
* as well as the subkeys fingerprint.
|
* as well as the component keys fingerprint.
|
||||||
*/
|
*/
|
||||||
class SubkeyIdentifier(
|
class SubkeyIdentifier(
|
||||||
val primaryKeyFingerprint: OpenPgpFingerprint,
|
val certificateFingerprint: OpenPgpFingerprint,
|
||||||
val subkeyFingerprint: OpenPgpFingerprint
|
val componentKeyFingerprint: OpenPgpFingerprint
|
||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(fingerprint: OpenPgpFingerprint) : this(fingerprint, fingerprint)
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to the primary key identified by the
|
||||||
|
* [certificateFingerprint].
|
||||||
|
* @param certificateFingerprint primary key fingerprint
|
||||||
|
*/
|
||||||
|
constructor(certificateFingerprint: OpenPgpFingerprint) : this(certificateFingerprint, certificateFingerprint)
|
||||||
|
|
||||||
constructor(keys: PGPKeyRing) : this(keys.publicKey)
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to the primary key of the given [PGPKeyRing].
|
||||||
|
*
|
||||||
|
* @param certificate certificate
|
||||||
|
*/
|
||||||
|
constructor(certificate: PGPKeyRing) : this(certificate.publicKey)
|
||||||
|
|
||||||
constructor(key: PGPPublicKey) : this(OpenPgpFingerprint.of(key))
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to the given [primaryKey].
|
||||||
|
*
|
||||||
|
* @param primaryKey primary key
|
||||||
|
*/
|
||||||
|
constructor(primaryKey: PGPPublicKey) : this(OpenPgpFingerprint.of(primaryKey))
|
||||||
|
|
||||||
constructor(keys: PGPKeyRing, keyId: Long) : this(keys, KeyIdentifier(keyId))
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to a component key (identified by
|
||||||
|
* [componentKeyId]) from the given [certificate].
|
||||||
|
*/
|
||||||
|
@Deprecated("Pass in a KeyIdentifier instead of a keyId.")
|
||||||
|
constructor(certificate: PGPKeyRing, componentKeyId: Long) : this(certificate, KeyIdentifier(componentKeyId))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to the given [componentKey].
|
||||||
|
*
|
||||||
|
* @param componentKey component key
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
key: OpenPGPComponentKey
|
componentKey: OpenPGPComponentKey
|
||||||
) : this(
|
) : this(
|
||||||
OpenPgpFingerprint.of(key.certificate.pgpPublicKeyRing),
|
OpenPgpFingerprint.of(componentKey.certificate),
|
||||||
OpenPgpFingerprint.of(key.pgpPublicKey))
|
OpenPgpFingerprint.of(componentKey))
|
||||||
|
|
||||||
constructor(key: OpenPGPPrivateKey) : this(key.secretKey)
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to the given [componentKey].
|
||||||
|
*/
|
||||||
|
constructor(componentKey: OpenPGPPrivateKey) : this(componentKey.secretKey)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to a component key (identified by
|
||||||
|
* the [componentKeyFingerprint]) of the given [certificate].
|
||||||
|
*
|
||||||
|
* @param certificate certificate
|
||||||
|
* @param componentKeyFingerprint fingerprint of the component key
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
keys: PGPKeyRing,
|
certificate: PGPKeyRing,
|
||||||
subkeyFingerprint: OpenPgpFingerprint
|
componentKeyFingerprint: OpenPgpFingerprint
|
||||||
) : this(OpenPgpFingerprint.of(keys), subkeyFingerprint)
|
) : this(OpenPgpFingerprint.of(certificate), componentKeyFingerprint)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for a [SubkeyIdentifier] pointing to a component key (identified by the
|
||||||
|
* [componentKeyIdentifier]) of the given [certificate].
|
||||||
|
*
|
||||||
|
* @param certificate certificate
|
||||||
|
* @param componentKeyIdentifier identifier of the component key
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
keys: PGPKeyRing,
|
certificate: PGPKeyRing,
|
||||||
subkeyIdentifier: KeyIdentifier
|
componentKeyIdentifier: KeyIdentifier
|
||||||
) : this(
|
) : this(
|
||||||
OpenPgpFingerprint.of(keys),
|
OpenPgpFingerprint.of(certificate),
|
||||||
OpenPgpFingerprint.of(
|
OpenPgpFingerprint.of(
|
||||||
keys.getPublicKey(subkeyIdentifier)
|
certificate.getPublicKey(componentKeyIdentifier)
|
||||||
?: throw NoSuchElementException(
|
?: throw NoSuchElementException(
|
||||||
"OpenPGP key does not contain subkey $subkeyIdentifier")))
|
"OpenPGP key does not contain subkey $componentKeyIdentifier")))
|
||||||
|
|
||||||
val keyIdentifier = KeyIdentifier(subkeyFingerprint.bytes)
|
@Deprecated("Use certificateFingerprint instead.",
|
||||||
val subkeyIdentifier = keyIdentifier
|
replaceWith = ReplaceWith("certificateFingerprint")
|
||||||
val primaryKeyIdentifier = KeyIdentifier(primaryKeyFingerprint.bytes)
|
)
|
||||||
|
val primaryKeyFingerprint: OpenPgpFingerprint = certificateFingerprint
|
||||||
|
|
||||||
|
@Deprecated("Use componentKeyFingerprint instead.",
|
||||||
|
replaceWith = ReplaceWith("componentKeyFingerprint"))
|
||||||
|
val subkeyFingerprint: OpenPgpFingerprint = componentKeyFingerprint
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [KeyIdentifier] of the component key.
|
||||||
|
*/
|
||||||
|
val keyIdentifier = componentKeyFingerprint.keyIdentifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [KeyIdentifier] of the component key.
|
||||||
|
*/
|
||||||
|
val componentKeyIdentifier = keyIdentifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [KeyIdentifier] of the primary key of the certificate the component key belongs to.
|
||||||
|
*/
|
||||||
|
val certificateIdentifier = certificateFingerprint.keyIdentifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key-ID of the component key.
|
||||||
|
*/
|
||||||
@Deprecated("Use of key-ids is discouraged.") val keyId = keyIdentifier.keyId
|
@Deprecated("Use of key-ids is discouraged.") val keyId = keyIdentifier.keyId
|
||||||
val fingerprint = subkeyFingerprint
|
|
||||||
|
|
||||||
@Deprecated("Use of key-ids is discouraged.") val subkeyId = subkeyIdentifier.keyId
|
/**
|
||||||
@Deprecated("Use of key-ids is discouraged.") val primaryKeyId = primaryKeyIdentifier.keyId
|
* Fingerprint of the component key.
|
||||||
|
*/
|
||||||
|
val fingerprint = componentKeyFingerprint
|
||||||
|
|
||||||
val isPrimaryKey = primaryKeyIdentifier == subkeyIdentifier
|
/**
|
||||||
|
* Key-ID of the component key.
|
||||||
|
*/
|
||||||
|
@Deprecated("Use of key-ids is discouraged.") val subkeyId = componentKeyIdentifier.keyId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key-ID of the primary key of the certificate the component key belongs to.
|
||||||
|
*/
|
||||||
|
@Deprecated("Use of key-ids is discouraged.") val primaryKeyId = certificateIdentifier.keyId
|
||||||
|
|
||||||
|
val isPrimaryKey = certificateIdentifier.matches(componentKeyIdentifier)
|
||||||
|
|
||||||
fun matches(fingerprint: OpenPgpFingerprint) =
|
fun matches(fingerprint: OpenPgpFingerprint) =
|
||||||
primaryKeyFingerprint == fingerprint || subkeyFingerprint == fingerprint
|
certificateFingerprint == fingerprint || componentKeyFingerprint == fingerprint
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other == null) {
|
if (other == null) {
|
||||||
|
@ -76,13 +152,13 @@ class SubkeyIdentifier(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return primaryKeyFingerprint == other.primaryKeyFingerprint &&
|
return certificateFingerprint == other.certificateFingerprint &&
|
||||||
subkeyFingerprint == other.subkeyFingerprint
|
componentKeyFingerprint == other.componentKeyFingerprint
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return primaryKeyFingerprint.hashCode() + 31 * subkeyFingerprint.hashCode()
|
return certificateFingerprint.hashCode() + 31 * componentKeyFingerprint.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "$subkeyFingerprint $primaryKeyFingerprint"
|
override fun toString(): String = "$componentKeyFingerprint $certificateFingerprint"
|
||||||
}
|
}
|
||||||
|
|
|
@ -594,7 +594,7 @@ class KeyRingInfo(
|
||||||
require(publicKey.keyIdentifier.equals(identifier.keyIdentifier)) {
|
require(publicKey.keyIdentifier.equals(identifier.keyIdentifier)) {
|
||||||
"Mismatching primary key ID."
|
"Mismatching primary key ID."
|
||||||
}
|
}
|
||||||
return getPublicKey(identifier.subkeyIdentifier)
|
return getPublicKey(identifier.componentKeyIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -605,7 +605,7 @@ class KeyRingInfo(
|
||||||
* key of the key.
|
* key of the key.
|
||||||
*/
|
*/
|
||||||
fun getSecretKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? =
|
fun getSecretKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? =
|
||||||
getSecretKey(identifier.subkeyIdentifier)
|
getSecretKey(identifier.componentKeyIdentifier)
|
||||||
|
|
||||||
fun isKeyValidlyBound(keyIdentifier: KeyIdentifier): Boolean {
|
fun isKeyValidlyBound(keyIdentifier: KeyIdentifier): Boolean {
|
||||||
return isKeyValidlyBound(keyIdentifier.keyId)
|
return isKeyValidlyBound(keyIdentifier.keyId)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue