Java Code Examples for jdk.testlibrary.RandomFactory#getRandom()

The following examples show how to use jdk.testlibrary.RandomFactory#getRandom() . 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: ModPow65537.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testSigning(KeyPair kp) throws Exception {
    System.out.println(kp.getPublic());
    byte[] data = new byte[1024];
    Random random = RandomFactory.getRandom();
    random.nextBytes(data);

    Signature sig = Signature.getInstance("SHA1withRSA", "SunRsaSign");
    sig.initSign(kp.getPrivate());
    sig.update(data);
    byte[] sigBytes = sig.sign();

    sig.initVerify(kp.getPublic());
    sig.update(data);
    if (sig.verify(sigBytes) == false) {
        throw new Exception("signature verification failed");
    }
    System.out.println("OK");
}
 
Example 2
Source File: EntryProtectionTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 3
Source File: DTLSIncorrectAppDataTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void checkIncorrectAppDataUnwrap(SSLEngine sendEngine,
        SSLEngine recvEngine) throws SSLException {
    String direction = sendEngine.getUseClientMode() ? "client"
            : "server";
    System.out.println("================================================="
            + "===========");
    System.out.println("Testing DTLS incorrect app data packages unwrapping"
            + " by sending data from " + direction);
    ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
    ByteBuffer net = doWrap(sendEngine, direction, 0, app);
    final Random RNG = RandomFactory.getRandom();
    int randomPlace = RNG.nextInt(net.remaining());
    net.array()[randomPlace] += 1;
    app = ByteBuffer.allocate(recvEngine.getSession()
            .getApplicationBufferSize());
    recvEngine.unwrap(net, app);
    app.flip();
    int length = app.remaining();
    System.out.println("Unwrapped " + length + " bytes.");
}
 
Example 4
Source File: TestAvailable.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Throwable {
    Random r = RandomFactory.getRandom();
    for (int n = 0; n < 10; n++) {
        byte[] src = new byte[r.nextInt(100) + 1];
        r.nextBytes(src);
        // test InflaterInputStream
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (DeflaterOutputStream dos = new DeflaterOutputStream(baos)) {
            dos.write(src);
        }
        try (InflaterInputStream iis = new InflaterInputStream(
               new ByteArrayInputStream(baos.toByteArray()))) {
            test(iis, src);
        }

        // test GZIPInputStream
        baos = new ByteArrayOutputStream();
        try (GZIPOutputStream dos = new GZIPOutputStream(baos)) {
            dos.write(src);
        }
        try (GZIPInputStream gis = new GZIPInputStream(
               new ByteArrayInputStream(baos.toByteArray()))) {
            test(gis, src);
        }
    }
}
 
Example 5
Source File: EntryProtectionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 6
Source File: EntryProtectionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 7
Source File: EntryProtectionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 8
Source File: EntryProtectionTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 9
Source File: EntryProtectionTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 10
Source File: EntryProtectionTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
Example 11
Source File: TestZoneTextPrinterParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 12
Source File: TestZoneTextPrinterParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 13
Source File: bug7123767.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static List<GraphicsConfiguration> getConfigs() {

        Random rnd = RandomFactory.getRandom();

        List<GraphicsConfiguration> configs = new ArrayList<>();

        GraphicsEnvironment ge =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        for (GraphicsDevice device : devices) {
            GraphicsConfiguration[] allConfigs = device.getConfigurations();
            int nConfigs = allConfigs.length;
            if (nConfigs <= MAX_N_CONFIGS) {
                Collections.addAll(configs, allConfigs);
            } else { // see JDK-8159454
                System.out.println("check only " + MAX_N_CONFIGS +
                        " configurations for device " + device);
                configs.add(device.getDefaultConfiguration()); // check default
                for (int j = 0; j < MAX_N_CONFIGS - 1; j++) {
                    int k = rnd.nextInt(nConfigs);
                    configs.add(allConfigs[k]);
                }
            }
        }

        return configs;
    }
 
Example 14
Source File: TestZoneTextPrinterParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 15
Source File: TestZoneTextPrinterParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 16
Source File: TestZoneTextPrinterParser.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 17
Source File: DTLSSequenceNumberTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void shuffleArray(int[] ar) {
    final Random RNG = RandomFactory.getRandom();
    for (int i = ar.length - 1; i > 0; i--) {
        int index = RNG.nextInt(i + 1);
        int a = ar[index];
        ar[index] = ar[i];
        ar[i] = a;
    }
}
 
