SignatureDigestAlgorithm.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.  * SignatureDigestAlgorithm
  24.  *
  25.  * @author Poli Andrea (poli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public enum SignatureDigestAlgorithm {

  30.     SHA1("http://www.w3.org/2000/09/xmldsig#sha1"),
  31.     SHA224("http://www.w3.org/2001/04/xmldsig-more#sha224"),
  32.     SHA256("http://www.w3.org/2001/04/xmlenc#sha256"),
  33.     SHA384("http://www.w3.org/2000/09/xmldsig#sha384"),
  34.     SHA512("http://www.w3.org/2001/04/xmlenc#sha512");
  35.    
  36.     private String uri;
  37.     SignatureDigestAlgorithm(String uri) {
  38.         this.uri = uri;
  39.     }
  40.    
  41.     public String getUri() {
  42.         return this.uri;
  43.     }
  44.    
  45.     public static SignatureDigestAlgorithm toEnumConstant(String uri){
  46.         try{
  47.             return toEnumConstant(uri,false);
  48.         }catch(NotFoundException notFound){
  49.             return null;
  50.         }
  51.     }
  52.     public static SignatureDigestAlgorithm toEnumConstant(String uri, boolean throwNotFoundException) throws NotFoundException{
  53.         SignatureDigestAlgorithm res = null;
  54.         for (SignatureDigestAlgorithm tmp : values()) {
  55.             if(tmp.getUri().equals(uri)){
  56.                 res = tmp;
  57.                 break;
  58.             }
  59.         }
  60.         if(res==null && throwNotFoundException){
  61.             throw new NotFoundException("Enum with uri ["+uri+"] not found");
  62.         }
  63.         return res;
  64.     }
  65. }