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.ASN1OctetString;
22  import org.apache.geronimo.util.asn1.DERBoolean;
23  
24  /**
25   * an object for the elements in the X.509 V3 extension block.
26   */
27  public class X509Extension
28  {
29      boolean             critical;
30      ASN1OctetString      value;
31  
32      public X509Extension(
33          DERBoolean              critical,
34          ASN1OctetString         value)
35      {
36          this.critical = critical.isTrue();
37          this.value = value;
38      }
39  
40      public X509Extension(
41          boolean                 critical,
42          ASN1OctetString         value)
43      {
44          this.critical = critical;
45          this.value = value;
46      }
47  
48      public boolean isCritical()
49      {
50          return critical;
51      }
52  
53      public ASN1OctetString getValue()
54      {
55          return value;
56      }
57  
58      public int hashCode()
59      {
60          if (this.isCritical())
61          {
62              return this.getValue().hashCode();
63          }
64  
65  
66          return ~this.getValue().hashCode();
67      }
68  
69      public boolean equals(
70          Object  o)
71      {
72          if (o == null || !(o instanceof X509Extension))
73          {
74              return false;
75          }
76  
77          X509Extension   other = (X509Extension)o;
78  
79          return other.getValue().equals(this.getValue())
80              && (other.isCritical() == this.isCritical());
81      }
82  }