< prev index next >

## src/java.base/share/classes/javax/security/auth/x500/X500Principal.java

Print this page

      1 /*
      2  * Copyright (c) 2000, 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
    477     }
    478
    479     /**
    480      * Return a hash code for this {@code X500Principal}.
    481      *
    482      * <p> The hash code is calculated via:
    483      * {@code getName(X500Principal.CANONICAL).hashCode()}
    484      *
    485      * @return a hash code for this {@code X500Principal}
    486      */
    487     public int hashCode() {
    488         return thisX500Name.hashCode();
    489     }
    490
    491     /**
    492      * Save the X500Principal object to a stream.
    493      *
    494      * @serialData this {@code X500Principal} is serialized
    495      *          by writing out its DER-encoded form
    496      *          (the value of {@code getEncoded} is serialized).

    497      */
    498     @java.io.Serial
    499     private void writeObject(java.io.ObjectOutputStream s)
    500         throws IOException {
    501         s.writeObject(thisX500Name.getEncodedInternal());
    502     }
    503
    504     /**
    505      * Reads this object from a stream (i.e., deserializes it).

    506      */
    507     @java.io.Serial
    508     private void readObject(java.io.ObjectInputStream s)
    509         throws java.io.IOException,
    510                java.io.NotActiveException,
    511                ClassNotFoundException {
    512
    513         // re-create thisX500Name
    514         thisX500Name = new X500Name((byte[])s.readObject());
    515     }
    516 }
      1 /*
      2  * Copyright (c) 2000, 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
    477     }
    478
    479     /**
    480      * Return a hash code for this {@code X500Principal}.
    481      *
    482      * <p> The hash code is calculated via:
    483      * {@code getName(X500Principal.CANONICAL).hashCode()}
    484      *
    485      * @return a hash code for this {@code X500Principal}
    486      */
    487     public int hashCode() {
    488         return thisX500Name.hashCode();
    489     }
    490
    491     /**
    492      * Save the X500Principal object to a stream.
    493      *
    494      * @serialData this {@code X500Principal} is serialized
    495      *          by writing out its DER-encoded form
    496      *          (the value of {@code getEncoded} is serialized).
    497      *
    498      * @param  s the {@code ObjectOutputStream} to which data is written
    499      * @throws IOException if an I/O error occurs
    500      */
    501     @java.io.Serial
    502     private void writeObject(java.io.ObjectOutputStream s)
    503         throws IOException {
    504         s.writeObject(thisX500Name.getEncodedInternal());
    505     }
    506
    507     /**
    508      * Reads this object from a stream (i.e., deserializes it).
    509      *
    510      * @param  s the {@code ObjectInputStream} from which data is read
    511      * @throws IOException if an I/O error occurs
    512      * @throws NotActiveException if serialization is not active
    513      * @throws ClassNotFoundException if a serialized class cannot be loaded
    514      */
    515     @java.io.Serial
    516     private void readObject(java.io.ObjectInputStream s)
    517         throws java.io.IOException,
    518                java.io.NotActiveException,
    519                ClassNotFoundException {
    520
    521         // re-create thisX500Name
    522         thisX500Name = new X500Name((byte[])s.readObject());
    523     }
    524 }

< prev index next >