]> WPIA git - gigi.git/commitdiff
chg: cleanup locateCertificate method
authorFelix Dörre <felix@dogcraft.de>
Sun, 14 Jan 2018 14:18:56 +0000 (15:18 +0100)
committerFelix Dörre <felix@dogcraft.de>
Mon, 15 Jan 2018 00:34:05 +0000 (01:34 +0100)
Change-Id: I9254473df87895df0548331c817d833efe170944

src/club/wpia/gigi/dbObjects/Certificate.java

index 014c697f8fd5628d52a466817efbb9bf211949fa..28c32088fd1f09e302f0327f2168f534215c9650 100644 (file)
@@ -590,18 +590,13 @@ public class Certificate implements IdCachable {
     }
 
     public static Certificate locateCertificate(String serial, String certData) throws GigiApiException {
     }
 
     public static Certificate locateCertificate(String serial, String certData) throws GigiApiException {
-        Certificate c = null;
-
         if (serial != null && !serial.isEmpty()) {
         if (serial != null && !serial.isEmpty()) {
-            c = getBySerial(normalizeSerial(serial));
-            if (c == null) {
-                return null;
-            }
+            return getBySerial(normalizeSerial(serial));
         }
         }
+
         if (certData != null && !certData.isEmpty()) {
         if (certData != null && !certData.isEmpty()) {
-            X509Certificate c0;
-            X509Certificate cert = null;
             final byte[] supplied;
             final byte[] supplied;
+            final X509Certificate c0;
             try {
                 supplied = PEM.decode("CERTIFICATE", certData);
                 c0 = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(new ByteArrayInputStream(supplied));
             try {
                 supplied = PEM.decode("CERTIFICATE", certData);
                 c0 = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(new ByteArrayInputStream(supplied));
@@ -611,24 +606,22 @@ public class Certificate implements IdCachable {
                 throw new GigiApiException(NOT_PARSED);
             }
             try {
                 throw new GigiApiException(NOT_PARSED);
             }
             try {
-                c = getBySerial(c0.getSerialNumber());
+                Certificate c = getBySerial(c0.getSerialNumber());
                 if (c == null) {
                     return null;
                 }
                 if (c == null) {
                     return null;
                 }
-                cert = c.cert();
+                X509Certificate cert = c.cert();
                 if ( !Arrays.equals(supplied, cert.getEncoded())) {
                     return null;
                 }
                 if ( !Arrays.equals(supplied, cert.getEncoded())) {
                     return null;
                 }
+                return c;
             } catch (IOException e) {
                 throw new GigiApiException(NOT_LOADED);
             } catch (GeneralSecurityException e) {
                 throw new GigiApiException(NOT_LOADED);
             }
         }
             } catch (IOException e) {
                 throw new GigiApiException(NOT_LOADED);
             } catch (GeneralSecurityException e) {
                 throw new GigiApiException(NOT_LOADED);
             }
         }
-        if (c == null) {
-            throw new GigiApiException("No information to identify the correct certificate was provided.");
-        }
-        return c;
+        throw new GigiApiException("No information to identify the correct certificate was provided.");
     }
 
     public static BigInteger normalizeSerial(String serial) throws GigiApiException {
     }
 
     public static BigInteger normalizeSerial(String serial) throws GigiApiException {