From: <gel...@mx...> - 2003-02-07 14:58:18
|
gelderen 03/02/07 10:06:24 Modified: jce/src/cryptix.jce.provider.util Util.java Log: Add boolean equals(byte[], byte[]). Revision Changes Path 1.3 +24 -2 projects/jce/src/cryptix.jce.provider.util/Util.java Index: Util.java =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/jce/src/cryptix.jce.provider.util/Util.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Util.java 18 Nov 2001 02:28:16 -0000 1.2 +++ Util.java 7 Feb 2003 15:06:24 -0000 1.3 @@ -1,4 +1,4 @@ -/* $Id: Util.java,v 1.2 2001/11/18 02:28:16 gelderen Exp $ +/* $Id: Util.java,v 1.3 2003/02/07 15:06:24 gelderen Exp $ * * Copyright (C) 2000 The Cryptix Foundation Limited. * All rights reserved. @@ -17,7 +17,7 @@ /** * Misc utility methods. * - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @author Jeroen C. van Gelderen (gel...@cr...) */ public final class Util @@ -69,5 +69,27 @@ int res_off = resultByteLen-x_len; System.arraycopy(x_bytes, x_off, res_bytes, res_off, x_len); return res_bytes; + } + + + /** + * Compare two byte[] for equality. byte[]s are considered equal if they + * have the same length and the same contents (same elems, same order). + * Additionally, two null arguments compare equal too. + */ + public static boolean equals(byte[] a, byte[] b) { + + if( a==null && b==null ) return true; + + if( a==null ^ b==null ) return false; + + int aLen = a.length; + int bLen = b.length; + if( aLen != bLen ) return false; + + for(int i=0; i<aLen; i++) + if( a[i] != b[i] ) return false; + + return true; } } |