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;
020    
021    import java.io.ByteArrayOutputStream;
022    import java.io.IOException;
023    
024    public abstract class ASN1Encodable
025        implements DEREncodable
026    {
027        public byte[] getEncoded()
028            throws IOException
029        {
030            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
031            ASN1OutputStream        aOut = new ASN1OutputStream(bOut);
032    
033            aOut.writeObject(this);
034    
035            return bOut.toByteArray();
036        }
037    
038        public int hashCode()
039        {
040            return this.toASN1Object().hashCode();
041        }
042    
043        public boolean equals(
044            Object  o)
045        {
046            if ((o == null) || !(o instanceof ASN1Encodable))
047            {
048                return false;
049            }
050    
051            ASN1Encodable other = (ASN1Encodable)o;
052    
053            return this.toASN1Object().equals(other.toASN1Object());
054        }
055    
056        public DERObject getDERObject()
057        {
058            return this.toASN1Object();
059        }
060    
061        public abstract DERObject toASN1Object();
062    }