1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 02:09:38 +02:00

Prevent NULL encryption algorithm

This commit is contained in:
Paul Schaub 2025-05-06 17:05:47 +02:00
parent 76efbf2e45
commit 3bc07f045c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 6 additions and 4 deletions

View file

@ -4,7 +4,6 @@
package org.pgpainless.algorithm.negotiation
import java.lang.IllegalArgumentException
import org.pgpainless.algorithm.SymmetricKeyAlgorithm
import org.pgpainless.policy.Policy
@ -36,9 +35,8 @@ interface SymmetricKeyAlgorithmNegotiator {
override: SymmetricKeyAlgorithm?,
keyPreferences: List<Set<SymmetricKeyAlgorithm>>
): SymmetricKeyAlgorithm {
if (override == SymmetricKeyAlgorithm.NULL) {
throw IllegalArgumentException(
"Algorithm override cannot be NULL (plaintext).")
require (override != SymmetricKeyAlgorithm.NULL) {
"Algorithm override cannot be NULL (plaintext)."
}
if (override != null) {

View file

@ -405,6 +405,10 @@ class EncryptionOptions(private val purpose: EncryptionPurpose, private val api:
}
fun overrideEncryptionMechanism(encryptionMechanism: MessageEncryptionMechanism) = apply {
require(api.algorithmPolicy.symmetricKeyEncryptionAlgorithmPolicy.isAcceptable(
encryptionMechanism.symmetricKeyAlgorithm)) {
"Provided symmetric encryption algorithm is not acceptable."
}
_encryptionMechanismOverride = encryptionMechanism
}