]> WPIA git - gigi.git/commitdiff
Adding "Error" as Certificate status.
authorFelix Dörre <felix@dogcraft.de>
Wed, 9 Jul 2014 14:38:03 +0000 (16:38 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 10 Jul 2014 22:35:13 +0000 (00:35 +0200)
src/org/cacert/gigi/Certificate.java

index 47efacce6b33df4e4d38a86f8b73a91ee50c1c2a..c6924132cdc8c0445e3bcbee2e88d34112251b31 100644 (file)
@@ -30,14 +30,48 @@ public class Certificate {
        }
 
        public enum CertificateStatus {
-               DRAFT(false), BEING_ISSUED(true), ISSUED(false), BEING_REVOKED(true), REVOKED(
-                               false);
+               /**
+                * This certificate is not in the database, has no id and only exists as
+                * this java object.
+                */
+               DRAFT(false),
+               /**
+                * The certificate has been written to the database and is waiting for
+                * the signer to sign it.
+                */
+               SIGNING(true),
+               /**
+                * The certificate has been signed. It is stored in the database.
+                * {@link Certificate#cert()} is valid.
+                */
+               ISSUED(false),
+               /**
+                * The cetrificate is about to be revoked by the signer bot.
+                */
+               BEING_REVOKED(true),
+
+               /**
+                * The certificate has been revoked.
+                */
+               REVOKED(false),
+
+               /**
+                * If this certificate cannot be updated because an error happened in
+                * the signer.
+                */
+               ERROR(false);
 
                private boolean unstable;
 
                private CertificateStatus(boolean unstable) {
                        this.unstable = unstable;
                }
+               /**
+                * Checks, iff this certificate stage will be left by signer actions.
+                * 
+                * @return True, iff this certificate stage will be left by signer
+                *         actions.
+                */
                public boolean isUnstable() {
                        return unstable;
                }
@@ -47,15 +81,21 @@ public class Certificate {
                if (id == 0) {
                        return CertificateStatus.DRAFT;
                }
-               PreparedStatement searcher = DatabaseConnection.getInstance().prepare(
-                               "SELECT crt_name, created, revoked FROM emailcerts WHERE id=?");
+               PreparedStatement searcher = DatabaseConnection
+                               .getInstance()
+                               .prepare(
+                                               "SELECT crt_name, created, revoked, warning FROM emailcerts WHERE id=?");
                searcher.setInt(1, id);
                ResultSet rs = searcher.executeQuery();
                if (!rs.next()) {
                        throw new IllegalStateException("Certificate not in Database");
                }
+               if (rs.getInt(4) >= 3) {
+                       return CertificateStatus.ERROR;
+               }
+
                if (rs.getString(2) == null) {
-                       return CertificateStatus.BEING_ISSUED;
+                       return CertificateStatus.SIGNING;
                }
                crtName = rs.getString(1);
                System.out.println(crtName);