1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import java.util.Enumeration;
22
23 import org.apache.geronimo.util.asn1.ASN1Encodable;
24 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
25 import org.apache.geronimo.util.asn1.ASN1Sequence;
26 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERSequence;
29 import org.apache.geronimo.util.asn1.DERTaggedObject;
30
31 public class NameConstraints
32 extends ASN1Encodable
33 {
34 ASN1Sequence permitted, excluded;
35
36 public NameConstraints(
37 ASN1Sequence seq)
38 {
39 Enumeration e = seq.getObjects();
40 while (e.hasMoreElements())
41 {
42 ASN1TaggedObject o = (ASN1TaggedObject)e.nextElement();
43 switch (o.getTagNo())
44 {
45 case 0:
46 permitted = ASN1Sequence.getInstance(o, false);
47 break;
48 case 1:
49 excluded = ASN1Sequence.getInstance(o, false);
50 break;
51 }
52 }
53 }
54
55 public ASN1Sequence getPermittedSubtrees()
56 {
57 return permitted;
58 }
59
60 public ASN1Sequence getExcludedSubtrees()
61 {
62 return excluded;
63 }
64
65
66
67
68
69
70 public DERObject toASN1Object()
71 {
72 ASN1EncodableVector v = new ASN1EncodableVector();
73
74 if (permitted != null)
75 {
76 v.add(new DERTaggedObject(false, 0, permitted));
77 }
78
79 if (excluded != null)
80 {
81 v.add(new DERTaggedObject(false, 1, excluded));
82 }
83
84 return new DERSequence(v);
85 }
86 }