SignatureAlgorithm.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.security.message.constants;

  21. import org.openspcoop2.generic_project.exception.NotFoundException;

  22. /**    
  23.  * SignatureAlgorithm
  24.  *
  25.  * @author Poli Andrea (poli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public enum SignatureAlgorithm {

  30.     DSA_SHA1("http://www.w3.org/2000/09/xmldsig#dsa-sha1"),
  31.     DSA_SHA256("http://www.w3.org/2009/xmldsig11#dsa-sha256"),
  32.     RSA_SHA1("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
  33.     RSA_SHA224("http://www.w3.org/2001/04/xmldsig-more#rsa-sha224"),
  34.     RSA_SHA256("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"),
  35.     RSA_SHA384("http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"),
  36.     RSA_SHA512("http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"),
  37.     ECDSA_SHA1("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"),
  38.     ECDSA_SHA224("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha224"),
  39.     ECDSA_SHA256("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"),
  40.     ECDSA_SHA384("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"),
  41.     ECDSA_SHA512("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"),
  42.     HMAC_SHA1("http://www.w3.org/2000/09/xmldsig#hmac-sha1"),
  43.     HMAC_SHA224("http://www.w3.org/2001/04/xmldsig-more#hmac-sha224"),
  44.     HMAC_SHA256("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256"),
  45.     HMAC_SHA384("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384"),
  46.     HMAC_SHA512("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512");
  47.    
  48.    
  49.     private String uri;
  50.     SignatureAlgorithm(String uri) {
  51.         this.uri = uri;
  52.     }
  53.    
  54.     public String getUri() {
  55.         return this.uri;
  56.     }
  57.    
  58.     public static SignatureAlgorithm toEnumConstant(String uri){
  59.         try{
  60.             return toEnumConstant(uri,false);
  61.         }catch(NotFoundException notFound){
  62.             return null;
  63.         }
  64.     }
  65.     public static SignatureAlgorithm toEnumConstant(String uri, boolean throwNotFoundException) throws NotFoundException{
  66.         SignatureAlgorithm res = null;
  67.         for (SignatureAlgorithm tmp : values()) {
  68.             if(tmp.getUri().equals(uri)){
  69.                 res = tmp;
  70.                 break;
  71.             }
  72.         }
  73.         if(res==null && throwNotFoundException){
  74.             throw new NotFoundException("Enum with uri ["+uri+"] not found");
  75.         }
  76.         return res;
  77.     }
  78. }