Home | History | Annotate | Download | only in x509
      1 /*
      2  * Copyright (c) 1997, 2008, 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
     23  * questions.
     24  */
     25 
     26 package sun.security.x509;
     27 
     28 import java.io.IOException;
     29 import java.util.Vector;
     30 import java.util.List;
     31 import java.util.Collections;
     32 
     33 import sun.security.util.*;
     34 
     35 /**
     36  * This class defines the certificate policy set ASN.1 object.
     37  *
     38  * @author Amit Kapoor
     39  * @author Hemma Prafullchandra
     40  */
     41 public class CertificatePolicySet {
     42 
     43     private final Vector<CertificatePolicyId> ids;
     44 
     45     /**
     46      * The default constructor for this class.
     47      *
     48      * @param ids the sequence of CertificatePolicyId's.
     49      */
     50     public CertificatePolicySet(Vector<CertificatePolicyId> ids) {
     51         this.ids = ids;
     52     }
     53 
     54     /**
     55      * Create the object from the DerValue.
     56      *
     57      * @param in the passed DerInputStream.
     58      * @exception IOException on decoding errors.
     59      */
     60     public CertificatePolicySet(DerInputStream in) throws IOException {
     61         ids = new Vector<CertificatePolicyId>();
     62         DerValue[] seq = in.getSequence(5);
     63 
     64         for (int i = 0; i < seq.length; i++) {
     65             CertificatePolicyId id = new CertificatePolicyId(seq[i]);
     66             ids.addElement(id);
     67         }
     68     }
     69 
     70     /**
     71      * Return printable form of the object.
     72      */
     73     public String toString() {
     74         String s = "CertificatePolicySet:[\n"
     75                  + ids.toString()
     76                  + "]\n";
     77 
     78         return (s);
     79     }
     80 
     81     /**
     82      * Encode the policy set to the output stream.
     83      *
     84      * @param out the DerOutputStream to encode the data to.
     85      */
     86     public void encode(DerOutputStream out) throws IOException {
     87         DerOutputStream tmp = new DerOutputStream();
     88 
     89         for (int i = 0; i < ids.size(); i++) {
     90             ids.elementAt(i).encode(tmp);
     91         }
     92         out.write(DerValue.tag_Sequence,tmp);
     93     }
     94 
     95     /**
     96      * Return the sequence of CertificatePolicyIds.
     97      *
     98      * @return A List containing the CertificatePolicyId objects.
     99      *
    100      */
    101     public List<CertificatePolicyId> getCertPolicyIds() {
    102         return Collections.unmodifiableList(ids);
    103     }
    104 }
    105