jdk/test/java/security/Signature/SignatureGetAlgorithm.java
author wetmore
Wed, 30 Oct 2013 16:49:35 -0700
changeset 21418 88cb3367643e
parent 18181 4f0a36582461
child 40416 5d91b2fd668c
permissions -rw-r--r--
8027526: CheckTipsAndVersions.java failing occasionally Reviewed-by: mullan, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18181
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     1
/*
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     4
 *
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     8
 *
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    13
 * accompanied this code).
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    14
 *
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    18
 *
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    21
 * questions.
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    22
 */
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    23
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    24
/*
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    25
 * Portions Copyright (c) 2013 IBM Corporation
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    26
 */
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    27
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    28
/*
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    29
 * @test
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    30
 * @bug 8014620
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    31
 * @summary Signature.getAlgorithm return null in special case
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    32
 * @run main/othervm SignatureGetAlgorithm
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    33
 * @author youdwei
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    34
 */
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    35
import java.security.*;
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    36
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    37
public class SignatureGetAlgorithm {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    38
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    40
        Provider testProvider = new TestProvider();
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    41
        Security.addProvider(testProvider);
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    42
        Signature sig = Signature.getInstance("MySignatureAlg");
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    43
        String algorithm = sig.getAlgorithm();
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    44
        System.out.println("Algorithm Name: " + algorithm);
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    45
        if (algorithm == null) {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    46
            throw new Exception("algorithm name should be 'MySignatureAlg'");
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    47
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    48
    }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    49
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    50
    public static class TestProvider extends Provider {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    51
        TestProvider() {
21418
88cb3367643e 8027526: CheckTipsAndVersions.java failing occasionally
wetmore
parents: 18181
diff changeset
    52
            super("testSignatureGetAlgorithm", 1.0, "test Signatures");
18181
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    53
            put("Signature.MySignatureAlg",
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    54
                "SignatureGetAlgorithm$MySignatureAlg");
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    55
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    56
    }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    57
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    58
    public static class MySignatureAlg extends Signature {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    59
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    60
        public MySignatureAlg() {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    61
            super(null);
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    62
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    63
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    64
        MySignatureAlg(String s) {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    65
            super(s);
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    66
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    67
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    68
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    69
        protected void engineInitVerify(PublicKey publicKey)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    70
                throws InvalidKeyException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    71
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    72
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    73
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    74
        protected void engineInitSign(PrivateKey privateKey)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    75
                throws InvalidKeyException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    76
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    77
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    78
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    79
        protected void engineUpdate(byte b) throws SignatureException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    80
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    81
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    82
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    83
        protected void engineUpdate(byte[] b, int off, int len)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    84
                throws SignatureException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    85
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    86
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    87
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    88
        protected byte[] engineSign()
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    89
                throws SignatureException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    90
            return new byte[0];
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    91
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    92
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    93
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    94
        protected boolean engineVerify(byte[] sigBytes)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    95
                throws SignatureException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    96
            return false;
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    97
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    98
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
    99
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   100
        @Deprecated
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   101
        protected void engineSetParameter(String param, Object value)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   102
                throws InvalidParameterException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   103
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   104
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   105
        @Override
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   106
        @Deprecated
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   107
        protected Object engineGetParameter(String param)
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   108
                throws InvalidParameterException {
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   109
            return null;
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   110
        }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   111
    }
4f0a36582461 8014620: Signature.getAlgorithm return null in special case
youdwei
parents:
diff changeset
   112
}