001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.util.asn1.x509;
019
020 import org.apache.geronimo.util.asn1.ASN1OctetString;
021 import org.apache.geronimo.util.asn1.DERBoolean;
022
023 /**
024 * an object for the elements in the X.509 V3 extension block.
025 */
026 public class X509Extension
027 {
028 boolean critical;
029 ASN1OctetString value;
030
031 public X509Extension(
032 DERBoolean critical,
033 ASN1OctetString value)
034 {
035 this.critical = critical.isTrue();
036 this.value = value;
037 }
038
039 public X509Extension(
040 boolean critical,
041 ASN1OctetString value)
042 {
043 this.critical = critical;
044 this.value = value;
045 }
046
047 public boolean isCritical()
048 {
049 return critical;
050 }
051
052 public ASN1OctetString getValue()
053 {
054 return value;
055 }
056
057 public int hashCode()
058 {
059 if (this.isCritical())
060 {
061 return this.getValue().hashCode();
062 }
063
064
065 return ~this.getValue().hashCode();
066 }
067
068 public boolean equals(
069 Object o)
070 {
071 if (o == null || !(o instanceof X509Extension))
072 {
073 return false;
074 }
075
076 X509Extension other = (X509Extension)o;
077
078 return other.getValue().equals(this.getValue())
079 && (other.isCritical() == this.isCritical());
080 }
081 }