Showing the changes to java/pkg/sun/security/util/ByteArrayTagOrder.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,61 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1997, 2006, 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 | + | |
| 27 | +/** | |
| 28 | + * ByteArrayTagOrder: a class for comparing two DER encodings by the | |
| 29 | + * order of their tags. | |
| 30 | + * | |
| 31 | + * @author D. N. Hoover | |
| 32 | + */ | |
| 33 | + | |
| 34 | +package sun.security.util; | |
| 35 | + | |
| 36 | +import java.util.Comparator; | |
| 37 | + | |
| 38 | +public class ByteArrayTagOrder implements Comparator<byte[]> { | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Compare two byte arrays, by the order of their tags, | |
| 42 | + * as defined in ITU-T X.680, sec. 6.4. (First compare | |
| 43 | + * tag classes, then tag numbers, ignoring the constructivity bit.) | |
| 44 | + * | |
| 45 | + * @param bytes1 first byte array to compare. | |
| 46 | + * @param bytes2 second byte array to compare. | |
| 47 | + * @return negative number if bytes1 < bytes2, 0 if bytes1 == bytes2, | |
| 48 | + * positive number if bytes1 > bytes2. | |
| 49 | + * | |
| 50 | + * @exception <code>ClassCastException</code> | |
| 51 | + * if either argument is not a byte array. | |
| 52 | + */ | |
| 53 | + | |
| 54 | + public final int compare(byte[] bytes1, byte[] bytes2) { | |
| 55 | + // tag order is same as byte order ignoring any difference in | |
| 56 | + // the constructivity bit (0x02) | |
| 57 | + return (bytes1[0] | 0x20) - (bytes2[0] | 0x20); | |
| 58 | + } | |
| 59 | + | |
| 60 | + | |
| 61 | +} | |