diff options
author | 2020-02-13 14:55:21 +0100 | |
---|---|---|
committer | 2020-02-13 14:55:21 +0100 | |
commit | 06f7465cebf967f6c1ffd9970b05158c00aa5ff1 (patch) | |
tree | ad950726b6da96f9af5ba898e7038d5984a87fee /certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java | |
parent | 459a31e973f55fd97831a9a7cae0dce664259a4e (diff) |
Improve exception flow
Issue-ID: AAF-995
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I4d690fbe27364bc50b97ab42e64e610566d93ca0
Diffstat (limited to 'certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java')
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java index 61ea0aaf..514101b9 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java @@ -22,22 +22,21 @@ package org.onap.aaf.certservice.certification; import java.io.IOException; import java.io.StringReader; +import java.util.Optional; import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemReader; -import org.onap.aaf.certservice.certification.exceptions.PemDecryptionException; - public class PemObjectFactory { - public PemObject createPemObject(String pem) throws PemDecryptionException { + public Optional<PemObject> createPemObject(String pem) { try (StringReader stringReader = new StringReader(pem); PemReader pemReader = new PemReader(stringReader)) { - return pemReader.readPemObject(); + return Optional.ofNullable(pemReader.readPemObject()); } catch (IOException e) { - throw new PemDecryptionException("Unable to create PEM", e); + return Optional.empty(); } } |