Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/LastReqEntry.java
41161 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25*26* (C) Copyright IBM Corp. 1999 All Rights Reserved.27* Copyright 1997 The Open Group Research Institute. All rights reserved.28*/2930package sun.security.krb5.internal;3132import sun.security.util.*;33import sun.security.krb5.Asn1Exception;34import java.io.IOException;3536public class LastReqEntry {37private int lrType;38private KerberosTime lrValue;3940private LastReqEntry() {41}4243public LastReqEntry(int Type, KerberosTime time){44lrType = Type;45lrValue = time;46// XXX check the type and time.47}4849/**50* Constructs a LastReqEntry object.51* @param encoding a Der-encoded data.52* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.53* @exception IOException if an I/O error occurs while reading encoded data.54*/55public LastReqEntry(DerValue encoding) throws Asn1Exception, IOException {56if (encoding.getTag() != DerValue.tag_Sequence) {57throw new Asn1Exception(Krb5.ASN1_BAD_ID);58}59DerValue der;60der = encoding.getData().getDerValue();61if ((der.getTag() & 0x1F) == 0x00){62lrType = der.getData().getBigInteger().intValue();63}64else65throw new Asn1Exception(Krb5.ASN1_BAD_ID);6667lrValue = KerberosTime.parse(encoding.getData(), (byte)0x01, false);68if (encoding.getData().available() > 0)69throw new Asn1Exception(Krb5.ASN1_BAD_ID);70}7172/**73* Encodes an LastReqEntry object.74* @return the byte array of encoded LastReqEntry object.75* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.76* @exception IOException if an I/O error occurs while reading encoded data.77*/78public byte[] asn1Encode() throws Asn1Exception, IOException {79DerOutputStream bytes = new DerOutputStream();80DerOutputStream temp = new DerOutputStream();81temp.putInteger(lrType);82bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);83bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), lrValue.asn1Encode());84temp = new DerOutputStream();85temp.write(DerValue.tag_Sequence, bytes);86return temp.toByteArray();87}8889public Object clone() {90LastReqEntry newEntry = new LastReqEntry();91newEntry.lrType = lrType;92newEntry.lrValue = lrValue;93return newEntry;94}95}969798