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.pkcs;
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.DERBitString;
25  import org.apache.geronimo.util.asn1.DERObject;
26  import org.apache.geronimo.util.asn1.DERSequence;
27  import org.apache.geronimo.util.asn1.x509.AlgorithmIdentifier;
28  
29  /**
30   * PKCS10 Certification request object.
31   * <pre>
32   * CertificationRequest ::= SEQUENCE {
33   *   certificationRequestInfo  CertificationRequestInfo,
34   *   signatureAlgorithm        AlgorithmIdentifier{{ SignatureAlgorithms }},
35   *   signature                 BIT STRING
36   * }
37   * </pre>
38   */
39  public class CertificationRequest
40      extends ASN1Encodable
41  {
42      protected CertificationRequestInfo reqInfo = null;
43      protected AlgorithmIdentifier sigAlgId = null;
44      protected DERBitString sigBits = null;
45  
46      protected CertificationRequest()
47      {
48      }
49  
50      public CertificationRequest(
51          CertificationRequestInfo requestInfo,
52          AlgorithmIdentifier     algorithm,
53          DERBitString            signature)
54      {
55          this.reqInfo = requestInfo;
56          this.sigAlgId = algorithm;
57          this.sigBits = signature;
58      }
59  
60      public CertificationRequest(
61          ASN1Sequence seq)
62      {
63          reqInfo = CertificationRequestInfo.getInstance(seq.getObjectAt(0));
64          sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
65          sigBits = (DERBitString)seq.getObjectAt(2);
66      }
67  
68      public CertificationRequestInfo getCertificationRequestInfo()
69      {
70          return reqInfo;
71      }
72  
73      public AlgorithmIdentifier getSignatureAlgorithm()
74      {
75          return sigAlgId;
76      }
77  
78      public DERBitString getSignature()
79      {
80          return sigBits;
81      }
82  
83      public DERObject toASN1Object()
84      {
85          // Construct the CertificateRequest
86          ASN1EncodableVector  v = new ASN1EncodableVector();
87  
88          v.add(reqInfo);
89          v.add(sigAlgId);
90          v.add(sigBits);
91  
92          return new DERSequence(v);
93      }
94  }