69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
/// Self-test result — wraps the FRB-generated report into Dart-idiomatic types.
|
|
library;
|
|
|
|
import 'package:ccc_cryptography/src/rust/api/dto.dart';
|
|
|
|
/// Result of a single algorithm's self-test.
|
|
class CccAlgorithmTestResult {
|
|
/// Numeric algorithm identifier.
|
|
final int algoId;
|
|
|
|
/// Human-readable algorithm name.
|
|
final String algoName;
|
|
|
|
/// Whether the algorithm passed its self-test.
|
|
final bool passed;
|
|
|
|
/// Diagnostic message if the test failed; `null` on success.
|
|
final String? errorMessage;
|
|
|
|
const CccAlgorithmTestResult({
|
|
required this.algoId,
|
|
required this.algoName,
|
|
required this.passed,
|
|
this.errorMessage,
|
|
});
|
|
|
|
factory CccAlgorithmTestResult._fromDto(CccAlgoTestResult dto) {
|
|
return CccAlgorithmTestResult(
|
|
algoId: dto.algoId,
|
|
algoName: dto.algoName,
|
|
passed: dto.passed,
|
|
errorMessage: dto.errorMessage,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Aggregate result of the provider self-test.
|
|
class CccSelfTestResult {
|
|
/// Name of the provider that was tested.
|
|
final String providerName;
|
|
|
|
/// Per-algorithm test results.
|
|
final List<CccAlgorithmTestResult> results;
|
|
|
|
/// Whether all algorithms passed.
|
|
final bool allPassed;
|
|
|
|
const CccSelfTestResult._({
|
|
required this.providerName,
|
|
required this.results,
|
|
required this.allPassed,
|
|
});
|
|
|
|
/// Convert from the FRB-generated self-test report DTO.
|
|
factory CccSelfTestResult.fromReport(CccSelfTestReport report) {
|
|
return CccSelfTestResult._(
|
|
providerName: report.providerName,
|
|
results: report.results
|
|
.map(CccAlgorithmTestResult._fromDto)
|
|
.toList(growable: false),
|
|
allPassed: report.allPassed,
|
|
);
|
|
}
|
|
|
|
/// Algorithms that failed their self-test.
|
|
List<CccAlgorithmTestResult> get failures =>
|
|
results.where((r) => !r.passed).toList(growable: false);
|
|
}
|