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

  30.     // Di fatto รจ EncryptAsymmetricKeyWrapAlgorithm
  31.    
  32.     RSA_OAEP("http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"),
  33.     RSA_OAEP_11("http://www.w3.org/2009/xmlenc11#rsa-oaep"),
  34.     RSA_v1dot5("http://www.w3.org/2001/04/xmlenc#rsa-1_5"),
  35.     DIFFIE_HELLMAN("http://www.w3.org/2001/04/xmlenc#dh");
  36.    
  37.     private String uri;
  38.     EncryptionKeyTransportAlgorithm(String uri) {
  39.         this.uri = uri;
  40.     }
  41.    
  42.     public String getUri() {
  43.         return this.uri;
  44.     }
  45.    
  46.     public static EncryptionKeyTransportAlgorithm toEnumConstant(String uri){
  47.         try{
  48.             return toEnumConstant(uri,false);
  49.         }catch(NotFoundException notFound){
  50.             return null;
  51.         }
  52.     }
  53.     public static EncryptionKeyTransportAlgorithm toEnumConstant(String uri, boolean throwNotFoundException) throws NotFoundException{
  54.         EncryptionKeyTransportAlgorithm res = null;
  55.         for (EncryptionKeyTransportAlgorithm tmp : values()) {
  56.             if(tmp.getUri().equals(uri)){
  57.                 res = tmp;
  58.                 break;
  59.             }
  60.         }
  61.         if(res==null && throwNotFoundException){
  62.             throw new NotFoundException("Enum with uri ["+uri+"] not found");
  63.         }
  64.         return res;
  65.     }
  66. }