< prev index next >

src/java.security.jgss/share/classes/sun/security/krb5/Checksum.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


 201     public Checksum(byte[] data) throws KdcErrException, KrbCryptoException {
 202         this(Checksum.CKSUMTYPE_DEFAULT, data);
 203     }
 204     */
 205 
 206     boolean isEqual(Checksum cksum) throws KdcErrException {
 207         if (cksumType != cksum.cksumType)
 208             return false;
 209         CksumType cksumEngine = CksumType.getInstance(cksumType);
 210         return CksumType.isChecksumEqual(checksum, cksum.checksum);
 211     }
 212 
 213     /**
 214      * Constructs an instance of Checksum from an ASN.1 encoded representation.
 215      * @param encoding a single DER-encoded value.
 216      * @exception Asn1Exception if an error occurs while decoding an ASN1
 217      * encoded data.
 218      * @exception IOException if an I/O error occurs while reading encoded data.
 219      *
 220      */
 221     public Checksum(DerValue encoding) throws Asn1Exception, IOException {
 222         DerValue der;
 223         if (encoding.getTag() != DerValue.tag_Sequence) {
 224             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 225         }
 226         der = encoding.getData().getDerValue();
 227         if ((der.getTag() & (byte)0x1F) == (byte)0x00) {
 228             cksumType = der.getData().getBigInteger().intValue();
 229         }
 230         else
 231             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 232         der = encoding.getData().getDerValue();
 233         if ((der.getTag() & (byte)0x1F) == (byte)0x01) {
 234             checksum = der.getData().getOctetString();
 235         }
 236         else
 237             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 238         if (encoding.getData().available() > 0) {
 239             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 240         }
 241     }


   1 /*
   2  * Copyright (c) 2000, 2017, 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


 201     public Checksum(byte[] data) throws KdcErrException, KrbCryptoException {
 202         this(Checksum.CKSUMTYPE_DEFAULT, data);
 203     }
 204     */
 205 
 206     boolean isEqual(Checksum cksum) throws KdcErrException {
 207         if (cksumType != cksum.cksumType)
 208             return false;
 209         CksumType cksumEngine = CksumType.getInstance(cksumType);
 210         return CksumType.isChecksumEqual(checksum, cksum.checksum);
 211     }
 212 
 213     /**
 214      * Constructs an instance of Checksum from an ASN.1 encoded representation.
 215      * @param encoding a single DER-encoded value.
 216      * @exception Asn1Exception if an error occurs while decoding an ASN1
 217      * encoded data.
 218      * @exception IOException if an I/O error occurs while reading encoded data.
 219      *
 220      */
 221     private Checksum(DerValue encoding) throws Asn1Exception, IOException {
 222         DerValue der;
 223         if (encoding.getTag() != DerValue.tag_Sequence) {
 224             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 225         }
 226         der = encoding.getData().getDerValue();
 227         if ((der.getTag() & (byte)0x1F) == (byte)0x00) {
 228             cksumType = der.getData().getBigInteger().intValue();
 229         }
 230         else
 231             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 232         der = encoding.getData().getDerValue();
 233         if ((der.getTag() & (byte)0x1F) == (byte)0x01) {
 234             checksum = der.getData().getOctetString();
 235         }
 236         else
 237             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 238         if (encoding.getData().available() > 0) {
 239             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
 240         }
 241     }


< prev index next >