Java Code Examples for java.lang.Integer#MAX_VALUE

The following examples show how to use java.lang.Integer#MAX_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxFloatingPointTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testCompoundOperators() {
  int i = Integer.MAX_VALUE;
  i += 1.0;
  assertEquals(Integer.MAX_VALUE, i);
  i *= 1.5;
  assertEquals(Integer.MAX_VALUE, i);
  i -= -1.0;
  assertEquals(Integer.MAX_VALUE, i);
  i /= 0.5;
  assertEquals(Integer.MAX_VALUE, i);
  long l = Long.MAX_VALUE;
  l += 1.0;
  assertEquals(Long.MAX_VALUE, l);
  l *= 1.5;
  assertEquals(Long.MAX_VALUE, l);
  l -= -1.0;
  assertEquals(Long.MAX_VALUE, l);
  l /= 0.5;
  assertEquals(Long.MAX_VALUE, l);
}
 
Example 2
Source File: TestCipherKeyWrapperTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 3
Source File: TestCipherKeyWrapperTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 4
Source File: TestCipherKeyWrapperTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void wrapperPBEKeyTest(Provider p) throws InvalidKeySpecException,
        InvalidKeyException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException {
    for (String alg : PBE_ALGORITHM_AR) {
        String baseAlgo = alg.split("/")[0].toUpperCase();
        // only run the tests on longer key lengths if unlimited version
        // of JCE jurisdiction policy files are installed

        if (Cipher.getMaxAllowedKeyLength(alg) < Integer.MAX_VALUE
                && (baseAlgo.endsWith("TRIPLEDES") || alg
                        .endsWith("AES_256"))) {
            out.println("keyStrength > 128 within " + alg
                    + " will not run under global policy");
            continue;
        }
        SecretKeyFactory skf = SecretKeyFactory.getInstance(baseAlgo, p);
        SecretKey key = skf.generateSecret(new PBEKeySpec("Secret Lover"
                .toCharArray()));
        wrapTest(alg, alg, key, key, Cipher.SECRET_KEY, true);
    }
}
 
Example 5
Source File: safeArithmetic.java    From JavaSCR with MIT License 5 votes vote down vote up
static int safeMultiply(int left, int right)
		throws ArithmeticException {
	if (right > 0 ? left > Integer.MAX_VALUE / right
			|| left < Integer.MIN_VALUE / right
			: (right < -1 ? left > Integer.MIN_VALUE / right
					|| left < Integer.MAX_VALUE / right : right == -1
					&& left == Integer.MIN_VALUE)) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left * right;
}
 
Example 6
Source File: Lists.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@VisibleForTesting static int computeArrayListCapacity(int arraySize) {
  Preconditions.checkArgument(arraySize >= 0);
  long desiredSize = 5L + arraySize + (arraySize / 10);

  if (desiredSize > Integer.MAX_VALUE) {
    return Integer.MAX_VALUE;
  }
  if (desiredSize < Integer.MIN_VALUE) {
    return Integer.MIN_VALUE;
  }
  return (int) desiredSize;
}
 
Example 7
Source File: DHGenParameterSpecTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
 
Example 8
Source File: TestCipherKeyWrapperTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 9
Source File: TestCipherKeyWrapperTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 10
Source File: TableColumn.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 11
Source File: TableColumn.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 12
Source File: TestCipherKeyWrapperTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }
 
Example 13
Source File: TableColumn.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 14
Source File: TestCipherKeyWrapperTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 15
Source File: TableColumn.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 16
Source File: TestCipherKeyWrapperTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 17
Source File: TableColumn.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 18
Source File: TableColumn.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  Creates and initializes an instance of
 *  <code>TableColumn</code> with the specified model index,
 *  width, cell renderer, and cell editor;
 *  all <code>TableColumn</code> constructors delegate to this one.
 *  The value of <code>width</code> is used
 *  for both the initial and preferred width;
 *  if <code>width</code> is negative,
 *  they're set to 0.
 *  The minimum width is set to 15 unless the initial width is less,
 *  in which case the minimum width is set to
 *  the initial width.
 *
 *  <p>
 *  When the <code>cellRenderer</code>
 *  or <code>cellEditor</code> parameter is <code>null</code>,
 *  a default value provided by the <code>JTable</code>
 *  <code>getDefaultRenderer</code>
 *  or <code>getDefaultEditor</code> method, respectively,
 *  is used to
 *  provide defaults based on the type of the data in this column.
 *  This column-centric rendering strategy can be circumvented by overriding
 *  the <code>getCellRenderer</code> methods in <code>JTable</code>.
 *
 * @param modelIndex the index of the column
 *  in the model that supplies the data for this column in the table;
 *  the model index remains the same
 *  even when columns are reordered in the view
 * @param width this column's preferred width and initial width
 * @param cellRenderer the object used to render values in this column
 * @param cellEditor the object used to edit values in this column
 * @see #getMinWidth()
 * @see JTable#getDefaultRenderer(Class)
 * @see JTable#getDefaultEditor(Class)
 * @see JTable#getCellRenderer(int, int)
 * @see JTable#getCellEditor(int, int)
 */
