Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/APOptions.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.krb5.Asn1Exception;33import sun.security.krb5.internal.util.KerberosFlags;34import sun.security.util.*;35import java.io.IOException;3637/**38* Implements the ASN.1 APOptions type.39*40* <pre>{@code41* APOptions ::= KerberosFlags42* -- reserved(0),43* -- use-session-key(1),44* -- mutual-required(2)45*46* KerberosFlags ::= BIT STRING (SIZE (32..MAX))47* -- minimum number of bits shall be sent,48* -- but no fewer than 3249*50* }</pre>51* <p>52* This definition reflects the Network Working Group RFC412053* specification available at54* <a href="http://www.ietf.org/rfc/rfc4120.txt">55* http://www.ietf.org/rfc/rfc4120.txt</a>.56*/5758public class APOptions extends KerberosFlags {59public APOptions() {60super(Krb5.AP_OPTS_MAX + 1);61}6263public APOptions(int oneBit) throws Asn1Exception {64super(Krb5.AP_OPTS_MAX + 1);65set(oneBit, true);66}67public APOptions(int size, byte[] data) throws Asn1Exception {68super(size, data);69if ((size > data.length * BITS_PER_UNIT) || (size > Krb5.AP_OPTS_MAX + 1)) {70throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);71}72}7374public APOptions(boolean[] data) throws Asn1Exception {75super(data);76if (data.length > Krb5.AP_OPTS_MAX + 1) {77throw new Asn1Exception(Krb5.BITSTRING_BAD_LENGTH);78}79}8081public APOptions(DerValue encoding) throws IOException, Asn1Exception {82this(encoding.getUnalignedBitString(true).toBooleanArray());83}8485/**86* Parse (unmarshal) an APOptions from a DER input stream. This form87* parsing might be used when expanding a value which is part of88* a constructed sequence and uses explicitly tagged type.89*90* @param data the Der input stream value, which contains one or more marshaled value.91* @param explicitTag tag number.92* @param optional indicate if this data field is optional.93* @return an instance of APOptions.94* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.95* @exception IOException if an I/O error occurs while reading encoded data.96*97*/98public static APOptions parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {99if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag))100return null;101DerValue der = data.getDerValue();102if (explicitTag != (der.getTag() & (byte)0x1F)) {103throw new Asn1Exception(Krb5.ASN1_BAD_ID);104} else {105DerValue subDer = der.getData().getDerValue();106return new APOptions(subDer);107}108}109}110111112