Turkish.java 4.7 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24 25
 */

/**
 * @test
26
 * @bug 6220064 7054918
D
duke 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 * @summary make sure everything works ok in the Turkish local (dotted/dotless i problem)
 * @author Andreas Sterbenz
 */

import java.util.*;

import java.security.*;
import java.security.Provider.Service;
import javax.crypto.*;

public class Turkish {

    public static void main(String[] args) throws Exception {
        Provider p1 = new TProvider("T1");
        System.out.println(p1.getServices()); // trigger service parsing

43 44 45
        Locale loc = Locale.getDefault();
        try {
            Locale.setDefault(new Locale("tr", "TR"));
D
duke 已提交
46

47 48
            Provider p2 = new TProvider("T2");
            System.out.println(p2.getServices()); // trigger service parsing
D
duke 已提交
49

50 51 52 53 54 55 56 57 58 59 60
            System.out.println(Signature.getInstance("MD5withRSA"));
            System.out.println(Signature.getInstance("md5withrsa"));
            System.out.println(Signature.getInstance("MD5WITHRSA"));
            Service s1, s2;
            s1 = p1.getService("Signature", "MD5withRSA");
            check(s1, null);
            check(s1, p1.getService("Signature", "md5withrsa"));
            check(s1, p1.getService("Signature", "MD5WITHRSA"));
            check(s1, p1.getService("Signature", "MD5RSA"));
            check(s1, p1.getService("Signature", "md5rsa"));
            check(s1, p1.getService("Signature", "MD5rsa"));
D
duke 已提交
61

62 63 64 65 66 67 68 69 70 71
            s1 = p1.getService("Signature", "SHAwithRSA");
            check(s1, null);
            check(s1, p1.getService("Signature", "shawithrsa"));
            check(s1, p1.getService("Signature", "SHAWITHRSA"));
            check(s1, p1.getService("Signature", "SHARSA"));
            check(s1, p1.getService("Signature", "sharsa"));
            check(s1, p1.getService("Signature", "SHArsa"));
            check(s1, p1.getService("Signature", "SHA1RSA"));
            check(s1, p1.getService("Signature", "sha1rsa"));
            check(s1, p1.getService("Signature", "SHA1rsa"));
D
duke 已提交
72

73 74 75 76 77 78 79
            s1 = p2.getService("Signature", "MD5withRSA");
            check(s1, null);
            check(s1, p2.getService("Signature", "md5withrsa"));
            check(s1, p2.getService("Signature", "MD5WITHRSA"));
            check(s1, p2.getService("Signature", "MD5RSA"));
            check(s1, p2.getService("Signature", "md5rsa"));
            check(s1, p2.getService("Signature", "MD5rsa"));
D
duke 已提交
80

81 82 83 84 85 86 87 88 89 90
            s1 = p2.getService("Signature", "SHAwithRSA");
            check(s1, null);
            check(s1, p2.getService("Signature", "shawithrsa"));
            check(s1, p2.getService("Signature", "SHAWITHRSA"));
            check(s1, p2.getService("Signature", "SHARSA"));
            check(s1, p2.getService("Signature", "sharsa"));
            check(s1, p2.getService("Signature", "SHArsa"));
            check(s1, p2.getService("Signature", "SHA1RSA"));
            check(s1, p2.getService("Signature", "sha1rsa"));
            check(s1, p2.getService("Signature", "SHA1rsa"));
D
duke 已提交
91

92 93 94 95
            System.out.println("OK");
        } finally {
            Locale.setDefault(loc);
        }
D
duke 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    }

    private static void check(Service s1, Service s2) throws Exception {
        System.out.println(s1);
        if (s1 == null) {
            throw new Exception("service is null");
        }
        if ((s2 != null) && (s1 != s2)) {
            throw new Exception("service does not match");
        }
    }

    private static class TProvider extends Provider {
        TProvider(String name) {
            super(name, 1.0d, null);
            put("Signature.MD5withRSA", "com.foo.Sig");
            put("Alg.Alias.Signature.MD5RSA", "MD5withRSA");
            put("sIGNATURE.shaWITHrsa", "com.foo.Sig");
            put("aLG.aLIAS.sIGNATURE.sharsa", "shaWITHrsa");
            put("aLG.aLIAS.sIGNATURE.sha1rsa", "shawithrsa");
        }
    }

}