1 /*
2 * Copyright (c) 1997, 2017, 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
304
305 private static String[] tokenizeTransformation(String transformation)
306 throws NoSuchAlgorithmException {
307 if (transformation == null) {
308 throw new NoSuchAlgorithmException("No transformation given");
309 }
310 /*
311 * array containing the components of a Cipher transformation:
312 *
313 * index 0: algorithm component (e.g., AES)
314 * index 1: feedback component (e.g., CFB)
315 * index 2: padding component (e.g., PKCS5Padding)
316 */
317 String[] parts = new String[3];
318 int count = 0;
319 StringTokenizer parser = new StringTokenizer(transformation, "/");
320 try {
321 while (parser.hasMoreTokens() && count < 3) {
322 parts[count++] = parser.nextToken().trim();
323 }
324 if (count == 0 || count == 2 || parser.hasMoreTokens()) {
325 throw new NoSuchAlgorithmException("Invalid transformation"
326 + " format:" +
327 transformation);
328 }
329 } catch (NoSuchElementException e) {
330 throw new NoSuchAlgorithmException("Invalid transformation " +
331 "format:" + transformation);
332 }
333 if ((parts[0] == null) || (parts[0].length() == 0)) {
334 throw new NoSuchAlgorithmException("Invalid transformation:" +
335 "algorithm not specified-"
336 + transformation);
337 }
338 return parts;
339 }
340
341 // Provider attribute name for supported chaining mode
342 private static final String ATTR_MODE = "SupportedModes";
343 // Provider attribute name for supported padding names
344 private static final String ATTR_PAD = "SupportedPaddings";
345
346 // constants indicating whether the provider supports
347 // a given mode or padding
|
1 /*
2 * Copyright (c) 1997, 2018, 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
304
305 private static String[] tokenizeTransformation(String transformation)
306 throws NoSuchAlgorithmException {
307 if (transformation == null) {
308 throw new NoSuchAlgorithmException("No transformation given");
309 }
310 /*
311 * array containing the components of a Cipher transformation:
312 *
313 * index 0: algorithm component (e.g., AES)
314 * index 1: feedback component (e.g., CFB)
315 * index 2: padding component (e.g., PKCS5Padding)
316 */
317 String[] parts = new String[3];
318 int count = 0;
319 StringTokenizer parser = new StringTokenizer(transformation, "/");
320 try {
321 while (parser.hasMoreTokens() && count < 3) {
322 parts[count++] = parser.nextToken().trim();
323 }
324 if (count == 0 || count == 2) {
325 throw new NoSuchAlgorithmException("Invalid transformation"
326 + " format:" +
327 transformation);
328 }
329 // treats all subsequent tokens as part of padding
330 if (count == 3 && parser.hasMoreTokens()) {
331 parts[2] = parts[2] + parser.nextToken("\r\n");
332 }
333 } catch (NoSuchElementException e) {
334 throw new NoSuchAlgorithmException("Invalid transformation " +
335 "format:" + transformation);
336 }
337 if ((parts[0] == null) || (parts[0].length() == 0)) {
338 throw new NoSuchAlgorithmException("Invalid transformation:" +
339 "algorithm not specified-"
340 + transformation);
341 }
342 return parts;
343 }
344
345 // Provider attribute name for supported chaining mode
346 private static final String ATTR_MODE = "SupportedModes";
347 // Provider attribute name for supported padding names
348 private static final String ATTR_PAD = "SupportedPaddings";
349
350 // constants indicating whether the provider supports
351 // a given mode or padding
|