KeystoreType.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.utils.certificate;

  21. /**
  22.  * Contiene i tipi di keystore
  23.  *
  24.  * @author corallo@link.it
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */

  28. public enum KeystoreType {

  29.     JKS ("jks","JKS"),
  30.     PKCS12 ("pkcs12","PKCS12"),
  31.     PKCS11 ("pkcs11","PKCS11"),
  32.     PKCS8 ("pkcs8","PKCS8"),
  33.     PKCS1 ("pkcs1","PKCS1"),
  34.     JCEKS ("jceks","JCEKS"),
  35.     JWK_SET ("jwk","JWK Set"),
  36.     PUBLIC_KEY ("public","Public Key"),
  37.     KEY_PAIR ("keys","Key Pair"),
  38.     SYMMETRIC_KEY ("symm", "Symmetric Key"),
  39.     PASSWORD_KEY_DERIVATION ("pass", "Password Key Derivation");
  40.    
  41.    
  42.     private final String nome;
  43.     private final String label;

  44.     KeystoreType(String nome, String label)
  45.     {
  46.         this.nome = nome;
  47.         this.label = label;
  48.     }

  49.     public String getNome()
  50.     {
  51.         return this.nome;
  52.     }

  53.     public String getLabel() {
  54.         if(this.label!=null) {
  55.             return this.label;
  56.         }
  57.         return this.nome;
  58.     }

  59.    
  60.     @Override
  61.     public String toString() {
  62.         return this.nome;
  63.     }
  64.    
  65.     public boolean isType(String value) {
  66.         return this.nome.equalsIgnoreCase(value);
  67.     }
  68.    
  69.     public static KeystoreType toEnumFromName(String name) {
  70.         KeystoreType [] tipi = KeystoreType.values();
  71.         for (int i = 0; i < tipi.length; i++) {
  72.             KeystoreType tipo = tipi[i];
  73.             if(tipo.getNome().equals(name)) {
  74.                 return tipo;
  75.             }
  76.         }
  77.         return null;
  78.     }
  79.     public static KeystoreType toEnumFromLabel(String label) {
  80.         KeystoreType [] tipi = KeystoreType.values();
  81.         for (int i = 0; i < tipi.length; i++) {
  82.             KeystoreType tipo = tipi[i];
  83.             if(tipo.getLabel().equals(label)) {
  84.                 return tipo;
  85.             }
  86.         }
  87.         return null;
  88.     }
  89. }