Example 18
Source File: StringConstructor.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 {
    constructWithError("");
    constructWithError("+");
    constructWithError("-");
    constructWithError("+e");
    constructWithError("-e");
    constructWithError("e+");
    constructWithError("1.-0");
    constructWithError(".-123");
    constructWithError("-");
    constructWithError("--1.1");
    constructWithError("-+1.1");
    constructWithError("+-1.1");
    constructWithError("1-.1");
    constructWithError("1+.1");
    constructWithError("1.111+1");
    constructWithError("1.111-1");
    constructWithError("11.e+");
    constructWithError("11.e-");
    constructWithError("11.e+-");
    constructWithError("11.e-+");
    constructWithError("11.e-+1");
    constructWithError("11.e+-1");

    // Range checks
    constructWithError("1e"+Integer.MIN_VALUE);
    constructWithError("10e"+Integer.MIN_VALUE);
    constructWithError("0.01e"+Integer.MIN_VALUE);
    constructWithError("1e"+((long)Integer.MIN_VALUE-1));
    constructWithError("1e"+((long)Integer.MAX_VALUE + 1));

    leadingExponentZeroTest();
    nonAsciiZeroTest();

    // Roundtrip tests
    Random random = RandomFactory.getRandom();
    for (int i=0; i<100; i++) {
        int size = random.nextInt(100) + 1;
        BigInteger bi = new BigInteger(size, random);
        if (random.nextBoolean())
            bi = bi.negate();
        int decimalLength = bi.toString().length();
        int scale = random.nextInt(decimalLength);
        BigDecimal bd = new BigDecimal(bi, scale);
        String bdString = bd.toString();
        // System.err.println("bi" + bi.toString() + "\tscale " + scale);
        // System.err.println("bd string: " + bdString);
        BigDecimal bdDoppel = new BigDecimal(bdString);
        if (!bd.equals(bdDoppel)) {
            System.err.println("bd string: scale: " + bd.scale() +
                               "\t" + bdString);
            System.err.println("bd doppel: scale: " + bdDoppel.scale() +
                               "\t" + bdDoppel.toString());
            throw new RuntimeException("String constructor failure.");
        }
    }
}
 
Example 19
Source File: TestDigestIOStream.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void run() throws Exception {
    for (String algorithm : ALGORITHM_ARRAY) {
        try {
            md = MessageDigest.getInstance(algorithm);
            for (int length : DATA_LEN_ARRAY) {

                Random rdm = RandomFactory.getRandom();
                data = new byte[length];
                rdm.nextBytes(data);

                if (!testMDChange(algorithm, length)) {
                    throw new RuntimeException("testMDChange failed at:"
                            + algorithm + "/" + length);
                }
                if (!testMDShare(algorithm, length)) {
                    throw new RuntimeException("testMDShare failed at:"
                            + algorithm + "/" + length);
                }
                for (ReadModel readModel : ReadModel.values()) {
                    // test Digest function when digest switch on
                    if (!testDigestOnOff(algorithm, readModel, true,
                            length)) {
                        throw new RuntimeException(
                                "testDigestOn failed at:" + algorithm + "/"
                                        + length + "/" + readModel);
                    }
                    // test Digest function when digest switch off
                    if (!testDigestOnOff(algorithm, readModel, false,
                            length)) {
                        throw new RuntimeException(
                                "testDigestOff failed at:" + algorithm + "/"
                                        + length + "/" + readModel);
                    }
                }
            }
        } catch (NoSuchAlgorithmException nae) {
            if (algorithm.startsWith("SHA3") && !isSHA3supported()) {
                continue;
            } else {
                throw nae;
            }
        }
    }
    int testNumber = ALGORITHM_ARRAY.length * ReadModel.values().length
            * DATA_LEN_ARRAY.length * 2
            + ALGORITHM_ARRAY.length * DATA_LEN_ARRAY.length * 2;
    out.println("All " + testNumber + " Tests Passed");
}
 
Example 20
Source File: RehandshakeWithCipherChangeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void testOneCipher(String cipher) throws SSLException {
    SSLContext context = getContext();
    int maxPacketSize = getMaxPacketSize();
    SSLEngine clientEngine = context.createSSLEngine();
    clientEngine.setUseClientMode(true);
    SSLEngine serverEngine = context.createSSLEngine();
    serverEngine.setUseClientMode(false);
    clientEngine.setEnabledCipherSuites(new String[]{cipher});
    serverEngine.setEnabledCipherSuites(
            Ciphers.ENABLED_NON_KRB_NOT_ANON_CIPHERS.ciphers);
    String randomCipher;
    serverEngine.setNeedClientAuth(true);
    long initialEpoch = 0;
    long secondEpoch = 0;
    SSLEngineResult r;
    doHandshake(clientEngine, serverEngine, maxPacketSize,
            HandshakeMode.INITIAL_HANDSHAKE);
    sendApplicationData(clientEngine, serverEngine);
    r = sendApplicationData(serverEngine, clientEngine);
    if (TESTED_SECURITY_PROTOCOL.contains("DTLS")) {
        initialEpoch = r.sequenceNumber() >> 48;
    }
    final Random RNG = RandomFactory.getRandom();
    randomCipher = Ciphers.ENABLED_NON_KRB_NOT_ANON_CIPHERS.ciphers[RNG
            .nextInt(Ciphers.ENABLED_NON_KRB_NOT_ANON_CIPHERS.ciphers.length)];
    clientEngine.setEnabledCipherSuites(new String[]{randomCipher});
    doHandshake(clientEngine, serverEngine, maxPacketSize,
            HandshakeMode.REHANDSHAKE_BEGIN_CLIENT);
    sendApplicationData(clientEngine, serverEngine);
    r = sendApplicationData(serverEngine, clientEngine);
    if (TESTED_SECURITY_PROTOCOL.contains("DTLS")) {
        secondEpoch = r.sequenceNumber() >> 48;
        AssertionError epochError = new AssertionError("Epoch number"
                + " did not grow after re-handshake! "
                + " Was " + initialEpoch + ", now " + secondEpoch + ".");
        if (Long.compareUnsigned(secondEpoch, initialEpoch) <= 0) {
            throw epochError;
        }
    }
    closeEngines(clientEngine, serverEngine);
}