001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.geronimo.util.asn1.x509;
020
021 import java.util.Enumeration;
022
023 import org.apache.geronimo.util.asn1.ASN1Encodable;
024 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
025 import org.apache.geronimo.util.asn1.ASN1Sequence;
026 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
027 import org.apache.geronimo.util.asn1.DERObject;
028 import org.apache.geronimo.util.asn1.DERSequence;
029 import org.apache.geronimo.util.asn1.DERTaggedObject;
030
031 public class NameConstraints
032 extends ASN1Encodable
033 {
034 ASN1Sequence permitted, excluded;
035
036 public NameConstraints(
037 ASN1Sequence seq)
038 {
039 Enumeration e = seq.getObjects();
040 while (e.hasMoreElements())
041 {
042 ASN1TaggedObject o = (ASN1TaggedObject)e.nextElement();
043 switch (o.getTagNo())
044 {
045 case 0:
046 permitted = ASN1Sequence.getInstance(o, false);
047 break;
048 case 1:
049 excluded = ASN1Sequence.getInstance(o, false);
050 break;
051 }
052 }
053 }
054
055 public ASN1Sequence getPermittedSubtrees()
056 {
057 return permitted;
058 }
059
060 public ASN1Sequence getExcludedSubtrees()
061 {
062 return excluded;
063 }
064
065 /*
066 * NameConstraints ::= SEQUENCE {
067 * permittedSubtrees [0] GeneralSubtrees OPTIONAL,
068 * excludedSubtrees [1] GeneralSubtrees OPTIONAL }
069 */
070 public DERObject toASN1Object()
071 {
072 ASN1EncodableVector v = new ASN1EncodableVector();
073
074 if (permitted != null)
075 {
076 v.add(new DERTaggedObject(false, 0, permitted));
077 }
078
079 if (excluded != null)
080 {
081 v.add(new DERTaggedObject(false, 1, excluded));
082 }
083
084 return new DERSequence(v);
085 }
086 }