001: /*
002: * @(#)CertificatePolicyId.java 1.16 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package sun.security.x509;
029:
030: import java.io.IOException;
031: import sun.security.util.*;
032:
033: /**
034: * Represent the CertificatePolicyId ASN.1 object.
035: *
036: * @author Amit Kapoor
037: * @author Hemma Prafullchandra
038: * @version 1.9
039: */
040: public class CertificatePolicyId {
041: private ObjectIdentifier id;
042:
043: /**
044: * Create a CertificatePolicyId with the ObjectIdentifier.
045: *
046: * @param id the ObjectIdentifier for the policy id.
047: */
048: public CertificatePolicyId(ObjectIdentifier id) {
049: this .id = id;
050: }
051:
052: /**
053: * Create the object from its Der encoded value.
054: *
055: * @param val the DER encoded value for the same.
056: */
057: public CertificatePolicyId(DerValue val) throws IOException {
058: this .id = val.getOID();
059: }
060:
061: /**
062: * Return the value of the CertificatePolicyId as an ObjectIdentifier.
063: */
064: public ObjectIdentifier getIdentifier() {
065: return (id);
066: }
067:
068: /**
069: * Returns a printable representation of the CertificatePolicyId.
070: */
071: public String toString() {
072: String s = "CertificatePolicyId: [" + id.toString() + "]\n";
073:
074: return (s);
075: }
076:
077: /**
078: * Write the CertificatePolicyId to the DerOutputStream.
079: *
080: * @param out the DerOutputStream to write the object to.
081: * @exception IOException on errors.
082: */
083: public void encode(DerOutputStream out) throws IOException {
084: out.putOID(id);
085: }
086:
087: /**
088: * Compares this CertificatePolicyId with another, for
089: * equality. Uses ObjectIdentifier.equals() as test for
090: * equality.
091: *
092: * @return true iff the ids are identical.
093: */
094: public boolean equals(Object other) {
095: if (other instanceof CertificatePolicyId)
096: return id.equals(((CertificatePolicyId) other)
097: .getIdentifier());
098: else
099: return false;
100: }
101:
102: /**
103: * Returns a hash code value for this object.
104: *
105: * @return a hash code value
106: */
107: public int hashCode() {
108: return id.hashCode();
109: }
110: }
|