Package co.ankatech.ankasecure.sdk.model.warning
package co.ankatech.ankasecure.sdk.model.warning
Structured warning types for cryptographic operations.
This package provides a type-safe alternative to string-based warnings, enabling compile-time safety and pattern matching for warning handling.
Overview
All cryptographic operation results (EncryptResult,
SignResult, etc.) return warnings as
List<CryptoWarning> instead of List<String>.
Core Types
CryptoWarning- Sealed interface (all warnings implement this)WarningSeverity- Severity levels (INFO, NOTICE, WARNING, CRITICAL)KeyExpirationWarning- Key approaching expirationUsageLimitWarning- Key approaching usage limitsGenericWarning- Fallback for unknown formats
Usage Example
import co.ankatech.ankasecure.sdk.model.warning.*;
EncryptResult result = sdk.encrypt("my-key", data);
for (CryptoWarning warning : result.getWarnings()) {
// Pattern matching with type safety
switch (warning) {
case KeyExpirationWarning kew when kew.severity() == WarningSeverity.CRITICAL -> {
System.err.println("URGENT: " + kew.message());
System.err.println("Action: " + kew.recommendedAction());
triggerRotation();
}
case KeyExpirationWarning kew ->
scheduleRotation(kew.daysRemaining());
case UsageLimitWarning ulw when ulw.invocationsRemaining() <= 100 ->
emergencyRotation();
case UsageLimitWarning ulw ->
logger.warn(ulw.message());
case GenericWarning gw ->
logger.info(gw.rawMessage());
}
}
Severity-Based Filtering
// Find all critical warnings
List<CryptoWarning> critical = result.getWarnings().stream()
.filter(w -> w.severity() == WarningSeverity.CRITICAL)
.toList();
if (!critical.isEmpty()) {
notifySecurityTeam(critical);
}
Migration from String Warnings (SDK 2.x → 3.0)
| SDK 2.x (deprecated) | SDK 3.0 (current) |
|---|---|
List<String> warnings = result.getWarnings(); |
List<CryptoWarning> warnings = result.getWarnings(); |
if (w.contains("expires")) ... |
if (w instanceof KeyExpirationWarning kew) ... |
warnings.forEach(System.out::println); |
warnings.forEach(w -> System.out.println(w.message())); |
Thread Safety
All warning types are immutable records, safe to share across threads. Warning lists returned by SDK are unmodifiable collections.
- Since:
- 3.0.0
-
ClassDescriptionRepresents a structured cryptographic operation warning.Generic warning for messages that don't match known patterns.Warning indicating that a cryptographic key is approaching expiration.Warning indicating that a cryptographic key is approaching its usage limit.Severity levels for cryptographic warnings.