/* * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// Test additional fields
enlarge(0, "8000"); // attributes
enlarge(1, "810100"); // public key for v2
enlarge(1, "8000", "810100"); // both
Assert.assertThrows(() -> enlarge(2)); // bad ver Assert.assertThrows(() -> enlarge(0, "8000", "8000")); // no dup Assert.assertThrows(() -> enlarge(0, "810100")); // no public in v1 Assert.assertThrows(() -> enlarge(1, "810100", "8000")); // bad order Assert.assertThrows(() -> enlarge(1, "820100")); // bad tag
}
/** * Add more fields to EXPECTED and see if it's still valid PKCS8. * * @param newVersion new version * @param fields extra fields to add, in hex
*/ staticvoid enlarge(int newVersion, String... fields) throws IOException { byte[] original = EXPECTED.clone(); int length = original.length; for (String field : fields) { // append fields byte[] add = HexFormat.of().parseHex(field);
original = Arrays.copyOf(original, length + add.length);
System.arraycopy(add, 0, original, length, add.length);
length += add.length;
} Assert.assertTrue(length < 127);
original[1] = (byte)(length - 2); // the length field inside DER
original[4] = (byte)newVersion; // the version inside DER
PKCS8Key.parseKey(original);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.