1. /*
  2. * @(#)X509CRLEntry.java 1.16 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.math.BigInteger;
  9. import java.util.Date;
  10. import java.util.Set;
  11. import javax.security.auth.x500.X500Principal;
  12. /**
  13. * <p>Abstract class for a revoked certificate in a CRL (Certificate
  14. * Revocation List).
  15. *
  16. * The ASN.1 definition for <em>revokedCertificates</em> is:
  17. * <pre>
  18. * revokedCertificates SEQUENCE OF SEQUENCE {
  19. * userCertificate CertificateSerialNumber,
  20. * revocationDate ChoiceOfTime,
  21. * crlEntryExtensions Extensions OPTIONAL
  22. * -- if present, must be v2
  23. * } OPTIONAL
  24. *<p>
  25. * CertificateSerialNumber ::= INTEGER
  26. *<p>
  27. * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
  28. *<p>
  29. * Extension ::= SEQUENCE {
  30. * extnId OBJECT IDENTIFIER,
  31. * critical BOOLEAN DEFAULT FALSE,
  32. * extnValue OCTET STRING
  33. * -- contains a DER encoding of a value
  34. * -- of the type registered for use with
  35. * -- the extnId object identifier value
  36. * }
  37. * </pre>
  38. *
  39. * @see X509CRL
  40. * @see X509Extension
  41. *
  42. * @author Hemma Prafullchandra
  43. * @version 1.16 03/12/19
  44. */
  45. public abstract class X509CRLEntry implements X509Extension {
  46. /**
  47. * Compares this CRL entry for equality with the given
  48. * object. If the <code>other</code> object is an
  49. * <code>instanceof</code> <code>X509CRLEntry</code>, then
  50. * its encoded form (the inner SEQUENCE) is retrieved and compared
  51. * with the encoded form of this CRL entry.
  52. *
  53. * @param other the object to test for equality with this CRL entry.
  54. * @return true iff the encoded forms of the two CRL entries
  55. * match, false otherwise.
  56. */
  57. public boolean equals(Object other) {
  58. if (this == other)
  59. return true;
  60. if (!(other instanceof X509CRLEntry))
  61. return false;
  62. try {
  63. byte[] thisCRLEntry = this.getEncoded();
  64. byte[] otherCRLEntry = ((X509CRLEntry)other).getEncoded();
  65. if (thisCRLEntry.length != otherCRLEntry.length)
  66. return false;
  67. for (int i = 0; i < thisCRLEntry.length; i++)
  68. if (thisCRLEntry[i] != otherCRLEntry[i])
  69. return false;
  70. } catch (CRLException ce) {
  71. return false;
  72. }
  73. return true;
  74. }
  75. /**
  76. * Returns a hashcode value for this CRL entry from its
  77. * encoded form.
  78. *
  79. * @return the hashcode value.
  80. */
  81. public int hashCode() {
  82. int retval = 0;
  83. try {
  84. byte[] entryData = this.getEncoded();
  85. for (int i = 1; i < entryData.length; i++)
  86. retval += entryData[i] * i;
  87. } catch (CRLException ce) {
  88. return(retval);
  89. }
  90. return(retval);
  91. }
  92. /**
  93. * Returns the ASN.1 DER-encoded form of this CRL Entry,
  94. * that is the inner SEQUENCE.
  95. *
  96. * @return the encoded form of this certificate
  97. * @exception CRLException if an encoding error occurs.
  98. */
  99. public abstract byte[] getEncoded() throws CRLException;
  100. /**
  101. * Gets the serial number from this X509CRLEntry,
  102. * the <em>userCertificate</em>.
  103. *
  104. * @return the serial number.
  105. */
  106. public abstract BigInteger getSerialNumber();
  107. /**
  108. * Get the issuer of the X509Certificate described by this entry. If
  109. * the certificate issuer is also the CRL issuer, this method returns
  110. * null.
  111. *
  112. * <p>This method is used with indirect CRLs. The default implementation
  113. * always returns null. Subclasses that wish to support indirect CRLs
  114. * should override it.
  115. *
  116. * @return the issuer of the X509Certificate described by this entry
  117. * or null if it is issued by the CRL issuer.
  118. *
  119. * @since 1.5
  120. */
  121. public X500Principal getCertificateIssuer() {
  122. return null;
  123. }
  124. /**
  125. * Gets the revocation date from this X509CRLEntry,
  126. * the <em>revocationDate</em>.
  127. *
  128. * @return the revocation date.
  129. */
  130. public abstract Date getRevocationDate();
  131. /**
  132. * Returns true if this CRL entry has extensions.
  133. *
  134. * @return true if this entry has extensions, false otherwise.
  135. */
  136. public abstract boolean hasExtensions();
  137. /**
  138. * Returns a string representation of this CRL entry.
  139. *
  140. * @return a string representation of this CRL entry.
  141. */
  142. public abstract String toString();
  143. }