Home | History | Annotate | Download | only in x509
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19 * @author Alexander Y. Kleymenov
     20 * @version $Revision$
     21 */
     22 
     23 package org.apache.harmony.security.x509;
     24 
     25 import java.util.ArrayList;
     26 import java.util.Collection;
     27 import java.util.List;
     28 import org.apache.harmony.security.asn1.ASN1SequenceOf;
     29 import org.apache.harmony.security.asn1.ASN1Type;
     30 import org.apache.harmony.security.asn1.BerInputStream;
     31 
     32 /**
     33  * The class encapsulates the ASN.1 DER encoding/decoding work
     34  * with the GeneralSubtrees structure which is a part of X.509 certificate:
     35  * (as specified in RFC 3280 -
     36  *  Internet X.509 Public Key Infrastructure.
     37  *  Certificate and Certificate Revocation List (CRL) Profile.
     38  *  http://www.ietf.org/rfc/rfc3280.txt):
     39  *
     40  * <pre>
     41  *   GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree
     42  * </pre>
     43  *
     44  * @see org.apache.harmony.security.x509.NameConstraints
     45  * @see org.apache.harmony.security.x509.GeneralSubtree
     46  */
     47 public final class GeneralSubtrees {
     48     /** the list of values of GeneralSubtrees */
     49     private List<GeneralSubtree> generalSubtrees;
     50     /** the ASN.1 encoded form of GeneralSubtrees */
     51     private byte[] encoding;
     52 
     53     public GeneralSubtrees(List<GeneralSubtree> generalSubtrees) {
     54         // TODO: the size should not be less than one
     55         this.generalSubtrees = generalSubtrees;
     56     }
     57 
     58     /**
     59      * Returns the list of values of subtrees.
     60      */
     61     public List<GeneralSubtree> getSubtrees() {
     62         return generalSubtrees;
     63     }
     64 
     65     /**
     66      * Returns ASN.1 encoded form of this X.509 AlgorithmIdentifier value.
     67      */
     68     public byte[] getEncoded() {
     69         if (encoding == null) {
     70             encoding = ASN1.encode(this);
     71         }
     72         return encoding;
     73     }
     74 
     75     /**
     76      * ASN.1 DER X.509 GeneralSubtrees encoder/decoder class.
     77      */
     78     public static final ASN1Type ASN1 = new ASN1SequenceOf(GeneralSubtree.ASN1) {
     79         @Override public Object getDecodedObject(BerInputStream in) {
     80             return new GeneralSubtrees((List<GeneralSubtree>) in.content);
     81         }
     82 
     83         @Override public Collection getValues(Object object) {
     84             GeneralSubtrees gss = (GeneralSubtrees) object;
     85             return (gss.generalSubtrees == null)
     86                     ? new ArrayList<GeneralSubtree>()
     87                     : gss.generalSubtrees;
     88         }
     89     };
     90 }
     91 
     92