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.DERBitString;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERSequence;
27
28 public class AttributeCertificate
29 extends ASN1Encodable
30 {
31 AttributeCertificateInfo acinfo;
32 AlgorithmIdentifier signatureAlgorithm;
33 DERBitString signatureValue;
34
35 /**
36 * @param obj
37 * @return an AttributeCertificate object
38 */
39 public static AttributeCertificate getInstance(Object obj)
40 {
41 if (obj instanceof AttributeCertificate)
42 {
43 return (AttributeCertificate)obj;
44 }
45 else if (obj instanceof ASN1Sequence)
46 {
47 return new AttributeCertificate((ASN1Sequence)obj);
48 }
49
50 throw new IllegalArgumentException("unknown object in factory");
51 }
52
53 public AttributeCertificate(
54 AttributeCertificateInfo acinfo,
55 AlgorithmIdentifier signatureAlgorithm,
56 DERBitString signatureValue)
57 {
58 this.acinfo = acinfo;
59 this.signatureAlgorithm = signatureAlgorithm;
60 this.signatureValue = signatureValue;
61 }
62
63 public AttributeCertificate(
64 ASN1Sequence seq)
65 {
66 this.acinfo = AttributeCertificateInfo.getInstance(seq.getObjectAt(0));
67 this.signatureAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
68 this.signatureValue = DERBitString.getInstance(seq.getObjectAt(2));
69 }
70
71 public AttributeCertificateInfo getAcinfo()
72 {
73 return acinfo;
74 }
75
76 public AlgorithmIdentifier getSignatureAlgorithm()
77 {
78 return signatureAlgorithm;
79 }
80
81 public DERBitString getSignatureValue()
82 {
83 return signatureValue;
84 }
85
86 /**
87 * Produce an object suitable for an ASN1OutputStream.
88 * <pre>
89 * AttributeCertificate ::= SEQUENCE {
90 * acinfo AttributeCertificateInfo,
91 * signatureAlgorithm AlgorithmIdentifier,
92 * signatureValue BIT STRING
93 * }
94 * </pre>
95 */
96 public DERObject toASN1Object()
97 {
98 ASN1EncodableVector v = new ASN1EncodableVector();
99
100 v.add(acinfo);
101 v.add(signatureAlgorithm);
102 v.add(signatureValue);
103
104 return new DERSequence(v);
105 }
106 }