mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 10:19:39 +02:00
Add documentation
This commit is contained in:
parent
1fee94bf93
commit
a0624d8ac1
3 changed files with 27 additions and 24 deletions
|
@ -69,6 +69,13 @@ class PGPainless(
|
||||||
fun toCertificate(publicKeyRing: PGPPublicKeyRing): OpenPGPCertificate =
|
fun toCertificate(publicKeyRing: PGPPublicKeyRing): OpenPGPCertificate =
|
||||||
OpenPGPCertificate(publicKeyRing, implementation)
|
OpenPGPCertificate(publicKeyRing, implementation)
|
||||||
|
|
||||||
|
fun mergeCertificate(
|
||||||
|
originalCopy: OpenPGPCertificate,
|
||||||
|
updatedCopy: OpenPGPCertificate
|
||||||
|
): OpenPGPCertificate {
|
||||||
|
return OpenPGPCertificate.join(originalCopy, updatedCopy)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@Volatile private var instance: PGPainless? = null
|
@Volatile private var instance: PGPainless? = null
|
||||||
|
@ -120,7 +127,7 @@ class PGPainless(
|
||||||
* @return public key certificate
|
* @return public key certificate
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Deprecated("Use toKey() and then .toCertificate() instead.")
|
@Deprecated("Use .toKey() and then .toCertificate() instead.")
|
||||||
fun extractCertificate(secretKey: PGPSecretKeyRing) =
|
fun extractCertificate(secretKey: PGPSecretKeyRing) =
|
||||||
KeyRingUtils.publicKeyRingFrom(secretKey)
|
KeyRingUtils.publicKeyRingFrom(secretKey)
|
||||||
|
|
||||||
|
@ -134,6 +141,7 @@ class PGPainless(
|
||||||
* @throws PGPException in case of an error
|
* @throws PGPException in case of an error
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@Deprecated("Use mergeCertificate() instead.")
|
||||||
fun mergeCertificate(originalCopy: PGPPublicKeyRing, updatedCopy: PGPPublicKeyRing) =
|
fun mergeCertificate(originalCopy: PGPPublicKeyRing, updatedCopy: PGPPublicKeyRing) =
|
||||||
PGPPublicKeyRing.join(originalCopy, updatedCopy)
|
PGPPublicKeyRing.join(originalCopy, updatedCopy)
|
||||||
|
|
||||||
|
@ -229,7 +237,7 @@ class PGPainless(
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun inspectKeyRing(key: OpenPGPCertificate, referenceTime: Date = Date()) =
|
fun inspectKeyRing(key: OpenPGPCertificate, referenceTime: Date = Date()) =
|
||||||
KeyRingInfo(key, getPolicy(), referenceTime)
|
KeyRingInfo(key, getInstance().algorithmPolicy, referenceTime)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access, and make changes to PGPainless policy on acceptable/default algorithms etc.
|
* Access, and make changes to PGPainless policy on acceptable/default algorithms etc.
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ class OpenPgpMessageInputStream(
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(inputStream: InputStream, options: ConsumerOptions) =
|
fun create(inputStream: InputStream, options: ConsumerOptions) =
|
||||||
create(inputStream, options, PGPainless.getPolicy())
|
create(inputStream, options, PGPainless.getInstance().algorithmPolicy)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(inputStream: InputStream, options: ConsumerOptions, policy: Policy) =
|
fun create(inputStream: InputStream, options: ConsumerOptions, policy: Policy) =
|
||||||
|
|
|
@ -11,13 +11,12 @@ import org.bouncycastle.openpgp.api.OpenPGPImplementation
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey
|
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey
|
||||||
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey
|
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey
|
||||||
import org.pgpainless.PGPainless.Companion.getPolicy
|
import org.pgpainless.PGPainless
|
||||||
import org.pgpainless.PGPainless.Companion.inspectKeyRing
|
import org.pgpainless.PGPainless.Companion.inspectKeyRing
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType
|
import org.pgpainless.algorithm.DocumentSignatureType
|
||||||
import org.pgpainless.algorithm.HashAlgorithm
|
import org.pgpainless.algorithm.HashAlgorithm
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm.Companion.requireFromId
|
import org.pgpainless.algorithm.PublicKeyAlgorithm.Companion.requireFromId
|
||||||
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator.Companion.negotiateSignatureHashAlgorithm
|
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator.Companion.negotiateSignatureHashAlgorithm
|
||||||
import org.pgpainless.bouncycastle.extensions.toOpenPGPKey
|
|
||||||
import org.pgpainless.exception.KeyException
|
import org.pgpainless.exception.KeyException
|
||||||
import org.pgpainless.exception.KeyException.*
|
import org.pgpainless.exception.KeyException.*
|
||||||
import org.pgpainless.key.OpenPgpFingerprint.Companion.of
|
import org.pgpainless.key.OpenPgpFingerprint.Companion.of
|
||||||
|
@ -28,7 +27,7 @@ import org.pgpainless.signature.subpackets.BaseSignatureSubpackets.Callback
|
||||||
import org.pgpainless.signature.subpackets.SignatureSubpackets
|
import org.pgpainless.signature.subpackets.SignatureSubpackets
|
||||||
import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper
|
import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper
|
||||||
|
|
||||||
class SigningOptions {
|
class SigningOptions(val api: PGPainless = PGPainless.getInstance()) {
|
||||||
|
|
||||||
val signingMethods: Map<OpenPGPPrivateKey, SigningMethod> = mutableMapOf()
|
val signingMethods: Map<OpenPGPPrivateKey, SigningMethod> = mutableMapOf()
|
||||||
private var _hashAlgorithmOverride: HashAlgorithm? = null
|
private var _hashAlgorithmOverride: HashAlgorithm? = null
|
||||||
|
@ -91,7 +90,7 @@ class SigningOptions {
|
||||||
@Deprecated("Pass an OpenPGPKey instead.")
|
@Deprecated("Pass an OpenPGPKey instead.")
|
||||||
@Throws(KeyException::class, PGPException::class)
|
@Throws(KeyException::class, PGPException::class)
|
||||||
fun addSignature(signingKeyProtector: SecretKeyRingProtector, signingKey: PGPSecretKeyRing) =
|
fun addSignature(signingKeyProtector: SecretKeyRingProtector, signingKey: PGPSecretKeyRing) =
|
||||||
addSignature(signingKeyProtector, signingKey.toOpenPGPKey())
|
addSignature(signingKeyProtector, api.toKey(signingKey))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add inline signatures with all secret key rings in the provided secret key ring collection.
|
* Add inline signatures with all secret key rings in the provided secret key ring collection.
|
||||||
|
@ -137,7 +136,7 @@ class SigningOptions {
|
||||||
signingKeyProtector: SecretKeyRingProtector,
|
signingKeyProtector: SecretKeyRingProtector,
|
||||||
signingKey: PGPSecretKeyRing,
|
signingKey: PGPSecretKeyRing,
|
||||||
signatureType: DocumentSignatureType
|
signatureType: DocumentSignatureType
|
||||||
) = addInlineSignature(signingKeyProtector, signingKey.toOpenPGPKey(), signatureType)
|
) = addInlineSignature(signingKeyProtector, api.toKey(signingKey), signatureType)
|
||||||
|
|
||||||
fun addInlineSignature(
|
fun addInlineSignature(
|
||||||
signingKeyProtector: SecretKeyRingProtector,
|
signingKeyProtector: SecretKeyRingProtector,
|
||||||
|
@ -169,7 +168,8 @@ class SigningOptions {
|
||||||
val hashAlgorithms =
|
val hashAlgorithms =
|
||||||
if (userId != null) keyRingInfo.getPreferredHashAlgorithms(userId)
|
if (userId != null) keyRingInfo.getPreferredHashAlgorithms(userId)
|
||||||
else keyRingInfo.getPreferredHashAlgorithms(signingPubKey.keyIdentifier)
|
else keyRingInfo.getPreferredHashAlgorithms(signingPubKey.keyIdentifier)
|
||||||
val hashAlgorithm: HashAlgorithm = negotiateHashAlgorithm(hashAlgorithms, getPolicy())
|
val hashAlgorithm: HashAlgorithm =
|
||||||
|
negotiateHashAlgorithm(hashAlgorithms, api.algorithmPolicy)
|
||||||
addSigningMethod(
|
addSigningMethod(
|
||||||
signingPrivKey, hashAlgorithm, signatureType, false, subpacketsCallback)
|
signingPrivKey, hashAlgorithm, signatureType, false, subpacketsCallback)
|
||||||
}
|
}
|
||||||
|
@ -203,11 +203,7 @@ class SigningOptions {
|
||||||
subpacketsCallback: Callback? = null
|
subpacketsCallback: Callback? = null
|
||||||
) =
|
) =
|
||||||
addInlineSignature(
|
addInlineSignature(
|
||||||
signingKeyProtector,
|
signingKeyProtector, api.toKey(signingKey), userId, signatureType, subpacketsCallback)
|
||||||
signingKey.toOpenPGPKey(),
|
|
||||||
userId,
|
|
||||||
signatureType,
|
|
||||||
subpacketsCallback)
|
|
||||||
|
|
||||||
fun addInlineSignature(
|
fun addInlineSignature(
|
||||||
signingKeyProtector: SecretKeyRingProtector,
|
signingKeyProtector: SecretKeyRingProtector,
|
||||||
|
@ -228,7 +224,8 @@ class SigningOptions {
|
||||||
|
|
||||||
val signingPrivKey = unlockSecretKey(signingKey, signingKeyProtector)
|
val signingPrivKey = unlockSecretKey(signingKey, signingKeyProtector)
|
||||||
val hashAlgorithms = keyRingInfo.getPreferredHashAlgorithms(signingKey.keyIdentifier)
|
val hashAlgorithms = keyRingInfo.getPreferredHashAlgorithms(signingKey.keyIdentifier)
|
||||||
val hashAlgorithm: HashAlgorithm = negotiateHashAlgorithm(hashAlgorithms, getPolicy())
|
val hashAlgorithm: HashAlgorithm =
|
||||||
|
negotiateHashAlgorithm(hashAlgorithms, api.algorithmPolicy)
|
||||||
addSigningMethod(signingPrivKey, hashAlgorithm, signatureType, false, subpacketsCallback)
|
addSigningMethod(signingPrivKey, hashAlgorithm, signatureType, false, subpacketsCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +254,7 @@ class SigningOptions {
|
||||||
signatureType: DocumentSignatureType = DocumentSignatureType.BINARY_DOCUMENT,
|
signatureType: DocumentSignatureType = DocumentSignatureType.BINARY_DOCUMENT,
|
||||||
subpacketsCallback: Callback? = null
|
subpacketsCallback: Callback? = null
|
||||||
): SigningOptions {
|
): SigningOptions {
|
||||||
val key = signingKey.toOpenPGPKey()
|
val key = api.toKey(signingKey)
|
||||||
val subkeyIdentifier = KeyIdentifier(keyId)
|
val subkeyIdentifier = KeyIdentifier(keyId)
|
||||||
return addInlineSignature(
|
return addInlineSignature(
|
||||||
signingKeyProtector,
|
signingKeyProtector,
|
||||||
|
@ -374,11 +371,7 @@ class SigningOptions {
|
||||||
subpacketCallback: Callback? = null
|
subpacketCallback: Callback? = null
|
||||||
) =
|
) =
|
||||||
addDetachedSignature(
|
addDetachedSignature(
|
||||||
signingKeyProtector,
|
signingKeyProtector, api.toKey(signingKey), userId, signatureType, subpacketCallback)
|
||||||
signingKey.toOpenPGPKey(),
|
|
||||||
userId,
|
|
||||||
signatureType,
|
|
||||||
subpacketCallback)
|
|
||||||
|
|
||||||
fun addDetachedSignature(
|
fun addDetachedSignature(
|
||||||
signingKeyProtector: SecretKeyRingProtector,
|
signingKeyProtector: SecretKeyRingProtector,
|
||||||
|
@ -392,7 +385,8 @@ class SigningOptions {
|
||||||
val hashAlgorithms =
|
val hashAlgorithms =
|
||||||
if (userId != null) keyRingInfo.getPreferredHashAlgorithms(userId)
|
if (userId != null) keyRingInfo.getPreferredHashAlgorithms(userId)
|
||||||
else keyRingInfo.getPreferredHashAlgorithms(signingKey.keyIdentifier)
|
else keyRingInfo.getPreferredHashAlgorithms(signingKey.keyIdentifier)
|
||||||
val hashAlgorithm: HashAlgorithm = negotiateHashAlgorithm(hashAlgorithms, getPolicy())
|
val hashAlgorithm: HashAlgorithm =
|
||||||
|
negotiateHashAlgorithm(hashAlgorithms, api.algorithmPolicy)
|
||||||
addSigningMethod(signingPrivKey, hashAlgorithm, signatureType, true, subpacketCallback)
|
addSigningMethod(signingPrivKey, hashAlgorithm, signatureType, true, subpacketCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +416,7 @@ class SigningOptions {
|
||||||
signatureType: DocumentSignatureType = DocumentSignatureType.BINARY_DOCUMENT,
|
signatureType: DocumentSignatureType = DocumentSignatureType.BINARY_DOCUMENT,
|
||||||
subpacketsCallback: Callback? = null
|
subpacketsCallback: Callback? = null
|
||||||
): SigningOptions {
|
): SigningOptions {
|
||||||
val key = signingKey.toOpenPGPKey()
|
val key = api.toKey(signingKey)
|
||||||
val signingKeyIdentifier = KeyIdentifier(keyId)
|
val signingKeyIdentifier = KeyIdentifier(keyId)
|
||||||
return addDetachedSignature(
|
return addDetachedSignature(
|
||||||
signingKeyProtector,
|
signingKeyProtector,
|
||||||
|
@ -443,7 +437,8 @@ class SigningOptions {
|
||||||
val signingSecretKey: PGPSecretKey = signingKey.secretKey.pgpSecretKey
|
val signingSecretKey: PGPSecretKey = signingKey.secretKey.pgpSecretKey
|
||||||
val publicKeyAlgorithm = requireFromId(signingSecretKey.publicKey.algorithm)
|
val publicKeyAlgorithm = requireFromId(signingSecretKey.publicKey.algorithm)
|
||||||
val bitStrength = signingSecretKey.publicKey.bitStrength
|
val bitStrength = signingSecretKey.publicKey.bitStrength
|
||||||
if (!getPolicy().publicKeyAlgorithmPolicy.isAcceptable(publicKeyAlgorithm, bitStrength)) {
|
if (!api.algorithmPolicy.publicKeyAlgorithmPolicy.isAcceptable(
|
||||||
|
publicKeyAlgorithm, bitStrength)) {
|
||||||
throw UnacceptableSigningKeyException(
|
throw UnacceptableSigningKeyException(
|
||||||
PublicKeyAlgorithmPolicyException(
|
PublicKeyAlgorithmPolicyException(
|
||||||
signingKey.secretKey, publicKeyAlgorithm, bitStrength))
|
signingKey.secretKey, publicKeyAlgorithm, bitStrength))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue