01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: import java.util.Enumeration;
19:
20: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
21: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
22: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
23: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
24: import org.apache.geronimo.crypto.asn1.DERObject;
25: import org.apache.geronimo.crypto.asn1.DERSequence;
26: import org.apache.geronimo.crypto.asn1.DERTaggedObject;
27:
28: public class NameConstraints extends ASN1Encodable {
29: ASN1Sequence permitted, excluded;
30:
31: public NameConstraints(ASN1Sequence seq) {
32: Enumeration e = seq.getObjects();
33: while (e.hasMoreElements()) {
34: ASN1TaggedObject o = (ASN1TaggedObject) e.nextElement();
35: switch (o.getTagNo()) {
36: case 0:
37: permitted = ASN1Sequence.getInstance(o, false);
38: break;
39: case 1:
40: excluded = ASN1Sequence.getInstance(o, false);
41: break;
42: }
43: }
44: }
45:
46: public ASN1Sequence getPermittedSubtrees() {
47: return permitted;
48: }
49:
50: public ASN1Sequence getExcludedSubtrees() {
51: return excluded;
52: }
53:
54: /*
55: * NameConstraints ::= SEQUENCE {
56: * permittedSubtrees [0] GeneralSubtrees OPTIONAL,
57: * excludedSubtrees [1] GeneralSubtrees OPTIONAL }
58: */
59: public DERObject toASN1Object() {
60: ASN1EncodableVector v = new ASN1EncodableVector();
61:
62: if (permitted != null) {
63: v.add(new DERTaggedObject(false, 0, permitted));
64: }
65:
66: if (excluded != null) {
67: v.add(new DERTaggedObject(false, 1, excluded));
68: }
69:
70: return new DERSequence(v);
71: }
72: }
|