Skip to content

Commit

Permalink
fix: increase exception completeness
Browse files Browse the repository at this point in the history
adjusted to include PEMException coverage

[#TPCF-6875]
[#TPCF-6876]
  • Loading branch information
Tallicia committed Aug 20, 2024
1 parent 432e0ea commit 9a26c18
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudfoundry.credhub.utils

import org.bouncycastle.asn1.pkcs.PrivateKeyInfo
import org.bouncycastle.openssl.PEMException
import org.bouncycastle.openssl.PEMKeyPair
import org.bouncycastle.openssl.PEMParser
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
Expand All @@ -24,8 +25,13 @@ class PrivateKeyReader private constructor() {
pemParser = PEMParser(StringReader(privateKeyPem!!))
parsed = pemParser.readObject()
pemParser.close()
} catch (e: DecoderException) {
throw MalformedPrivateKeyException("Keys must be PEM-encoded PKCS#1 or unencrypted PKCS#8 keys.")
} catch (ex: Exception) {
when (ex) {
is DecoderException, is PEMException -> {
throw MalformedPrivateKeyException("Keys must be PEM-encoded PKCS#1 or unencrypted PKCS#8 keys.")
}
else -> throw ex
}
}

return when (parsed) {
Expand Down

0 comments on commit 9a26c18

Please sign in to comment.