public TableColumn(int modelIndex, int width,
                             TableCellRenderer cellRenderer,
                             TableCellEditor cellEditor) {
    super();
    this.modelIndex = modelIndex;
    preferredWidth = this.width = Math.max(width, 0);

    this.cellRenderer = cellRenderer;
    this.cellEditor = cellEditor;

    // Set other instance variables to default values.
    minWidth = Math.min(15, this.width);
    maxWidth = Integer.MAX_VALUE;
    isResizable = true;
    resizedPostingDisableCount = 0;
    headerValue = null;
}
 
Example 19
Source File: TestCipherKeyWrapperTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void wrapperBlowfishKeyTest() throws InvalidKeyException,
        NoSuchAlgorithmException, NoSuchPaddingException,
        IllegalBlockSizeException, InvalidAlgorithmParameterException {
    // how many kinds of padding mode
    int padKinds;
    // Keysize should be multiple of 8 bytes.
    int KeyCutter = 8;
    int kSize = BLOWFISH_MIN_KEYSIZE;
    String algorithm = "Blowfish";
    int maxAllowKeyLength = Cipher.getMaxAllowedKeyLength(algorithm);
    boolean unLimitPolicy = maxAllowKeyLength == Integer.MAX_VALUE;
    SecretKey key = null;
    while (kSize <= BLOWFISH_MAX_KEYSIZE) {
        for (String mode : MODEL_AR) {
            // PKCS5padding is meaningful only for ECB, CBC, PCBC
            if (mode.equalsIgnoreCase(MODEL_AR[0])
                    || mode.equalsIgnoreCase(MODEL_AR[1])
                    || mode.equalsIgnoreCase(MODEL_AR[2])) {
                padKinds = PADDING_AR.length;
            } else {
                padKinds = 1;
            }
            // Initialization
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            for (int k = 0; k < padKinds; k++) {
                String transformation = algorithm + "/" + mode + "/"
                        + PADDING_AR[k];
                if (NOPADDING.equals(PADDING_AR[k]) && kSize % 64 != 0) {
                    out.println(transformation
                            + " will not run if input length not multiple"
                            + " of 8 bytes when padding is " + NOPADDING);
                    continue;
                }
                kg.init(kSize);
                key = kg.generateKey();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!unLimitPolicy && kSize > LINIMITED_KEYSIZE) {
                    out.println("keyStrength > 128 within " + algorithm
                            + " will not run under global policy");
                } else {
                    wrapTest(transformation, transformation, key, key,
                            Cipher.SECRET_KEY, false);
                }
            }
        }
        if (kSize <= LINIMITED_KEYSIZE) {
            KeyCutter = 8;
        } else {
            KeyCutter = 48;
        }
        kSize += KeyCutter;
    }
}
 
Example 20
Source File: TestCipherKeyWrapperTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        TestCipherKeyWrapperTest test = new TestCipherKeyWrapperTest();
        // AESWrap and DESedeWrap test
        for (AlgorithmWrapper algoWrapper : AlgorithmWrapper.values()) {
            String algo = algoWrapper.getAlgorithm();
            String wrapper = algoWrapper.getWrapper();
            try {
                int keySize = algoWrapper.getKeySize();
                // only run the tests on longer key lengths if unlimited
                // version of JCE jurisdiction policy files are installed
                if (!(Cipher.getMaxAllowedKeyLength(algo) == Integer.MAX_VALUE)
                        && keySize > LINIMITED_KEYSIZE) {
                    out.println(algo + " will not run if unlimited version of"
                            + " JCE jurisdiction policy files are installed");
                    continue;
                }
                test.wrapperAesDESedeKeyTest(algo, wrapper, keySize);
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    throw new RuntimeException("Expected not throw when algo"
                            + " and wrapAlgo are not match:" + algo);
                }
            } catch (InvalidKeyException e) {
                if (algoWrapper == AlgorithmWrapper.NegtiveWrap) {
                    out.println("Expepted exception when algo"
                            + " and wrapAlgo are not match:" + algo);
                } else {
                    throw e;
                }
            }
        }
        test.wrapperBlowfishKeyTest();
        // PBE and public wrapper test.
        String[] publicPrivateAlgos = new String[] { "DiffieHellman", "DSA",
                "RSA" };
        Provider provider = Security.getProvider(SUN_JCE);
        if (provider == null) {
            throw new RuntimeException("SUN_JCE provider not exist");
        }

        test.wrapperPBEKeyTest(provider);
        // Public and private key wrap test
        test.wrapperPublicPriviteKeyTest(provider, publicPrivateAlgos);
    }