Record Class KeyExpirationWarning

java.lang.Object
java.lang.Record
co.ankatech.ankasecure.sdk.model.warning.KeyExpirationWarning
Record Components:
daysRemaining - number of days until key expires (must be positive)
All Implemented Interfaces:
CryptoWarning

public record KeyExpirationWarning(int daysRemaining) extends Record implements CryptoWarning
Warning indicating that a cryptographic key is approaching expiration.

Severity automatically escalates based on days remaining, allowing applications to implement tiered response strategies (alerting, automated rotation, etc.).

Severity escalation thresholds:

  • CRITICAL - 7 days or less (immediate action required)
  • WARNING - 8-14 days (plan rotation this week)
  • NOTICE - 15-30 days (schedule rotation soon)
  • INFO - More than 30 days (awareness only)

Example - Severity-based handling:


 for (CryptoWarning w : result.getWarnings()) {
     if (w instanceof KeyExpirationWarning kew) {
         switch (kew.severity()) {
             case CRITICAL -> {
                 logger.error("URGENT: {}", kew.message());
                 triggerEmergencyRotation(result.getKeyRequested());
             }
             case WARNING ->
                 scheduleRotationThisWeek(kew.daysRemaining());
             case NOTICE ->
                 planRotation(kew.daysRemaining());
             case INFO ->
                 logger.info("{}", kew.message());
         }
     }
 }
 

Example - Pattern matching with guard:


 switch (warning) {
     case KeyExpirationWarning kew when kew.daysRemaining() <= 3 ->
         sendPagerDutyAlert("Key expires in " + kew.daysRemaining() + " days!");
     case KeyExpirationWarning kew ->
         logger.warn("{} - {}", kew.message(), kew.recommendedAction());
 }
 
Since:
3.0.0
See Also:
  • Constructor Details

    • KeyExpirationWarning

      public KeyExpirationWarning(int daysRemaining)
      Creates an instance of a KeyExpirationWarning record class.
      Parameters:
      daysRemaining - the value for the daysRemaining record component
  • Method Details

    • severity

      public WarningSeverity severity()
      Description copied from interface: CryptoWarning
      Returns the severity level of this warning.
      Specified by:
      severity in interface CryptoWarning
      Returns:
      warning severity (INFO, NOTICE, WARNING, or CRITICAL)
    • message

      public String message()
      Description copied from interface: CryptoWarning
      Returns a human-readable warning message.
      Specified by:
      message in interface CryptoWarning
      Returns:
      descriptive message
    • recommendedAction

      public String recommendedAction()
      Description copied from interface: CryptoWarning
      Returns the recommended action to address this warning.
      Specified by:
      recommendedAction in interface CryptoWarning
      Returns:
      actionable guidance for the user
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • daysRemaining

      public int daysRemaining()
      Returns the value of the daysRemaining record component.
      Returns:
      the value of the daysRemaining record component