1 /*
   2  * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.security.ucrypto;
  27 
  28 import java.util.List;
  29 import static sun.security.util.SecurityProviderConstants.getAliases;
  30 
  31 /**
  32  * Enum for representing the ucrypto mechanisms.
  33  *
  34  * @since 9
  35  */
  36 public enum LibMDMech {
  37 
  38     MD5(new ServiceDesc[]
  39         { sd("MessageDigest", "MD5", "com.oracle.security.ucrypto.NativeDigestMD$MD5")
  40         }),
  41     SHA_1(new ServiceDesc[]
  42         { sd("MessageDigest", "SHA-1", "com.oracle.security.ucrypto.NativeDigestMD$SHA1",
  43              getAliases("SHA-1"))
  44         }),
  45     SHA_256(new ServiceDesc[]
  46         { sd("MessageDigest", "SHA-256", "com.oracle.security.ucrypto.NativeDigestMD$SHA256",
  47              getAliases("SHA-256"))
  48         }),
  49     SHA_384(new ServiceDesc[]
  50         { sd("MessageDigest", "SHA-384", "com.oracle.security.ucrypto.NativeDigestMD$SHA384",
  51              getAliases("SHA-384"))
  52         }),
  53     SHA_512(new ServiceDesc[]
  54         { sd("MessageDigest", "SHA-512", "com.oracle.security.ucrypto.NativeDigestMD$SHA512",
  55              getAliases("SHA-512"))
  56         });
  57 
  58     ServiceDesc[] serviceDescs;
  59 
  60     private static ServiceDesc sd(String type, String algo, String cn) {
  61         return new ServiceDesc(type, algo, cn, null);
  62     }
  63 
  64     private static ServiceDesc sd(String type, String algo, String cn,
  65             List<String> aliases) {
  66         return new ServiceDesc(type, algo, cn, aliases);
  67     }
  68 
  69     LibMDMech(ServiceDesc[] serviceDescs) {
  70         this.serviceDescs = serviceDescs;
  71     }
  72 
  73     public ServiceDesc[] getServiceDescriptions() { return serviceDescs; }
  74 }