/// Structured exception classes for CCC cryptographic operations. /// /// These wrap the FRB-generated [CccCryptoError] into typed Dart exceptions /// so consuming code can catch specific failure modes. library; import 'package:ccc_cryptography/src/rust/api/dto.dart'; /// Base class for all CCC cryptographic exceptions. sealed class CccException implements Exception { /// Human-readable error description. final String message; const CccException(this.message); @override String toString() => '$runtimeType: $message'; /// Convert a FRB-generated [CccCryptoError] into the appropriate /// typed [CccException] subclass. factory CccException.from(CccCryptoError error) { return switch (error) { CccCryptoError_UnsupportedAlgorithm(:final field0) => CccUnsupportedAlgorithm(field0), CccCryptoError_InvalidKey(:final field0) => CccInvalidKey(field0), CccCryptoError_InvalidNonce(:final field0) => CccInvalidNonce(field0), CccCryptoError_AuthenticationFailed() => const CccAuthenticationFailed(), CccCryptoError_InvalidInput(:final field0) => CccInvalidInput(field0), CccCryptoError_FeatureNotCompiled(:final field0) => CccFeatureNotCompiled(field0), CccCryptoError_InternalError(:final field0) => CccInternalError(field0), }; } } /// The requested algorithm is not supported by any registered provider. class CccUnsupportedAlgorithm extends CccException { const CccUnsupportedAlgorithm(super.message); } /// The supplied key is invalid (wrong length, weak key, etc.). class CccInvalidKey extends CccException { const CccInvalidKey(super.message); } /// The supplied nonce/IV is invalid (wrong length, reuse detected, etc.). class CccInvalidNonce extends CccException { const CccInvalidNonce(super.message); } /// AEAD authentication tag verification failed — ciphertext was tampered. class CccAuthenticationFailed extends CccException { const CccAuthenticationFailed() : super('authentication failed'); } /// The supplied input data is invalid. class CccInvalidInput extends CccException { const CccInvalidInput(super.message); } /// The requested feature/algorithm is not compiled into the provider. class CccFeatureNotCompiled extends CccException { const CccFeatureNotCompiled(super.message); } /// An unexpected internal error occurred in the cryptographic provider. class CccInternalError extends CccException { const CccInternalError(super.message); }