src/java.security.jgss/share/classes/sun/security/krb5/internal/PAData.java
changeset 55258 d65d3c37232c
parent 47226 4f029f064481
child 59024 b046ba510bbc
equal deleted inserted replaced
55257:442b86eb633c 55258:d65d3c37232c
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    33 
    33 
    34 import sun.security.krb5.internal.crypto.EType;
    34 import sun.security.krb5.internal.crypto.EType;
    35 import sun.security.util.*;
    35 import sun.security.util.*;
    36 import sun.security.krb5.Asn1Exception;
    36 import sun.security.krb5.Asn1Exception;
    37 import java.io.IOException;
    37 import java.io.IOException;
       
    38 import java.util.Vector;
       
    39 
    38 import sun.security.krb5.internal.util.KerberosString;
    40 import sun.security.krb5.internal.util.KerberosString;
    39 
    41 
    40 /**
    42 /**
    41  * Implements the ASN.1 PA-DATA type.
    43  * Implements the ASN.1 PA-DATA type.
    42  *
    44  *
   135         return pADataType;
   137         return pADataType;
   136     }
   138     }
   137 
   139 
   138     public byte[] getValue() {
   140     public byte[] getValue() {
   139         return ((pADataValue == null) ? null : pADataValue.clone());
   141         return ((pADataValue == null) ? null : pADataValue.clone());
       
   142     }
       
   143 
       
   144     /**
       
   145      * Parse (unmarshal) a PAData from a DER input stream.  This form
       
   146      * parsing might be used when expanding a value which is part of
       
   147      * a constructed sequence and uses explicitly tagged type.
       
   148      *
       
   149      * @exception Asn1Exception if an Asn1Exception occurs.
       
   150      * @param data the Der input stream value, which contains one or more
       
   151      *        marshaled values.
       
   152      * @param explicitTag tag number.
       
   153      * @param optional indicates if this data field is optional.
       
   154      * @return an array of PAData.
       
   155      */
       
   156     public static PAData[] parseSequence(DerInputStream data,
       
   157                                       byte explicitTag, boolean optional)
       
   158         throws Asn1Exception, IOException {
       
   159         if ((optional) &&
       
   160                 (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
       
   161                 return null;
       
   162         DerValue subDer = data.getDerValue();
       
   163         DerValue subsubDer = subDer.getData().getDerValue();
       
   164         if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
       
   165             throw new Asn1Exception(Krb5.ASN1_BAD_ID);
       
   166         }
       
   167         Vector<PAData> v = new Vector<>();
       
   168         while (subsubDer.getData().available() > 0) {
       
   169             v.addElement(new PAData(subsubDer.getData().getDerValue()));
       
   170         }
       
   171         if (v.size() > 0) {
       
   172             PAData[] pas = new PAData[v.size()];
       
   173             v.copyInto(pas);
       
   174             return pas;
       
   175         }
       
   176         return null;
   140     }
   177     }
   141 
   178 
   142     /**
   179     /**
   143      * Gets the preferred etype from the PAData array.
   180      * Gets the preferred etype from the PAData array.
   144      * <ol>
   181      * <ol>