KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > NameConstraints


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 package org.apache.geronimo.util.asn1.x509;
19
20 import java.util.Enumeration JavaDoc;
21
22 import org.apache.geronimo.util.asn1.ASN1Encodable;
23 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
24 import org.apache.geronimo.util.asn1.ASN1Sequence;
25 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
26 import org.apache.geronimo.util.asn1.DERObject;
27 import org.apache.geronimo.util.asn1.DERSequence;
28 import org.apache.geronimo.util.asn1.DERTaggedObject;
29
30 public class NameConstraints
31     extends ASN1Encodable
32 {
33     ASN1Sequence permitted, excluded;
34
35     public NameConstraints(
36         ASN1Sequence seq)
37     {
38         Enumeration JavaDoc e = seq.getObjects();
39         while (e.hasMoreElements())
40         {
41             ASN1TaggedObject o = (ASN1TaggedObject)e.nextElement();
42             switch (o.getTagNo())
43             {
44             case 0:
45                 permitted = ASN1Sequence.getInstance(o, false);
46                 break;
47             case 1:
48                 excluded = ASN1Sequence.getInstance(o, false);
49                 break;
50             }
51         }
52     }
53
54     public ASN1Sequence getPermittedSubtrees()
55     {
56         return permitted;
57     }
58
59     public ASN1Sequence getExcludedSubtrees()
60     {
61         return excluded;
62     }
63
64     /*
65      * NameConstraints ::= SEQUENCE {
66      * permittedSubtrees [0] GeneralSubtrees OPTIONAL,
67      * excludedSubtrees [1] GeneralSubtrees OPTIONAL }
68      */

69     public DERObject toASN1Object()
70     {
71         ASN1EncodableVector v = new ASN1EncodableVector();
72
73         if (permitted != null)
74         {
75             v.add(new DERTaggedObject(false, 0, permitted));
76         }
77
78         if (excluded != null)
79         {
80             v.add(new DERTaggedObject(false, 1, excluded));
81         }
82
83         return new DERSequence(v);
84     }
85 }
86
Popular Tags