From 355c07de6d5252fe6da46f7a2bde6ac71e8c3d81 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 15 Oct 2003 13:10:06 +0000 Subject: Use IllegalArgumentException instead of Error --- .../fancydress/crypto/CryptoPrimitives.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/org/noreply/fancydress/crypto/CryptoPrimitives.java b/src/org/noreply/fancydress/crypto/CryptoPrimitives.java index 1525f1d..820dbcb 100644 --- a/src/org/noreply/fancydress/crypto/CryptoPrimitives.java +++ b/src/org/noreply/fancydress/crypto/CryptoPrimitives.java @@ -44,11 +44,11 @@ public class CryptoPrimitives { * @param a octet array 1 * @param b octet array 2 * @return an octet array of equal length where x[i] = a[i] XOR b[i] for all i - * @throws Error if a and b do not have the same length + * @throws IllegalArgumentException if a and b do not have the same length */ public static byte[] xor(byte[] a, byte[] b) { if (a.length != b.length) - throw new Error("Arguments to xor must have the same length"); + throw new IllegalArgumentException("Arguments to xor must have the same length"); byte[] result = new byte[a.length]; for (int i=0; ik is not KEY_LEN (=16) octets long. + * @throws IllegalArgumentException if k is not KEY_LEN (=16) octets long. */ public static byte[] prng(byte[] k, int n) { byte[] result = new byte[ n ]; byte[] block = new byte[ KEY_LEN ]; byte[] encrypted = new byte[ KEY_LEN ]; if (k.length != KEY_LEN) - throw new Error("Argument k to encrypt must be KEY_LEN bytes"); + throw new IllegalArgumentException("Argument k to encrypt must be KEY_LEN bytes"); KeyParameter params = new KeyParameter(k); aes_cipher.init(true, params); for (int i=0, p=0; ik is not KEY_LEN (=16) octets long. + * @throws IllegalArgumentException if k is not KEY_LEN (=16) octets long. */ public static byte[] encrypt(byte[] k, byte[] m) { byte[] result; if (k.length != KEY_LEN) - throw new Error("Argument k to encrypt must be KEY_LEN bytes"); + throw new IllegalArgumentException("Argument k to encrypt must be KEY_LEN bytes"); result = xor(m, prng(k, m.length)); return(result); } @@ -179,14 +179,14 @@ public class CryptoPrimitives { * @param k the key for our SPRP function * @param m the message to encrypt * @return the encrypted message. (len(e) == len(m)) - * @throws Error if k is not SPRP_KEY_LEN (=20) octets long - * @throws Error if m is shorter than SPRP_KEY_LEN (=20) octets + * @throws IllegalArgumentException if k is not SPRP_KEY_LEN (=20) octets long + * @throws IllegalArgumentException if m is shorter than SPRP_KEY_LEN (=20) octets */ public static byte[] sprpEncrypt(byte[] k, byte[] m) { if (m.length < HASH_LEN) - throw new Error("Argument m to sprp_encrypt must be of at least HASH_LEN bytes"); + throw new IllegalArgumentException("Argument m to sprp_encrypt must be of at least HASH_LEN bytes"); if (k.length != SPRP_KEY_LEN) - throw new Error("Argument k to sprp_encrypt must be SPRP_KEY_LEN bytes"); + throw new IllegalArgumentException("Argument k to sprp_encrypt must be SPRP_KEY_LEN bytes"); byte[] result; byte[] k1 = new byte[HASH_LEN]; byte[] k2 = new byte[HASH_LEN]; @@ -219,7 +219,7 @@ public class CryptoPrimitives { * @param p a string to build a subkey with. * @param m the message to encrypt * @return the encrypted message. (len(e) == len(m)) - * @throws Error if m is shorter than SPRP_KEY_LEN (=20) octets + * @throws IllegalArgumentException if m is shorter than SPRP_KEY_LEN (=20) octets * @see #sprpEncrypt(byte[] k, byte[] m) */ public static byte[] sprpEncrypt(byte[] k, String p, byte[] m) { @@ -234,15 +234,15 @@ public class CryptoPrimitives { * @param k the key for our SPRP function * @param m the message to decrypt * @return the encrypted message. (len(e) == len(m)) - * @throws Error if k is not SPRP_KEY_LEN (=20) octets long - * @throws Error if m is shorter than SPRP_KEY_LEN (=20) octets + * @throws IllegalArgumentException if k is not SPRP_KEY_LEN (=20) octets long + * @throws IllegalArgumentException if m is shorter than SPRP_KEY_LEN (=20) octets * @see #sprpEncrypt(byte[] k, byte[] m) */ public static byte[] sprpDecrypt(byte[] k, byte[] m) { if (m.length < HASH_LEN) - throw new Error("Argument m to sprp_decrypt must be of at least HASH_LEN bytes"); + throw new IllegalArgumentException("Argument m to sprp_decrypt must be of at least HASH_LEN bytes"); if (k.length != SPRP_KEY_LEN) - throw new Error("Argument k to sprp_decrypt must be SPRP_KEY_LEN bytes"); + throw new IllegalArgumentException("Argument k to sprp_decrypt must be SPRP_KEY_LEN bytes"); byte[] result; byte[] k1 = new byte[HASH_LEN]; byte[] k2 = new byte[HASH_LEN]; @@ -275,7 +275,7 @@ public class CryptoPrimitives { * @param p a string to build a subkey with. * @param m the message to decrypt * @return the encrypted message. (len(e) == len(m)) - * @throws Error if m is shorter than SPRP_KEY_LEN (=20) octets + * @throws IllegalArgumentException if m is shorter than SPRP_KEY_LEN (=20) octets * @see #sprpEncrypt(byte[] k, byte[] m) * @see #sprpDecrypt(byte[] k, byte[] m) */ @@ -290,11 +290,11 @@ public class CryptoPrimitives { * @param k a master key * @param p a string to build a subkey with * @return the subkey - * @throws Error if k is not KEY_LEN (=16) octets long + * @throws IllegalArgumentException if k is not KEY_LEN (=16) octets long */ public static byte[] subKey(byte[] k, String p) { if (k.length != KEY_LEN) - throw new Error("Argument k to subKey must be KEY_LEN bytes"); + throw new IllegalArgumentException("Argument k to subKey must be KEY_LEN bytes"); return Util.slice(hash(k, Util.toOctets(p)), 0, 16); } } -- cgit v1.2.3