1. /*
  2. * @(#)X509CRLEntry.java 1.14 03/01/23
  3. *
  4. * Copyright 2003 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. /**
  12. * <p>Abstract class for a revoked certificate in a CRL (Certificate
  13. * Revocation List).
  14. *
  15. * The ASN.1 definition for <em>revokedCertificates</em> is:
  16. * <pre>
  17. * revokedCertificates SEQUENCE OF SEQUENCE {
  18. * userCertificate CertificateSerialNumber,
  19. * revocationDate ChoiceOfTime,
  20. * crlEntryExtensions Extensions OPTIONAL
  21. * -- if present, must be v2
  22. * } OPTIONAL
  23. *<p>
  24. * CertificateSerialNumber ::= INTEGER
  25. *<p>
  26. * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
  27. *<p>
  28. * Extension ::= SEQUENCE {
  29. * extnId OBJECT IDENTIFIER,
  30. * critical BOOLEAN DEFAULT FALSE,
  31. * extnValue OCTET STRING
  32. * -- contains a DER encoding of a value
  33. * -- of the type registered for use with
  34. * -- the extnId object identifier value
  35. * }
  36. * </pre>
  37. *
  38. * @see X509CRL
  39. * @see X509Extension
  40. *
  41. * @author Hemma Prafullchandra
  42. * @version 1.14 03/01/23
  43. */
  44. public abstract class X509CRLEntry implements X509Extension {
  45. /**
  46. * Compares this CRL entry for equality with the given
  47. * object. If the <code>other</code> object is an
  48. * <code>instanceof</code> <code>X509CRLEntry</code>, then
  49. * its encoded form (the inner SEQUENCE) is retrieved and compared
  50. * with the encoded form of this CRL entry.
  51. *
  52. * @param other the object to test for equality with this CRL entry.
  53. * @return true iff the encoded forms of the two CRL entries
  54. * match, false otherwise.
  55. */
  56. public boolean equals(Object other) {
  57. if (this == other)
  58. return true;
  59. if (!(other instanceof X509CRLEntry))
  60. return false;
  61. try {
  62. byte[] thisCRLEntry = this.getEncoded();
  63. byte[] otherCRLEntry = ((X509CRLEntry)other).getEncoded();
  64. if (thisCRLEntry.length != otherCRLEntry.length)
  65. return false;
  66. for (int i = 0; i < thisCRLEntry.length; i++)
  67. if (thisCRLEntry[i] != otherCRLEntry[i])
  68. return false;
  69. } catch (CRLException ce) {
  70. return false;
  71. }
  72. return true;
  73. }
  74. /**
  75. * Returns a hashcode value for this CRL entry from its
  76. * encoded form.
  77. *
  78. * @return the hashcode value.
  79. */
  80. public int hashCode() {
  81. int retval = 0;
  82. try {
  83. byte[] entryData = this.getEncoded();
  84. for (int i = 1; i < entryData.length; i++)
  85. retval += entryData[i] * i;
  86. } catch (CRLException ce) {
  87. return(retval);
  88. }
  89. return(retval);
  90. }
  91. /**
  92. * Returns the ASN.1 DER-encoded form of this CRL Entry,
  93. * that is the inner SEQUENCE.
  94. *
  95. * @return the encoded form of this certificate
  96. * @exception CRLException if an encoding error occurs.
  97. */
  98. public abstract byte[] getEncoded() throws CRLException;
  99. /**
  100. * Gets the serial number from this X509CRLEntry,
  101. * the <em>userCertificate</em>.
  102. *
  103. * @return the serial number.
  104. */
  105. public abstract BigInteger getSerialNumber();
  106. /**
  107. * Gets the revocation date from this X509CRLEntry,
  108. * the <em>revocationDate</em>.
  109. *
  110. * @return the revocation date.
  111. */
  112. public abstract Date getRevocationDate();
  113. /**
  114. * Returns true if this CRL entry has extensions.
  115. *
  116. * @return true if this entry has extensions, false otherwise.
  117. */
  118. public abstract boolean hasExtensions();
  119. /**
  120. * Returns a string representation of this CRL entry.
  121. *
  122. * @return a string representation of this CRL entry.
  123. */
  124. public abstract String toString();
  125. }