Path: blob/master/test/jdk/sun/security/util/AlgorithmConstraints/DecomposeAlgorithms.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813641026* @summary AlgorithmDecomposer is not parsing padding correctly27* @modules java.base/sun.security.util28*/2930import sun.security.util.AlgorithmDecomposer;31import java.util.Set;3233public class DecomposeAlgorithms {3435public static void main(String[] args) throws Exception {36AlgorithmDecomposer decomposer = new AlgorithmDecomposer();3738check(decomposer, "AES/CBC/NoPadding", new String[] {39"AES", "CBC", "NoPadding"});40check(decomposer, "DES/CBC/PKCS5Padding", new String[] {41"DES", "CBC", "PKCS5Padding"});42check(decomposer, "RSA/ECB/OAEPWithSHA-1AndMGF1Padding", new String[] {43"RSA", "ECB", "OAEP", "SHA1", "SHA-1", "MGF1Padding"});44check(decomposer, "OAEPWithSHA-512AndMGF1Padding", new String[] {45"OAEP", "SHA512", "SHA-512", "MGF1Padding"});46check(decomposer, "OAEPWithSHA-512AndMGF1Padding", new String[] {47"OAEP", "SHA512", "SHA-512", "MGF1Padding"});48check(decomposer, "PBEWithSHA1AndRC2_40", new String[] {49"PBE", "SHA1", "SHA-1", "RC2_40"});50check(decomposer, "PBEWithHmacSHA224AndAES_128", new String[] {51"PBE", "HmacSHA224", "AES_128"});52}5354private static void check(AlgorithmDecomposer parser,55String fullAlgName, String[] components) throws Exception {5657Set<String> parsed = parser.decompose(fullAlgName);58if (parsed.size() != components.length) {59throw new Exception("Not expected components number: " + parsed);60}6162for (String component : components) {63if (!parsed.contains(component)) {64throw new Exception("Not a expected component: " + component);65}66}6768System.out.println("OK: " + fullAlgName);69}70}717273