Interface CryptoWarning

All Known Implementing Classes:
GenericWarning, KeyExpirationWarning, UsageLimitWarning

public sealed interface CryptoWarning permits KeyExpirationWarning, UsageLimitWarning, GenericWarning
Represents a structured cryptographic operation warning.

Warnings are categorized by type and severity, allowing clients to programmatically handle different warning scenarios (key expiration, usage limits, etc.) instead of parsing string messages. This sealed interface ensures type safety and enables exhaustive pattern matching.

Basic usage with pattern matching:


 EncryptResult result = sdk.encrypt("my-key", data);

 if (result.getWarnings() != null) {
     for (CryptoWarning warning : result.getWarnings()) {
         switch (warning) {
             case KeyExpirationWarning kew when kew.severity() == WarningSeverity.CRITICAL ->
                 handleCriticalExpiration(kew.daysRemaining());
             case KeyExpirationWarning kew ->
                 scheduleRotation(kew.daysRemaining());
             case UsageLimitWarning ulw when ulw.invocationsRemaining() <= 100 ->
                 emergencyKeyRotation();
             case UsageLimitWarning ulw ->
                 logger.warn("{} - {}", ulw.message(), ulw.recommendedAction());
             case GenericWarning gw ->
                 logger.info("Server warning: {}", gw.rawMessage());
         }
     }
 }
 

Severity-based filtering:


 boolean hasCriticalWarnings = result.getWarnings().stream()
     .anyMatch(w -> w.severity() == WarningSeverity.CRITICAL);

 if (hasCriticalWarnings) {
     notifySecurityTeam(result.getWarnings());
 }
 

Implementations:

Since:
3.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a human-readable warning message.
    Returns the recommended action to address this warning.
    Returns the severity level of this warning.
  • Method Details

    • severity

      WarningSeverity severity()
      Returns the severity level of this warning.
      Returns:
      warning severity (INFO, NOTICE, WARNING, or CRITICAL)
    • message

      String message()
      Returns a human-readable warning message.
      Returns:
      descriptive message
    • recommendedAction

      String recommendedAction()
      Returns the recommended action to address this warning.
      Returns:
      actionable guidance for the user