01: package org.bouncycastle.asn1.x509;
02:
03: import org.bouncycastle.asn1.ASN1Object;
04: import org.bouncycastle.asn1.ASN1OctetString;
05: import org.bouncycastle.asn1.DERBoolean;
06:
07: import java.io.IOException;
08:
09: /**
10: * an object for the elements in the X.509 V3 extension block.
11: */
12: public class X509Extension {
13: boolean critical;
14: ASN1OctetString value;
15:
16: public X509Extension(DERBoolean critical, ASN1OctetString value) {
17: this .critical = critical.isTrue();
18: this .value = value;
19: }
20:
21: public X509Extension(boolean critical, ASN1OctetString value) {
22: this .critical = critical;
23: this .value = value;
24: }
25:
26: public boolean isCritical() {
27: return critical;
28: }
29:
30: public ASN1OctetString getValue() {
31: return value;
32: }
33:
34: public int hashCode() {
35: if (this .isCritical()) {
36: return this .getValue().hashCode();
37: }
38:
39: return ~this .getValue().hashCode();
40: }
41:
42: public boolean equals(Object o) {
43: if (!(o instanceof X509Extension)) {
44: return false;
45: }
46:
47: X509Extension other = (X509Extension) o;
48:
49: return other.getValue().equals(this .getValue())
50: && (other.isCritical() == this .isCritical());
51: }
52:
53: /**
54: * Convert the value of the passed in extension to an object
55: * @param ext the extension to parse
56: * @return the object the value string contains
57: * @exception IllegalArgumentException if conversion is not possible
58: */
59: public static ASN1Object convertValueToObject(X509Extension ext)
60: throws IllegalArgumentException {
61: try {
62: return ASN1Object.fromByteArray(ext.getValue().getOctets());
63: } catch (IOException e) {
64: throw new IllegalArgumentException(
65: "can't convert extension: " + e);
66: }
67: }
68: }
|