CertificateValidity.java

/*
** Module   : CertificateValidity.java
** Abstract : CertificateValidity lists certificate's validity types.
**
** Copyright (c) 2017, Golden Code Development Corporation.
**
** -#- -I- --Date-- ----------------Description----------------------
** 001 SBI 20170601 Created initial version.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.admin.client.application.home.accounts;

/**
 * CertificateValidity lists certificate's validity types.
 */
public enum CertificateValidity
{
   /** Defines that the certificate is valid */
   CERT_VALID(0, "valid"),
   
   /** Defines that its PEM definition is broken */
   CERT_INVALID_BROKEN(1, "invalid: PEM definition broken"),
   
   /** Defines that the certificate is invalid */
   CERT_INVALID_NOT_YET_VALID(2, "not yet valid"),
   
   /** Defines that the certificate is expired */
   CERT_INVALID_EXPIRED(3, "expired"),
   
   /** Defines that the certificate peer is self-signed */
   CERT_INVALID_PEER_SELF_SIGNED(4, "invalid: peer certificate is self-signed"),
   
   /** Defines that the peer certificate is not signed by a CA certificate */
   CERT_INVALID_PEER_NOT_SIGNED_BY_CA(5, "invalid: peer certificate not signed by a CA certificate"),
   
   /** Defines that the signer certificate is not found */
   CERT_INVALID_SIGNER_NOT_FOUND(6, "invalid: signer certificate not found"),
   
   /** Defines that the CA certificate is signed by Peer certificate */
   CERT_INVALID_CA_NOT_SIGNED_BY_CA(7, "invalid: CA certificate is signed by Peer certificate"),
   
   /** Defines that the signer's public key is invalid */
   CERT_INVALID_CORRUPTED1(8, "invalid: invalid signer's public key"),
   
   /** Defines that there is no such security provider */
   CERT_INVALID_CORRUPTED2(9, "invalid: no such security provider"),
   
   /** Defines that there is no such digital signature algorithm */
   CERT_INVALID_CORRUPTED3(10, "invalid: no such digital signature algorithm"),
   
   /** Defines that the signature does not match contents */
   CERT_INVALID_CORRUPTED4(11, "invalid: signature does not match contents"),
   
   /** Defines that the certificate encoding is invalid */
   CERT_INVALID_CORRUPTED5(12, "invalid: invalid certificate encoding"),
   
   /** Defines that the certificate validity state is unknown */
   CERT_UNKNOWN(13, "**unknown state**");

   /**
    * Constructs the certificate validity constant by its code and its description.
    * 
    * @param    code
    *           The certificate validity code
    * @param    validityMessage
    *           The certificate validity description
    */
   private CertificateValidity(int code, String validityMessage)
   {
      this.validityMessage = validityMessage;
      this.code = code;
   }

   /** The certificate validity description */
   private final String validityMessage;
   
   /** The certificate validity code */
   private final int code;
   
   /**
    * Gets the certificate validity description.
    * 
    * @return   The certificate validity description
    */
   public String getValidityMessage()
   {
      return validityMessage;
   }
   
   /**
    * Gets the certificate validity code.
    * 
    * @return   The certificate validity code
    */
   public int getCode()
   {
      return code;
   }

   /**
    * Gets the certificate validity constant by the given code 
    * @param    code
    *           The certificate validity code
    * 
    * @return   The certificate validity constant
    */
   public static CertificateValidity get(Integer code)
   {
      if (code == null)
      {
         return CERT_UNKNOWN;
      }
      
      for(CertificateValidity value : values())
      {
         if (code.intValue() == value.getCode())
         {
            return value;
         }
      }
      
      return CERT_UNKNOWN;
   }
}