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:
parent
76efbf2e45
commit
3bc07f045c
2 changed files with 6 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue