View Javadoc

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 org.apache.geronimo.util.asn1.ASN1Encodable;
22  import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23  import org.apache.geronimo.util.asn1.ASN1Sequence;
24  import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25  import org.apache.geronimo.util.asn1.DERObject;
26  import org.apache.geronimo.util.asn1.DERSequence;
27  import org.apache.geronimo.util.asn1.DERTaggedObject;
28  
29  public class V2Form
30      extends ASN1Encodable
31  {
32      GeneralNames        issuerName;
33      IssuerSerial        baseCertificateID;
34      ObjectDigestInfo    objectDigestInfo;
35  
36      public static V2Form getInstance(
37          ASN1TaggedObject obj,
38          boolean          explicit)
39      {
40          return getInstance(ASN1Sequence.getInstance(obj, explicit));
41      }
42  
43      public static V2Form getInstance(
44          Object  obj)
45      {
46          if (obj == null || obj instanceof V2Form)
47          {
48              return (V2Form)obj;
49          }
50          else if (obj instanceof ASN1Sequence)
51          {
52              return new V2Form((ASN1Sequence)obj);
53          }
54  
55          throw new IllegalArgumentException("unknown object in factory");
56      }
57  
58      public V2Form(
59          GeneralNames    issuerName)
60      {
61          this.issuerName = issuerName;
62      }
63  
64      public V2Form(
65          ASN1Sequence seq)
66      {
67          int    index = 0;
68  
69          if (!(seq.getObjectAt(0) instanceof ASN1TaggedObject))
70          {
71              index++;
72              this.issuerName = GeneralNames.getInstance(seq.getObjectAt(0));
73          }
74  
75          for (int i = index; i != seq.size(); i++)
76          {
77              ASN1TaggedObject o = (ASN1TaggedObject)seq.getObjectAt(i);
78              if (o.getTagNo() == 0)
79              {
80                  baseCertificateID = IssuerSerial.getInstance(o, false);
81              }
82              else if (o.getTagNo() == 1)
83              {
84                  objectDigestInfo = ObjectDigestInfo.getInstance(o, false);
85              }
86          }
87      }
88  
89      public GeneralNames getIssuerName()
90      {
91          return issuerName;
92      }
93  
94      public IssuerSerial getBaseCertificateID()
95      {
96          return baseCertificateID;
97      }
98  
99      public ObjectDigestInfo getObjectDigestInfo()
100     {
101         return objectDigestInfo;
102     }
103 
104     /**
105      * Produce an object suitable for an ASN1OutputStream.
106      * <pre>
107      *  V2Form ::= SEQUENCE {
108      *       issuerName            GeneralNames  OPTIONAL,
109      *       baseCertificateID     [0] IssuerSerial  OPTIONAL,
110      *       objectDigestInfo      [1] ObjectDigestInfo  OPTIONAL
111      *         -- issuerName MUST be present in this profile
112      *         -- baseCertificateID and objectDigestInfo MUST NOT
113      *         -- be present in this profile
114      *  }
115      * </pre>
116      */
117     public DERObject toASN1Object()
118     {
119         ASN1EncodableVector  v = new ASN1EncodableVector();
120 
121         if (issuerName != null)
122         {
123             v.add(issuerName);
124         }
125 
126         if (baseCertificateID != null)
127         {
128             v.add(new DERTaggedObject(false, 0, baseCertificateID));
129         }
130 
131         if (objectDigestInfo != null)
132         {
133             v.add(new DERTaggedObject(false, 1, objectDigestInfo));
134         }
135 
136         return new DERSequence(v);
137     }
138 }