41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
/// CCC Key-Derivation Function (KDF) definitions and helpers.
|
|
///
|
|
/// This module owns:
|
|
/// - stable int-backed KDF identifiers for persistence,
|
|
/// - normalization/parsing helpers,
|
|
/// - conversion from persisted int to enum.
|
|
///
|
|
/// Keeping this in `ccc/` preserves separation of concerns so data models remain
|
|
/// focused on storage shape only.
|
|
enum CccKdfFunction {
|
|
sha256(1),
|
|
sha384(2),
|
|
sha512(3),
|
|
blake2b512(4);
|
|
|
|
final int value;
|
|
const CccKdfFunction(this.value);
|
|
}
|
|
|
|
/// Default persisted KDF selector.
|
|
const int cccDefaultKdfFunctionValue = 1;
|
|
|
|
/// Normalize arbitrary input to a supported KDF function int value.
|
|
int normalizeCccKdfFunctionValue(dynamic raw) {
|
|
final parsed = raw is int ? raw : int.tryParse(raw?.toString() ?? '');
|
|
if (parsed == null) return cccDefaultKdfFunctionValue;
|
|
|
|
for (final option in CccKdfFunction.values) {
|
|
if (option.value == parsed) return parsed;
|
|
}
|
|
return cccDefaultKdfFunctionValue;
|
|
}
|
|
|
|
/// Resolve an enum value from persisted int representation.
|
|
CccKdfFunction cccKdfFunctionFromInt(int raw) {
|
|
for (final option in CccKdfFunction.values) {
|
|
if (option.value == raw) return option;
|
|
}
|
|
return CccKdfFunction.sha256;
|
|
}
|