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