KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > crypto > asn1 > x509 > X509Extension


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.crypto.asn1.x509;
21
22 import com.maverick.crypto.asn1.ASN1OctetString;
23 import com.maverick.crypto.asn1.DERBoolean;
24
25 /**
26  * an object for the elements in the X.509 V3 extension block.
27  */

28 public class X509Extension
29 {
30     boolean critical;
31     ASN1OctetString value;
32
33     public X509Extension(
34         DERBoolean critical,
35         ASN1OctetString value)
36     {
37         this.critical = critical.isTrue();
38         this.value = value;
39     }
40
41     public X509Extension(
42         boolean critical,
43         ASN1OctetString value)
44     {
45         this.critical = critical;
46         this.value = value;
47     }
48
49     public boolean isCritical()
50     {
51         return critical;
52     }
53
54     public ASN1OctetString getValue()
55     {
56         return value;
57     }
58
59     public int hashCode()
60     {
61         if (this.isCritical())
62         {
63             return this.getValue().hashCode();
64         }
65
66
67         return ~this.getValue().hashCode();
68     }
69
70     public boolean equals(
71         Object JavaDoc o)
72     {
73         if (o == null || !(o instanceof X509Extension))
74         {
75             return false;
76         }
77
78         X509Extension other = (X509Extension)o;
79
80         return other.getValue().equals(this.getValue())
81             && (other.isCritical() == this.isCritical());
82     }
83 }
84
Popular Tags