< prev index next >

## src/java.base/share/classes/java/security/cert/Certificate.java

Print this page

      1 /*
      2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     48  * functionality (like encoding and verifying) and
     49  * some types of information (like a public key).
     50  * <p>
     51  * X.509, PGP, and SDSI certificates can all be implemented by
     52  * subclassing the Certificate class, even though they contain different
     53  * sets of information, and they store and retrieve the information in
     54  * different ways.
     55  *
     56  * @see X509Certificate
     57  * @see CertificateFactory
     58  *
     59  * @author Hemma Prafullchandra
     60  * @since 1.2
     61  */
     62
     63 public abstract class Certificate implements java.io.Serializable {
     64
     65     @java.io.Serial
     66     private static final long serialVersionUID = -3585440601605666277L;
     67
     68     // the certificate type
     69     private final String type;
     70
     71     /** Cache the hash code for the certiticate */
     72     private int hash = -1; // Default to -1
     73
     74     /**
     75      * Creates a certificate of the specified type.
     76      *
     77      * @param type the standard name of the certificate type.
     78      * See the CertificateFactory section in the <a href=
     79      * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
     80      * Java Security Standard Algorithm Names Specification</a>
     81      * for information about standard certificate types.
     82      */
     83     protected Certificate(String type) {
     84         this.type = type;
     85     }
     86
     87     /**
     88      * Returns the type of this certificate.
     89      *
     90      * @return the type of this certificate.
     91      */
    227      * @return a string representation of this certificate.
    228      */
    229     public abstract String toString();
    230
    231     /**
    232      * Gets the public key from this certificate.
    233      *
    234      * @return the public key.
    235      */
    236     public abstract PublicKey getPublicKey();
    237
    238     /**
    239      * Alternate Certificate class for serialization.
    240      * @since 1.3
    241      */
    242     protected static class CertificateRep implements java.io.Serializable {
    243
    244         @java.io.Serial
    245         private static final long serialVersionUID = -8563758940495660020L;
    246

    247         private String type;

    248         private byte[] data;
    249
    250         /**
    251          * Construct the alternate Certificate class with the Certificate
    252          * type and Certificate encoding bytes.
    253          *
    254          * @param type the standard name of the Certificate type.
    255          *
    256          * @param data the Certificate data.
    257          */
    258         protected CertificateRep(String type, byte[] data) {
    259             this.type = type;
    260             this.data = data;
    261         }
    262
    263         /**
    264          * Resolve the Certificate Object.
    265          *
    266          * @return the resolved Certificate Object
    267          *
      1 /*
      2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     48  * functionality (like encoding and verifying) and
     49  * some types of information (like a public key).
     50  * <p>
     51  * X.509, PGP, and SDSI certificates can all be implemented by
     52  * subclassing the Certificate class, even though they contain different
     53  * sets of information, and they store and retrieve the information in
     54  * different ways.
     55  *
     56  * @see X509Certificate
     57  * @see CertificateFactory
     58  *
     59  * @author Hemma Prafullchandra
     60  * @since 1.2
     61  */
     62
     63 public abstract class Certificate implements java.io.Serializable {
     64
     65     @java.io.Serial
     66     private static final long serialVersionUID = -3585440601605666277L;
     67
     68     /** The certificate type. */
     69     private final String type;
     70
     71     /** Cache the hash code for the certiticate. */
     72     private int hash = -1; // Default to -1
     73
     74     /**
     75      * Creates a certificate of the specified type.
     76      *
     77      * @param type the standard name of the certificate type.
     78      * See the CertificateFactory section in the <a href=
     79      * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
     80      * Java Security Standard Algorithm Names Specification</a>
     81      * for information about standard certificate types.
     82      */
     83     protected Certificate(String type) {
     84         this.type = type;
     85     }
     86
     87     /**
     88      * Returns the type of this certificate.
     89      *
     90      * @return the type of this certificate.
     91      */
    227      * @return a string representation of this certificate.
    228      */
    229     public abstract String toString();
    230
    231     /**
    232      * Gets the public key from this certificate.
    233      *
    234      * @return the public key.
    235      */
    236     public abstract PublicKey getPublicKey();
    237
    238     /**
    239      * Alternate Certificate class for serialization.
    240      * @since 1.3
    241      */
    242     protected static class CertificateRep implements java.io.Serializable {
    243
    244         @java.io.Serial
    245         private static final long serialVersionUID = -8563758940495660020L;
    246
    247         /** The standard name of the certificate type. */
    248         private String type;
    249
    250         /** The certificate data. */
    251         private byte[] data;
    252
    253         /**
    254          * Construct the alternate Certificate class with the Certificate
    255          * type and Certificate encoding bytes.
    256          *
    257          * @param type the standard name of the Certificate type.
    258          *
    259          * @param data the Certificate data.
    260          */
    261         protected CertificateRep(String type, byte[] data) {
    262             this.type = type;
    263             this.data = data;
    264         }
    265
    266         /**
    267          * Resolve the Certificate Object.
    268          *
    269          * @return the resolved Certificate Object
    270          *

< prev index next >