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