001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.security.x509;
022:
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.List;
026:
027: import org.apache.harmony.security.asn1.ASN1SequenceOf;
028: import org.apache.harmony.security.asn1.ASN1Type;
029: import org.apache.harmony.security.asn1.BerInputStream;
030:
031: /**
032: * The class encapsulates the ASN.1 DER encoding/decoding work
033: * with the GeneralSubtrees structure which is a part of X.509 certificate:
034: * (as specified in RFC 3280 -
035: * Internet X.509 Public Key Infrastructure.
036: * Certificate and Certificate Revocation List (CRL) Profile.
037: * http://www.ietf.org/rfc/rfc3280.txt):
038: *
039: * <pre>
040: * GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree
041: * </pre>
042: *
043: * @see org.apache.harmony.security.x509.NameConstraints
044: * @see org.apache.harmony.security.x509.GeneralSubtree
045: */
046:
047: public class GeneralSubtrees {
048:
049: // the list of values of GeneralSubtrees
050: private List generalSubtrees;
051: // the ASN.1 encoded form of GeneralSubtrees
052: private byte[] encoding;
053:
054: /**
055: * Constructs an object representing the value of GeneralSubtrees.
056: */
057: public GeneralSubtrees() {
058: }
059:
060: /**
061: * TODO
062: * @param generalSubtrees: List
063: */
064: public GeneralSubtrees(List generalSubtrees) {
065: // TODO: the size should not be less than one
066: this .generalSubtrees = generalSubtrees;
067: }
068:
069: /**
070: * Returns the list of values of subtrees.
071: * @return subtrees
072: */
073: public List getSubtrees() {
074: return generalSubtrees;
075: }
076:
077: /**
078: * TODO
079: * @param subtree: GeneralSubtree
080: * @return
081: */
082: public GeneralSubtrees addSubtree(GeneralSubtree subtree) {
083: encoding = null;
084: if (generalSubtrees == null) {
085: generalSubtrees = new ArrayList();
086: }
087: generalSubtrees.add(subtree);
088: return this ;
089: }
090:
091: /**
092: * Returns ASN.1 encoded form of this X.509 AlgorithmIdentifier value.
093: * @return a byte array containing ASN.1 encode form.
094: */
095: public byte[] getEncoded() {
096: if (encoding == null) {
097: encoding = ASN1.encode(this );
098: }
099: return encoding;
100: }
101:
102: /**
103: * ASN.1 DER X.509 GeneralSubtrees encoder/decoder class.
104: */
105: public static final ASN1Type ASN1 = new ASN1SequenceOf(
106: GeneralSubtree.ASN1) {
107:
108: public Object getDecodedObject(BerInputStream in) {
109: return new GeneralSubtrees((List) in.content);
110: }
111:
112: public Collection getValues(Object object) {
113: GeneralSubtrees gss = (GeneralSubtrees) object;
114: return (gss.generalSubtrees == null) ? new ArrayList()
115: : gss.generalSubtrees;
116: }
117: };
118: }
|