lum_ccc_fplugin/lib/ccc_provider_catalog.dart

111 lines
3.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// Provider catalog — describes what a registered provider supports.
///
/// Wraps the FRB-generated [CccCapabilities] into a Dart-idiomatic type
/// for querying algorithm availability and quality scores.
library;
import 'package:ccc_cryptography/src/rust/api/dto.dart';
/// Describes the full set of capabilities for a registered provider.
class CccProviderCatalog {
/// Provider name (e.g. "wolfssl").
final String providerName;
/// AEAD algorithms supported by this provider.
final List<CccAlgorithmInfo> aead;
/// KDF algorithms supported by this provider.
final List<CccAlgorithmInfo> kdf;
/// MAC algorithms supported by this provider.
final List<CccAlgorithmInfo> mac;
/// Hash algorithms supported by this provider.
final List<CccAlgorithmInfo> hash;
/// KEM algorithms supported by this provider.
final List<CccAlgorithmInfo> kem;
const CccProviderCatalog._({
required this.providerName,
required this.aead,
required this.kdf,
required this.mac,
required this.hash,
required this.kem,
});
/// Convert from the FRB-generated capabilities DTO.
factory CccProviderCatalog.fromCapabilities(CccCapabilities caps) {
return CccProviderCatalog._(
providerName: caps.providerName,
aead: caps.aead.map(CccAlgorithmInfo._fromEntry).toList(growable: false),
kdf: caps.kdf.map(CccAlgorithmInfo._fromEntry).toList(growable: false),
mac: caps.mac.map(CccAlgorithmInfo._fromEntry).toList(growable: false),
hash: caps.hash.map(CccAlgorithmInfo._fromEntry).toList(growable: false),
kem: caps.kem.map(CccAlgorithmInfo._fromEntry).toList(growable: false),
);
}
/// All available AEAD algorithms.
List<CccAlgorithmInfo> get availableAead =>
aead.where((a) => a.available).toList(growable: false);
/// All available KDF algorithms.
List<CccAlgorithmInfo> get availableKdf =>
kdf.where((a) => a.available).toList(growable: false);
/// All available MAC algorithms.
List<CccAlgorithmInfo> get availableMac =>
mac.where((a) => a.available).toList(growable: false);
/// All available Hash algorithms.
List<CccAlgorithmInfo> get availableHash =>
hash.where((a) => a.available).toList(growable: false);
/// All available KEM algorithms.
List<CccAlgorithmInfo> get availableKem =>
kem.where((a) => a.available).toList(growable: false);
}
/// Describes a single algorithm's availability and quality metrics.
class CccAlgorithmInfo {
/// Numeric algorithm identifier (matches Rust `#[repr(u32)]`).
final int id;
/// Human-readable algorithm name (e.g. "AES-256-GCM").
final String name;
/// Whether this algorithm is available in the provider.
final bool available;
/// Whether the algorithm produces deterministic output for the same input.
final bool deterministicIo;
/// Provider-reported efficiency score (0100).
final int efficiencyScore;
/// Provider-reported reliability score (0100).
final int reliabilityScore;
const CccAlgorithmInfo({
required this.id,
required this.name,
required this.available,
required this.deterministicIo,
required this.efficiencyScore,
required this.reliabilityScore,
});
factory CccAlgorithmInfo._fromEntry(CccAlgorithmEntry e) {
return CccAlgorithmInfo(
id: e.algoId,
name: e.algoName,
available: e.capability.available,
deterministicIo: e.capability.deterministicIo,
efficiencyScore: e.capability.efficiencyScore,
reliabilityScore: e.capability.reliabilityScore,
);
}
}