NEW: added bridge API and DTO for dart

This commit is contained in:
JohnE 2026-03-11 16:57:28 -07:00
parent a129711e4d
commit b79878a0b5
12 changed files with 5442 additions and 141 deletions

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"chat.tools.terminal.autoApprove": {
"cargo check": true,
"flutter_rust_bridge_codegen": true
}
}

View File

@ -39,7 +39,7 @@ Phase Overview
Phase Title Status Depends on
====== ========================================== ========== ============
1 Project Restructure & FRB Setup Done —
2 Rust Bridge Crate (DTOs + API) Not Started Phase 1
2 Rust Bridge Crate (DTOs + API) Done Phase 1
3 Dart API Surface Not Started Phase 2
4 Platform Build Verification Not Started Phase 3
5 Unit Tests Not Started Phase 3
@ -115,7 +115,7 @@ Exit Criteria
Phase 2 — Rust Bridge Crate (DTOs + API)
------------------------------------------
:Status: Not Started
:Status: Done
:Depends on: Phase 1
**Goal:** Implement DTOs and thin Rust wrappers in the bridge crate that
@ -124,8 +124,13 @@ expose all ``ccc_rust`` provider functionality across the FRB bridge.
The bridge crate lives at ``rust/`` and must not contain any cryptographic
logic — only type conversions and delegation to ``ccc_rust`` providers.
DTOs (``rust/src/dto.rs``)
~~~~~~~~~~~~~~~~~~~~~~~~~~
Files created:
* ``rust/src/api/dto.rs`` — DTOs, algorithm enums, bridge error type
* ``rust/src/api/crypto.rs`` — 13 bridge entry-point functions
DTOs (``rust/src/api/dto.rs``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bridge-visible data transfer objects with ``From<core type>`` impls:
@ -137,29 +142,29 @@ Bridge-visible data transfer objects with ``From<core type>`` impls:
- Task
- Status
* - 2.1
- ``CapabilitiesDto`` — maps from ``ProviderCapabilities``
(provider name, algorithm availability, efficiency/reliability
scores)
-
- ``CccCapabilities`` — maps from ``ProviderCapabilities``
(provider name, per-category algorithm list with availability,
efficiency/reliability scores); flattened HashMap → Vec for FRB
-
* - 2.2
- ``KemKeyPairDto`` — maps from ``KemKeyPair``
- ``CccKemKeyPair`` — maps from ``KemKeyPair``
(public_key, private_key as ``Vec<u8>``)
-
-
* - 2.3
- ``KemEncapDto`` — maps from KEM encapsulation result
- ``CccKemEncapResult`` — maps from ``KemEncapResult``
(ciphertext, shared_secret)
-
-
* - 2.4
- ``SelfTestDto`` — maps from ``SelfTestReport``
- ``CccSelfTestReport`` — maps from ``SelfTestReport``
(overall pass/fail, per-algorithm results)
-
-
* - 2.5
- ``AlgoTestResultDto`` — maps from ``AlgoTestResult``
- ``CccAlgoTestResult`` — maps from ``AlgoTestResult``
(algorithm ID, pass/fail, diagnostic message)
-
-
Bridge API (``rust/src/api.rs``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bridge API (``rust/src/api/crypto.rs``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. list-table::
:header-rows: 1
@ -169,86 +174,93 @@ Bridge API (``rust/src/api.rs``)
- Task
- Status
* - 2.6
- ``ccc_init()`` — register WolfSslProvider, run capability probe
-
- ``ccc_init()`` — register WolfSslProvider (idempotent)
-
* - 2.7
- ``ccc_list_providers()`` — return registered provider names
-
- ``ccc_list_providers()`` — return registered provider names (sync)
-
* - 2.8
- ``ccc_capabilities()`` / ``ccc_available_algorithms()``
— return ``CapabilitiesDto`` for a provider
- ☐
- ``ccc_capabilities()`` — return ``CccCapabilities`` for default provider
- ✅
* - 2.9
- ``ccc_aead_encrypt(algorithm, key, nonce, plaintext, aad)``
— thin wrapper over provider AEAD encrypt
-
-
* - 2.10
- ``ccc_aead_decrypt(algorithm, key, nonce, ciphertext, aad)``
— thin wrapper over provider AEAD decrypt
-
-
* - 2.11
- ``ccc_kdf_derive(algorithm, ikm, salt, info, len)``
— thin wrapper over provider KDF
-
-
* - 2.12
- ``ccc_mac_compute(algorithm, key, data)``
— thin wrapper over provider MAC compute
-
-
* - 2.13
- ``ccc_mac_verify(algorithm, key, data, mac)``
— thin wrapper over provider MAC verify
-
-
* - 2.14
- ``ccc_hash(algorithm, data)``
— thin wrapper over provider hash
-
-
* - 2.15
- ``ccc_kem_generate_keypair(algorithm)``
— return ``KemKeyPairDto``
-
— return ``CccKemKeyPair``
-
* - 2.16
- ``ccc_kem_encapsulate(algorithm, public_key)``
— return ``KemEncapDto``
-
— return ``CccKemEncapResult``
-
* - 2.17
- ``ccc_kem_decapsulate(algorithm, private_key, ciphertext)``
— return shared secret
-
-
* - 2.18
- ``ccc_self_test()`` — return ``SelfTestDto``
-
- ``ccc_self_test()`` — return ``CccSelfTestReport``
-
* - 2.19
- Define bridge-visible error enum mapping ``CryptoError``
variants to structured types (``UnsupportedAlgorithm``,
``InvalidKey``, ``InvalidNonce``, ``AuthenticationFailed``,
- ``CccCryptoError`` enum mapping all 7 ``CryptoError`` variants
(``UnsupportedAlgorithm``, ``InvalidKey``, ``InvalidNonce``,
``AuthenticationFailed``, ``InvalidInput``, ``FeatureNotCompiled``,
``InternalError``)
-
-
* - 2.20
- Run ``flutter_rust_bridge_codegen generate``verify all
wrappers produce valid Dart bindings
-
- Run ``flutter_rust_bridge_codegen generate``Dart bindings
generated; ``flutter build macos`` succeeds (44.5 MB)
-
DTO ↔ Rust Type Mapping
~~~~~~~~~~~~~~~~~~~~~~~~
======================== =================================== ========================
Bridge DTO Rust Core Type Direction
======================== =================================== ========================
``CapabilitiesDto`` ``ProviderCapabilities`` Rust → Dart
``KemKeyPairDto`` ``KemKeyPair`` Rust → Dart
``KemEncapDto`` (ciphertext, shared_secret) Rust → Dart
``SelfTestDto`` ``SelfTestReport`` Rust → Dart
``AlgoTestResultDto`` ``AlgoTestResult`` Rust → Dart
``CryptoError`` enum ``CryptoError`` Rust → Dart exception
======================== =================================== ========================
========================== =================================== ========================
Bridge DTO Rust Core Type Direction
========================== =================================== ========================
``CccCapabilities`` ``ProviderCapabilities`` Rust → Dart
``CccAlgorithmEntry`` (algo_id, name, capability) Rust → Dart
``CccAlgorithmCapability`` ``AlgorithmCapability`` Rust → Dart
``CccKemKeyPair`` ``KemKeyPair`` Rust → Dart
``CccKemEncapResult`` ``KemEncapResult`` Rust → Dart
``CccSelfTestReport`` ``SelfTestReport`` Rust → Dart
``CccAlgoTestResult`` ``AlgoTestResult`` Rust → Dart
``CccCryptoError`` enum ``CryptoError`` Rust → Dart exception
``CccAeadAlgorithm`` ``AeadAlgorithm`` Dart → Rust
``CccKdfAlgorithm`` ``KdfAlgorithm`` Dart → Rust
``CccMacAlgorithm`` ``MacAlgorithm`` Dart → Rust
``CccHashAlgorithm`` ``HashAlgorithm`` Dart → Rust
``CccKemAlgorithm`` ``KemAlgorithm`` Dart → Rust
========================== =================================== ========================
Exit Criteria
~~~~~~~~~~~~~
* All DTOs defined with ``From<>`` impls.
* All 13 bridge entry points exist in ``api.rs``.
* Codegen produces Dart bindings without warnings.
* Rust crate compiles with ``ccc_rust`` linked.
* ✅ All DTOs defined with ``From<>`` impls.
* ✅ All 13 bridge entry points exist in ``crypto.rs``.
* ✅ Codegen produces Dart bindings (+ freezed).
* ✅ Rust crate compiles with ``ccc_rust`` linked.
* ✅ ``flutter build macos`` succeeds (44.5 MB).
----

View File

@ -0,0 +1,137 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.11.1.
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
import '../frb_generated.dart';
import 'dto.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
// These functions are ignored because they are not marked as `pub`: `default_provider`, `kem_provider`
/// Initialise the CCC cryptographic subsystem.
///
/// Registers the wolfSSL provider in the global registry.
/// Safe to call multiple times (idempotent).
Future<void> cccInit() => RustLib.instance.api.crateApiCryptoCccInit();
/// List all registered provider names.
List<String> cccListProviders() =>
RustLib.instance.api.crateApiCryptoCccListProviders();
/// Return the capabilities of the default provider.
Future<CccCapabilities> cccCapabilities() =>
RustLib.instance.api.crateApiCryptoCccCapabilities();
/// Encrypt with an AEAD algorithm.
///
/// Returns ciphertexttag.
Future<Uint8List> cccAeadEncrypt({
required CccAeadAlgorithm algorithm,
required List<int> key,
required List<int> nonce,
required List<int> plaintext,
required List<int> aad,
}) => RustLib.instance.api.crateApiCryptoCccAeadEncrypt(
algorithm: algorithm,
key: key,
nonce: nonce,
plaintext: plaintext,
aad: aad,
);
/// Decrypt with an AEAD algorithm.
///
/// Expects ciphertexttag as `ciphertext`.
Future<Uint8List> cccAeadDecrypt({
required CccAeadAlgorithm algorithm,
required List<int> key,
required List<int> nonce,
required List<int> ciphertext,
required List<int> aad,
}) => RustLib.instance.api.crateApiCryptoCccAeadDecrypt(
algorithm: algorithm,
key: key,
nonce: nonce,
ciphertext: ciphertext,
aad: aad,
);
/// Derive key material using a KDF.
Future<Uint8List> cccKdfDerive({
required CccKdfAlgorithm algorithm,
required List<int> ikm,
required List<int> salt,
required List<int> info,
required int length,
}) => RustLib.instance.api.crateApiCryptoCccKdfDerive(
algorithm: algorithm,
ikm: ikm,
salt: salt,
info: info,
length: length,
);
/// Compute a MAC tag.
Future<Uint8List> cccMacCompute({
required CccMacAlgorithm algorithm,
required List<int> key,
required List<int> data,
}) => RustLib.instance.api.crateApiCryptoCccMacCompute(
algorithm: algorithm,
key: key,
data: data,
);
/// Verify a MAC tag. Returns `true` if valid.
Future<bool> cccMacVerify({
required CccMacAlgorithm algorithm,
required List<int> key,
required List<int> data,
required List<int> mac,
}) => RustLib.instance.api.crateApiCryptoCccMacVerify(
algorithm: algorithm,
key: key,
data: data,
mac: mac,
);
/// Compute a cryptographic hash.
Future<Uint8List> cccHash({
required CccHashAlgorithm algorithm,
required List<int> data,
}) => RustLib.instance.api.crateApiCryptoCccHash(
algorithm: algorithm,
data: data,
);
/// Generate a KEM key pair.
Future<CccKemKeyPair> cccKemGenerateKeypair({
required CccKemAlgorithm algorithm,
}) => RustLib.instance.api.crateApiCryptoCccKemGenerateKeypair(
algorithm: algorithm,
);
/// KEM encapsulation produce ciphertext + shared secret from a public key.
Future<CccKemEncapResult> cccKemEncapsulate({
required CccKemAlgorithm algorithm,
required List<int> publicKey,
}) => RustLib.instance.api.crateApiCryptoCccKemEncapsulate(
algorithm: algorithm,
publicKey: publicKey,
);
/// KEM decapsulation recover shared secret from ciphertext + private key.
Future<Uint8List> cccKemDecapsulate({
required CccKemAlgorithm algorithm,
required List<int> privateKey,
required List<int> ciphertext,
}) => RustLib.instance.api.crateApiCryptoCccKemDecapsulate(
algorithm: algorithm,
privateKey: privateKey,
ciphertext: ciphertext,
);
/// Run the provider self-test and return a structured report.
Future<CccSelfTestReport> cccSelfTest() =>
RustLib.instance.api.crateApiCryptoCccSelfTest();

260
lib/src/rust/api/dto.dart Normal file
View File

@ -0,0 +1,260 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.11.1.
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
part 'dto.freezed.dart';
// These functions are ignored because they are not marked as `pub`: `to_core`, `to_core`, `to_core`, `to_core`, `to_core`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `fmt`, `fmt`, `from`, `from`, `from`, `from`, `from`, `from`, `from`
/// AEAD algorithm identifiers values match `ccc_rust` `#[repr(u32)]`.
enum CccAeadAlgorithm {
aesGcm256,
chaCha20Poly1305,
xChaCha20Poly1305,
ascon128A,
}
/// Per-algorithm self-test result.
class CccAlgoTestResult {
final int algoId;
final String algoName;
final bool passed;
final String? errorMessage;
const CccAlgoTestResult({
required this.algoId,
required this.algoName,
required this.passed,
this.errorMessage,
});
@override
int get hashCode =>
algoId.hashCode ^
algoName.hashCode ^
passed.hashCode ^
errorMessage.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccAlgoTestResult &&
runtimeType == other.runtimeType &&
algoId == other.algoId &&
algoName == other.algoName &&
passed == other.passed &&
errorMessage == other.errorMessage;
}
/// Per-algorithm availability and quality scores.
class CccAlgorithmCapability {
final bool available;
final bool deterministicIo;
final int efficiencyScore;
final int reliabilityScore;
const CccAlgorithmCapability({
required this.available,
required this.deterministicIo,
required this.efficiencyScore,
required this.reliabilityScore,
});
@override
int get hashCode =>
available.hashCode ^
deterministicIo.hashCode ^
efficiencyScore.hashCode ^
reliabilityScore.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccAlgorithmCapability &&
runtimeType == other.runtimeType &&
available == other.available &&
deterministicIo == other.deterministicIo &&
efficiencyScore == other.efficiencyScore &&
reliabilityScore == other.reliabilityScore;
}
/// An algorithm entry in the capabilities list.
class CccAlgorithmEntry {
final int algoId;
final String algoName;
final CccAlgorithmCapability capability;
const CccAlgorithmEntry({
required this.algoId,
required this.algoName,
required this.capability,
});
@override
int get hashCode => algoId.hashCode ^ algoName.hashCode ^ capability.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccAlgorithmEntry &&
runtimeType == other.runtimeType &&
algoId == other.algoId &&
algoName == other.algoName &&
capability == other.capability;
}
/// Provider capabilities flattened from HashMap to Vec for FRB.
class CccCapabilities {
final String providerName;
final List<CccAlgorithmEntry> aead;
final List<CccAlgorithmEntry> kdf;
final List<CccAlgorithmEntry> mac;
final List<CccAlgorithmEntry> hash;
final List<CccAlgorithmEntry> kem;
const CccCapabilities({
required this.providerName,
required this.aead,
required this.kdf,
required this.mac,
required this.hash,
required this.kem,
});
@override
int get hashCode =>
providerName.hashCode ^
aead.hashCode ^
kdf.hashCode ^
mac.hashCode ^
hash.hashCode ^
kem.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccCapabilities &&
runtimeType == other.runtimeType &&
providerName == other.providerName &&
aead == other.aead &&
kdf == other.kdf &&
mac == other.mac &&
hash == other.hash &&
kem == other.kem;
}
@freezed
sealed class CccCryptoError with _$CccCryptoError implements FrbException {
const CccCryptoError._();
const factory CccCryptoError.unsupportedAlgorithm(String field0) =
CccCryptoError_UnsupportedAlgorithm;
const factory CccCryptoError.invalidKey(String field0) =
CccCryptoError_InvalidKey;
const factory CccCryptoError.invalidNonce(String field0) =
CccCryptoError_InvalidNonce;
const factory CccCryptoError.authenticationFailed() =
CccCryptoError_AuthenticationFailed;
const factory CccCryptoError.invalidInput(String field0) =
CccCryptoError_InvalidInput;
const factory CccCryptoError.featureNotCompiled(String field0) =
CccCryptoError_FeatureNotCompiled;
const factory CccCryptoError.internalError(String field0) =
CccCryptoError_InternalError;
}
/// Hash algorithm identifiers.
enum CccHashAlgorithm { sha256, sha384, sha512, blake2B512, sha3256, sha3512 }
/// KDF algorithm identifiers.
enum CccKdfAlgorithm { sha256, sha384, sha512, blake2B512, argon2Id, kmac256 }
/// KEM algorithm identifiers.
enum CccKemAlgorithm {
x25519,
x448,
mlKem768,
mlKem1024,
classicMcEliece460896,
}
/// KEM encapsulation result ciphertext + shared secret.
class CccKemEncapResult {
final Uint8List ciphertext;
final Uint8List sharedSecret;
const CccKemEncapResult({
required this.ciphertext,
required this.sharedSecret,
});
@override
int get hashCode => ciphertext.hashCode ^ sharedSecret.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccKemEncapResult &&
runtimeType == other.runtimeType &&
ciphertext == other.ciphertext &&
sharedSecret == other.sharedSecret;
}
/// KEM key pair public + private key bytes.
class CccKemKeyPair {
final Uint8List publicKey;
final Uint8List privateKey;
const CccKemKeyPair({required this.publicKey, required this.privateKey});
@override
int get hashCode => publicKey.hashCode ^ privateKey.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccKemKeyPair &&
runtimeType == other.runtimeType &&
publicKey == other.publicKey &&
privateKey == other.privateKey;
}
/// MAC algorithm identifiers.
enum CccMacAlgorithm {
hmacSha256,
hmacSha384,
hmacSha512,
blake2BMac,
poly1305,
}
/// Aggregate self-test report.
class CccSelfTestReport {
final String providerName;
final List<CccAlgoTestResult> results;
final bool allPassed;
const CccSelfTestReport({
required this.providerName,
required this.results,
required this.allPassed,
});
@override
int get hashCode =>
providerName.hashCode ^ results.hashCode ^ allPassed.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CccSelfTestReport &&
runtimeType == other.runtimeType &&
providerName == other.providerName &&
results == other.results &&
allPassed == other.allPassed;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,8 @@
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
import 'api/crypto.dart';
import 'api/dto.dart';
import 'api/simple.dart';
import 'dart:async';
import 'dart:convert';
@ -21,9 +23,72 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String dco_decode_String(dynamic raw);
@protected
bool dco_decode_bool(dynamic raw);
@protected
CccAeadAlgorithm dco_decode_ccc_aead_algorithm(dynamic raw);
@protected
CccAlgoTestResult dco_decode_ccc_algo_test_result(dynamic raw);
@protected
CccAlgorithmCapability dco_decode_ccc_algorithm_capability(dynamic raw);
@protected
CccAlgorithmEntry dco_decode_ccc_algorithm_entry(dynamic raw);
@protected
CccCapabilities dco_decode_ccc_capabilities(dynamic raw);
@protected
CccCryptoError dco_decode_ccc_crypto_error(dynamic raw);
@protected
CccHashAlgorithm dco_decode_ccc_hash_algorithm(dynamic raw);
@protected
CccKdfAlgorithm dco_decode_ccc_kdf_algorithm(dynamic raw);
@protected
CccKemAlgorithm dco_decode_ccc_kem_algorithm(dynamic raw);
@protected
CccKemEncapResult dco_decode_ccc_kem_encap_result(dynamic raw);
@protected
CccKemKeyPair dco_decode_ccc_kem_key_pair(dynamic raw);
@protected
CccMacAlgorithm dco_decode_ccc_mac_algorithm(dynamic raw);
@protected
CccSelfTestReport dco_decode_ccc_self_test_report(dynamic raw);
@protected
int dco_decode_i_32(dynamic raw);
@protected
List<String> dco_decode_list_String(dynamic raw);
@protected
List<CccAlgoTestResult> dco_decode_list_ccc_algo_test_result(dynamic raw);
@protected
List<CccAlgorithmEntry> dco_decode_list_ccc_algorithm_entry(dynamic raw);
@protected
List<int> dco_decode_list_prim_u_8_loose(dynamic raw);
@protected
Uint8List dco_decode_list_prim_u_8_strict(dynamic raw);
@protected
String? dco_decode_opt_String(dynamic raw);
@protected
int dco_decode_u_32(dynamic raw);
@protected
int dco_decode_u_8(dynamic raw);
@ -33,41 +98,214 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String sse_decode_String(SseDeserializer deserializer);
@protected
bool sse_decode_bool(SseDeserializer deserializer);
@protected
CccAeadAlgorithm sse_decode_ccc_aead_algorithm(SseDeserializer deserializer);
@protected
CccAlgoTestResult sse_decode_ccc_algo_test_result(
SseDeserializer deserializer,
);
@protected
CccAlgorithmCapability sse_decode_ccc_algorithm_capability(
SseDeserializer deserializer,
);
@protected
CccAlgorithmEntry sse_decode_ccc_algorithm_entry(
SseDeserializer deserializer,
);
@protected
CccCapabilities sse_decode_ccc_capabilities(SseDeserializer deserializer);
@protected
CccCryptoError sse_decode_ccc_crypto_error(SseDeserializer deserializer);
@protected
CccHashAlgorithm sse_decode_ccc_hash_algorithm(SseDeserializer deserializer);
@protected
CccKdfAlgorithm sse_decode_ccc_kdf_algorithm(SseDeserializer deserializer);
@protected
CccKemAlgorithm sse_decode_ccc_kem_algorithm(SseDeserializer deserializer);
@protected
CccKemEncapResult sse_decode_ccc_kem_encap_result(
SseDeserializer deserializer,
);
@protected
CccKemKeyPair sse_decode_ccc_kem_key_pair(SseDeserializer deserializer);
@protected
CccMacAlgorithm sse_decode_ccc_mac_algorithm(SseDeserializer deserializer);
@protected
CccSelfTestReport sse_decode_ccc_self_test_report(
SseDeserializer deserializer,
);
@protected
int sse_decode_i_32(SseDeserializer deserializer);
@protected
List<String> sse_decode_list_String(SseDeserializer deserializer);
@protected
List<CccAlgoTestResult> sse_decode_list_ccc_algo_test_result(
SseDeserializer deserializer,
);
@protected
List<CccAlgorithmEntry> sse_decode_list_ccc_algorithm_entry(
SseDeserializer deserializer,
);
@protected
List<int> sse_decode_list_prim_u_8_loose(SseDeserializer deserializer);
@protected
Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer);
@protected
String? sse_decode_opt_String(SseDeserializer deserializer);
@protected
int sse_decode_u_32(SseDeserializer deserializer);
@protected
int sse_decode_u_8(SseDeserializer deserializer);
@protected
void sse_decode_unit(SseDeserializer deserializer);
@protected
int sse_decode_i_32(SseDeserializer deserializer);
@protected
bool sse_decode_bool(SseDeserializer deserializer);
@protected
void sse_encode_String(String self, SseSerializer serializer);
@protected
void sse_encode_bool(bool self, SseSerializer serializer);
@protected
void sse_encode_ccc_aead_algorithm(
CccAeadAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algo_test_result(
CccAlgoTestResult self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algorithm_capability(
CccAlgorithmCapability self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algorithm_entry(
CccAlgorithmEntry self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_capabilities(
CccCapabilities self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_crypto_error(
CccCryptoError self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_hash_algorithm(
CccHashAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kdf_algorithm(
CccKdfAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_algorithm(
CccKemAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_encap_result(
CccKemEncapResult self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_key_pair(
CccKemKeyPair self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_mac_algorithm(
CccMacAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_self_test_report(
CccSelfTestReport self,
SseSerializer serializer,
);
@protected
void sse_encode_i_32(int self, SseSerializer serializer);
@protected
void sse_encode_list_String(List<String> self, SseSerializer serializer);
@protected
void sse_encode_list_ccc_algo_test_result(
List<CccAlgoTestResult> self,
SseSerializer serializer,
);
@protected
void sse_encode_list_ccc_algorithm_entry(
List<CccAlgorithmEntry> self,
SseSerializer serializer,
);
@protected
void sse_encode_list_prim_u_8_loose(List<int> self, SseSerializer serializer);
@protected
void sse_encode_list_prim_u_8_strict(
Uint8List self,
SseSerializer serializer,
);
@protected
void sse_encode_opt_String(String? self, SseSerializer serializer);
@protected
void sse_encode_u_32(int self, SseSerializer serializer);
@protected
void sse_encode_u_8(int self, SseSerializer serializer);
@protected
void sse_encode_unit(void self, SseSerializer serializer);
@protected
void sse_encode_i_32(int self, SseSerializer serializer);
@protected
void sse_encode_bool(bool self, SseSerializer serializer);
}
// Section: wire_class

View File

@ -6,6 +6,8 @@
// Static analysis wrongly picks the IO variant, thus ignore this
// ignore_for_file: argument_type_not_assignable
import 'api/crypto.dart';
import 'api/dto.dart';
import 'api/simple.dart';
import 'dart:async';
import 'dart:convert';
@ -23,9 +25,72 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String dco_decode_String(dynamic raw);
@protected
bool dco_decode_bool(dynamic raw);
@protected
CccAeadAlgorithm dco_decode_ccc_aead_algorithm(dynamic raw);
@protected
CccAlgoTestResult dco_decode_ccc_algo_test_result(dynamic raw);
@protected
CccAlgorithmCapability dco_decode_ccc_algorithm_capability(dynamic raw);
@protected
CccAlgorithmEntry dco_decode_ccc_algorithm_entry(dynamic raw);
@protected
CccCapabilities dco_decode_ccc_capabilities(dynamic raw);
@protected
CccCryptoError dco_decode_ccc_crypto_error(dynamic raw);
@protected
CccHashAlgorithm dco_decode_ccc_hash_algorithm(dynamic raw);
@protected
CccKdfAlgorithm dco_decode_ccc_kdf_algorithm(dynamic raw);
@protected
CccKemAlgorithm dco_decode_ccc_kem_algorithm(dynamic raw);
@protected
CccKemEncapResult dco_decode_ccc_kem_encap_result(dynamic raw);
@protected
CccKemKeyPair dco_decode_ccc_kem_key_pair(dynamic raw);
@protected
CccMacAlgorithm dco_decode_ccc_mac_algorithm(dynamic raw);
@protected
CccSelfTestReport dco_decode_ccc_self_test_report(dynamic raw);
@protected
int dco_decode_i_32(dynamic raw);
@protected
List<String> dco_decode_list_String(dynamic raw);
@protected
List<CccAlgoTestResult> dco_decode_list_ccc_algo_test_result(dynamic raw);
@protected
List<CccAlgorithmEntry> dco_decode_list_ccc_algorithm_entry(dynamic raw);
@protected
List<int> dco_decode_list_prim_u_8_loose(dynamic raw);
@protected
Uint8List dco_decode_list_prim_u_8_strict(dynamic raw);
@protected
String? dco_decode_opt_String(dynamic raw);
@protected
int dco_decode_u_32(dynamic raw);
@protected
int dco_decode_u_8(dynamic raw);
@ -35,41 +100,214 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String sse_decode_String(SseDeserializer deserializer);
@protected
bool sse_decode_bool(SseDeserializer deserializer);
@protected
CccAeadAlgorithm sse_decode_ccc_aead_algorithm(SseDeserializer deserializer);
@protected
CccAlgoTestResult sse_decode_ccc_algo_test_result(
SseDeserializer deserializer,
);
@protected
CccAlgorithmCapability sse_decode_ccc_algorithm_capability(
SseDeserializer deserializer,
);
@protected
CccAlgorithmEntry sse_decode_ccc_algorithm_entry(
SseDeserializer deserializer,
);
@protected
CccCapabilities sse_decode_ccc_capabilities(SseDeserializer deserializer);
@protected
CccCryptoError sse_decode_ccc_crypto_error(SseDeserializer deserializer);
@protected
CccHashAlgorithm sse_decode_ccc_hash_algorithm(SseDeserializer deserializer);
@protected
CccKdfAlgorithm sse_decode_ccc_kdf_algorithm(SseDeserializer deserializer);
@protected
CccKemAlgorithm sse_decode_ccc_kem_algorithm(SseDeserializer deserializer);
@protected
CccKemEncapResult sse_decode_ccc_kem_encap_result(
SseDeserializer deserializer,
);
@protected
CccKemKeyPair sse_decode_ccc_kem_key_pair(SseDeserializer deserializer);
@protected
CccMacAlgorithm sse_decode_ccc_mac_algorithm(SseDeserializer deserializer);
@protected
CccSelfTestReport sse_decode_ccc_self_test_report(
SseDeserializer deserializer,
);
@protected
int sse_decode_i_32(SseDeserializer deserializer);
@protected
List<String> sse_decode_list_String(SseDeserializer deserializer);
@protected
List<CccAlgoTestResult> sse_decode_list_ccc_algo_test_result(
SseDeserializer deserializer,
);
@protected
List<CccAlgorithmEntry> sse_decode_list_ccc_algorithm_entry(
SseDeserializer deserializer,
);
@protected
List<int> sse_decode_list_prim_u_8_loose(SseDeserializer deserializer);
@protected
Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer);
@protected
String? sse_decode_opt_String(SseDeserializer deserializer);
@protected
int sse_decode_u_32(SseDeserializer deserializer);
@protected
int sse_decode_u_8(SseDeserializer deserializer);
@protected
void sse_decode_unit(SseDeserializer deserializer);
@protected
int sse_decode_i_32(SseDeserializer deserializer);
@protected
bool sse_decode_bool(SseDeserializer deserializer);
@protected
void sse_encode_String(String self, SseSerializer serializer);
@protected
void sse_encode_bool(bool self, SseSerializer serializer);
@protected
void sse_encode_ccc_aead_algorithm(
CccAeadAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algo_test_result(
CccAlgoTestResult self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algorithm_capability(
CccAlgorithmCapability self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_algorithm_entry(
CccAlgorithmEntry self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_capabilities(
CccCapabilities self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_crypto_error(
CccCryptoError self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_hash_algorithm(
CccHashAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kdf_algorithm(
CccKdfAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_algorithm(
CccKemAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_encap_result(
CccKemEncapResult self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_kem_key_pair(
CccKemKeyPair self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_mac_algorithm(
CccMacAlgorithm self,
SseSerializer serializer,
);
@protected
void sse_encode_ccc_self_test_report(
CccSelfTestReport self,
SseSerializer serializer,
);
@protected
void sse_encode_i_32(int self, SseSerializer serializer);
@protected
void sse_encode_list_String(List<String> self, SseSerializer serializer);
@protected
void sse_encode_list_ccc_algo_test_result(
List<CccAlgoTestResult> self,
SseSerializer serializer,
);
@protected
void sse_encode_list_ccc_algorithm_entry(
List<CccAlgorithmEntry> self,
SseSerializer serializer,
);
@protected
void sse_encode_list_prim_u_8_loose(List<int> self, SseSerializer serializer);
@protected
void sse_encode_list_prim_u_8_strict(
Uint8List self,
SseSerializer serializer,
);
@protected
void sse_encode_opt_String(String? self, SseSerializer serializer);
@protected
void sse_encode_u_32(int self, SseSerializer serializer);
@protected
void sse_encode_u_8(int self, SseSerializer serializer);
@protected
void sse_encode_unit(void self, SseSerializer serializer);
@protected
void sse_encode_i_32(int self, SseSerializer serializer);
@protected
void sse_encode_bool(bool self, SseSerializer serializer);
}
// Section: wire_class

185
rust/src/api/crypto.rs Normal file
View File

@ -0,0 +1,185 @@
// Bridge API — thin wrappers that delegate to ccc_rust providers.
//
// No cryptographic logic here; only type conversions and registry lookups.
use ccc_crypto_core::{KemProvider, ProviderRegistry};
use ccc_crypto_wolfssl::WolfSslProvider;
use crate::api::dto::*;
// ── Helpers ──────────────────────────────────────────────────────────────────
/// Default provider name used when the caller doesn't specify one.
const DEFAULT_PROVIDER: &str = "wolfssl";
/// Get the default provider from the registry or return an error.
fn default_provider(
) -> Result<std::sync::Arc<dyn ccc_crypto_core::provider::CryptoProvider>, CccCryptoError> {
ProviderRegistry::global()
.get(DEFAULT_PROVIDER)
.ok_or_else(|| {
CccCryptoError::InternalError(format!(
"provider '{DEFAULT_PROVIDER}' not registered — call ccc_init() first"
))
})
}
/// A lazily-initialised KemProvider instance.
///
/// `KemProvider` is not part of the `CryptoProvider` supertrait, so we keep
/// a standalone `WolfSslProvider` for KEM operations.
fn kem_provider() -> &'static WolfSslProvider {
use std::sync::OnceLock;
static KEM: OnceLock<WolfSslProvider> = OnceLock::new();
KEM.get_or_init(WolfSslProvider::new)
}
// ── Init ─────────────────────────────────────────────────────────────────────
/// Initialise the CCC cryptographic subsystem.
///
/// Registers the wolfSSL provider in the global registry.
/// Safe to call multiple times (idempotent).
pub fn ccc_init() {
flutter_rust_bridge::setup_default_user_utils();
if !ProviderRegistry::global().contains(DEFAULT_PROVIDER) {
ccc_crypto_wolfssl::init();
}
}
// ── Provider info ────────────────────────────────────────────────────────────
/// List all registered provider names.
#[flutter_rust_bridge::frb(sync)]
pub fn ccc_list_providers() -> Vec<String> {
ProviderRegistry::global().list()
}
/// Return the capabilities of the default provider.
pub fn ccc_capabilities() -> Result<CccCapabilities, CccCryptoError> {
let provider = default_provider()?;
Ok(CccCapabilities::from(provider.capabilities()))
}
// ── AEAD ─────────────────────────────────────────────────────────────────────
/// Encrypt with an AEAD algorithm.
///
/// Returns ciphertext‖tag.
pub fn ccc_aead_encrypt(
algorithm: CccAeadAlgorithm,
key: Vec<u8>,
nonce: Vec<u8>,
plaintext: Vec<u8>,
aad: Vec<u8>,
) -> Result<Vec<u8>, CccCryptoError> {
let provider = default_provider()?;
Ok(provider.encrypt_aead(algorithm.to_core(), &key, &nonce, &plaintext, &aad)?)
}
/// Decrypt with an AEAD algorithm.
///
/// Expects ciphertext‖tag as `ciphertext`.
pub fn ccc_aead_decrypt(
algorithm: CccAeadAlgorithm,
key: Vec<u8>,
nonce: Vec<u8>,
ciphertext: Vec<u8>,
aad: Vec<u8>,
) -> Result<Vec<u8>, CccCryptoError> {
let provider = default_provider()?;
Ok(provider.decrypt_aead(algorithm.to_core(), &key, &nonce, &ciphertext, &aad)?)
}
// ── KDF ──────────────────────────────────────────────────────────────────────
/// Derive key material using a KDF.
pub fn ccc_kdf_derive(
algorithm: CccKdfAlgorithm,
ikm: Vec<u8>,
salt: Vec<u8>,
info: Vec<u8>,
length: u32,
) -> Result<Vec<u8>, CccCryptoError> {
let provider = default_provider()?;
let derived = provider.derive_key(
algorithm.to_core(),
&ikm,
&salt,
&info,
length as usize,
)?;
// Move out of Zeroizing wrapper — FRB will copy to Dart.
Ok(derived.to_vec())
}
// ── MAC ──────────────────────────────────────────────────────────────────────
/// Compute a MAC tag.
pub fn ccc_mac_compute(
algorithm: CccMacAlgorithm,
key: Vec<u8>,
data: Vec<u8>,
) -> Result<Vec<u8>, CccCryptoError> {
let provider = default_provider()?;
Ok(provider.compute_mac(algorithm.to_core(), &key, &data)?)
}
/// Verify a MAC tag. Returns `true` if valid.
pub fn ccc_mac_verify(
algorithm: CccMacAlgorithm,
key: Vec<u8>,
data: Vec<u8>,
mac: Vec<u8>,
) -> Result<bool, CccCryptoError> {
let provider = default_provider()?;
Ok(provider.verify_mac(algorithm.to_core(), &key, &data, &mac)?)
}
// ── Hash ─────────────────────────────────────────────────────────────────────
/// Compute a cryptographic hash.
pub fn ccc_hash(
algorithm: CccHashAlgorithm,
data: Vec<u8>,
) -> Result<Vec<u8>, CccCryptoError> {
let provider = default_provider()?;
Ok(provider.hash(algorithm.to_core(), &data)?)
}
// ── KEM ──────────────────────────────────────────────────────────────────────
/// Generate a KEM key pair.
pub fn ccc_kem_generate_keypair(
algorithm: CccKemAlgorithm,
) -> Result<CccKemKeyPair, CccCryptoError> {
let kp = kem_provider().generate_keypair(algorithm.to_core())?;
Ok(CccKemKeyPair::from(kp))
}
/// KEM encapsulation — produce ciphertext + shared secret from a public key.
pub fn ccc_kem_encapsulate(
algorithm: CccKemAlgorithm,
public_key: Vec<u8>,
) -> Result<CccKemEncapResult, CccCryptoError> {
let result = kem_provider().encapsulate(algorithm.to_core(), &public_key)?;
Ok(CccKemEncapResult::from(result))
}
/// KEM decapsulation — recover shared secret from ciphertext + private key.
pub fn ccc_kem_decapsulate(
algorithm: CccKemAlgorithm,
private_key: Vec<u8>,
ciphertext: Vec<u8>,
) -> Result<Vec<u8>, CccCryptoError> {
let ss = kem_provider().decapsulate(algorithm.to_core(), &private_key, &ciphertext)?;
Ok(ss.to_vec())
}
// ── Self-test ────────────────────────────────────────────────────────────────
/// Run the provider self-test and return a structured report.
pub fn ccc_self_test() -> Result<CccSelfTestReport, CccCryptoError> {
let provider = default_provider()?;
Ok(CccSelfTestReport::from(provider.self_test()))
}

328
rust/src/api/dto.rs Normal file
View File

@ -0,0 +1,328 @@
// Bridge-visible DTOs — no crypto logic, only type conversions.
//
// flutter_rust_bridge codegen picks up all pub types under crate::api
// and generates corresponding Dart classes.
use ccc_crypto_core::{
AeadAlgorithm, AlgoTestResult, AlgorithmCapability, HashAlgorithm, KdfAlgorithm,
KemAlgorithm, KemEncapResult, KemKeyPair, MacAlgorithm, ProviderCapabilities, SelfTestReport,
};
// ── Algorithm ID enums (mirror Rust repr(u32) values) ────────────────────────
/// AEAD algorithm identifiers — values match `ccc_rust` `#[repr(u32)]`.
#[flutter_rust_bridge::frb(dart_metadata=("freezed"))]
pub enum CccAeadAlgorithm {
AesGcm256 = 12,
ChaCha20Poly1305 = 13,
XChaCha20Poly1305 = 14,
Ascon128a = 15,
}
/// KDF algorithm identifiers.
#[flutter_rust_bridge::frb(dart_metadata=("freezed"))]
pub enum CccKdfAlgorithm {
Sha256 = 1,
Sha384 = 2,
Sha512 = 3,
Blake2b512 = 4,
Argon2id = 5,
Kmac256 = 6,
}
/// MAC algorithm identifiers.
#[flutter_rust_bridge::frb(dart_metadata=("freezed"))]
pub enum CccMacAlgorithm {
HmacSha256 = 30,
HmacSha384 = 31,
HmacSha512 = 32,
Blake2bMac = 33,
Poly1305 = 35,
}
/// Hash algorithm identifiers.
#[flutter_rust_bridge::frb(dart_metadata=("freezed"))]
pub enum CccHashAlgorithm {
Sha256 = 40,
Sha384 = 41,
Sha512 = 42,
Blake2b512 = 43,
Sha3_256 = 44,
Sha3_512 = 45,
}
/// KEM algorithm identifiers.
#[flutter_rust_bridge::frb(dart_metadata=("freezed"))]
pub enum CccKemAlgorithm {
X25519 = 50,
X448 = 51,
MlKem768 = 52,
MlKem1024 = 53,
ClassicMcEliece460896 = 54,
}
// ── Enum conversions ─────────────────────────────────────────────────────────
impl CccAeadAlgorithm {
pub(crate) fn to_core(&self) -> AeadAlgorithm {
match self {
Self::AesGcm256 => AeadAlgorithm::AesGcm256,
Self::ChaCha20Poly1305 => AeadAlgorithm::ChaCha20Poly1305,
Self::XChaCha20Poly1305 => AeadAlgorithm::XChaCha20Poly1305,
Self::Ascon128a => AeadAlgorithm::Ascon128a,
}
}
}
impl CccKdfAlgorithm {
pub(crate) fn to_core(&self) -> KdfAlgorithm {
match self {
Self::Sha256 => KdfAlgorithm::Sha256,
Self::Sha384 => KdfAlgorithm::Sha384,
Self::Sha512 => KdfAlgorithm::Sha512,
Self::Blake2b512 => KdfAlgorithm::Blake2b512,
Self::Argon2id => KdfAlgorithm::Argon2id,
Self::Kmac256 => KdfAlgorithm::Kmac256,
}
}
}
impl CccMacAlgorithm {
pub(crate) fn to_core(&self) -> MacAlgorithm {
match self {
Self::HmacSha256 => MacAlgorithm::HmacSha256,
Self::HmacSha384 => MacAlgorithm::HmacSha384,
Self::HmacSha512 => MacAlgorithm::HmacSha512,
Self::Blake2bMac => MacAlgorithm::Blake2bMac,
Self::Poly1305 => MacAlgorithm::Poly1305,
}
}
}
impl CccHashAlgorithm {
pub(crate) fn to_core(&self) -> HashAlgorithm {
match self {
Self::Sha256 => HashAlgorithm::Sha256,
Self::Sha384 => HashAlgorithm::Sha384,
Self::Sha512 => HashAlgorithm::Sha512,
Self::Blake2b512 => HashAlgorithm::Blake2b512,
Self::Sha3_256 => HashAlgorithm::Sha3_256,
Self::Sha3_512 => HashAlgorithm::Sha3_512,
}
}
}
impl CccKemAlgorithm {
pub(crate) fn to_core(&self) -> KemAlgorithm {
match self {
Self::X25519 => KemAlgorithm::X25519,
Self::X448 => KemAlgorithm::X448,
Self::MlKem768 => KemAlgorithm::MlKem768,
Self::MlKem1024 => KemAlgorithm::MlKem1024,
Self::ClassicMcEliece460896 => KemAlgorithm::ClassicMcEliece460896,
}
}
}
// ── DTO structs ──────────────────────────────────────────────────────────────
/// Per-algorithm availability and quality scores.
pub struct CccAlgorithmCapability {
pub available: bool,
pub deterministic_io: bool,
pub efficiency_score: u8,
pub reliability_score: u8,
}
impl From<&AlgorithmCapability> for CccAlgorithmCapability {
fn from(cap: &AlgorithmCapability) -> Self {
Self {
available: cap.available,
deterministic_io: cap.deterministic_io,
efficiency_score: cap.efficiency_score,
reliability_score: cap.reliability_score,
}
}
}
/// An algorithm entry in the capabilities list.
pub struct CccAlgorithmEntry {
pub algo_id: u32,
pub algo_name: String,
pub capability: CccAlgorithmCapability,
}
/// Provider capabilities — flattened from HashMap to Vec for FRB.
pub struct CccCapabilities {
pub provider_name: String,
pub aead: Vec<CccAlgorithmEntry>,
pub kdf: Vec<CccAlgorithmEntry>,
pub mac: Vec<CccAlgorithmEntry>,
pub hash: Vec<CccAlgorithmEntry>,
pub kem: Vec<CccAlgorithmEntry>,
}
impl From<ProviderCapabilities> for CccCapabilities {
fn from(caps: ProviderCapabilities) -> Self {
Self {
provider_name: caps.provider_name,
aead: caps
.aead
.iter()
.map(|(algo, cap)| CccAlgorithmEntry {
algo_id: *algo as u32,
algo_name: algo.name().to_string(),
capability: CccAlgorithmCapability::from(cap),
})
.collect(),
kdf: caps
.kdf
.iter()
.map(|(algo, cap)| CccAlgorithmEntry {
algo_id: *algo as u32,
algo_name: algo.name().to_string(),
capability: CccAlgorithmCapability::from(cap),
})
.collect(),
mac: caps
.mac
.iter()
.map(|(algo, cap)| CccAlgorithmEntry {
algo_id: *algo as u32,
algo_name: algo.name().to_string(),
capability: CccAlgorithmCapability::from(cap),
})
.collect(),
hash: caps
.hash
.iter()
.map(|(algo, cap)| CccAlgorithmEntry {
algo_id: *algo as u32,
algo_name: algo.name().to_string(),
capability: CccAlgorithmCapability::from(cap),
})
.collect(),
kem: caps
.kem
.iter()
.map(|(algo, cap)| CccAlgorithmEntry {
algo_id: *algo as u32,
algo_name: algo.name().to_string(),
capability: CccAlgorithmCapability::from(cap),
})
.collect(),
}
}
}
/// KEM key pair — public + private key bytes.
pub struct CccKemKeyPair {
pub public_key: Vec<u8>,
pub private_key: Vec<u8>,
}
impl From<KemKeyPair> for CccKemKeyPair {
fn from(kp: KemKeyPair) -> Self {
Self {
public_key: kp.public_key.clone(),
private_key: kp.private_key.clone(),
}
}
}
/// KEM encapsulation result — ciphertext + shared secret.
pub struct CccKemEncapResult {
pub ciphertext: Vec<u8>,
pub shared_secret: Vec<u8>,
}
impl From<KemEncapResult> for CccKemEncapResult {
fn from(er: KemEncapResult) -> Self {
Self {
ciphertext: er.ciphertext.clone(),
shared_secret: er.shared_secret.clone(),
}
}
}
/// Per-algorithm self-test result.
pub struct CccAlgoTestResult {
pub algo_id: u32,
pub algo_name: String,
pub passed: bool,
pub error_message: Option<String>,
}
impl From<&AlgoTestResult> for CccAlgoTestResult {
fn from(r: &AlgoTestResult) -> Self {
Self {
algo_id: r.algo_id,
algo_name: r.algo_name.clone(),
passed: r.passed,
error_message: r.error_message.clone(),
}
}
}
/// Aggregate self-test report.
pub struct CccSelfTestReport {
pub provider_name: String,
pub results: Vec<CccAlgoTestResult>,
pub all_passed: bool,
}
impl From<SelfTestReport> for CccSelfTestReport {
fn from(report: SelfTestReport) -> Self {
Self {
provider_name: report.provider_name,
results: report.results.iter().map(CccAlgoTestResult::from).collect(),
all_passed: report.all_passed,
}
}
}
// ── Bridge error ─────────────────────────────────────────────────────────────
/// Bridge-visible error type — maps 1:1 from `ccc_rust::CryptoError`.
///
/// FRB translates this into a Dart exception.
#[derive(Debug)]
pub enum CccCryptoError {
UnsupportedAlgorithm(String),
InvalidKey(String),
InvalidNonce(String),
AuthenticationFailed,
InvalidInput(String),
FeatureNotCompiled(String),
InternalError(String),
}
impl std::fmt::Display for CccCryptoError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnsupportedAlgorithm(s) => write!(f, "unsupported algorithm: {s}"),
Self::InvalidKey(s) => write!(f, "invalid key: {s}"),
Self::InvalidNonce(s) => write!(f, "invalid nonce: {s}"),
Self::AuthenticationFailed => write!(f, "authentication failed"),
Self::InvalidInput(s) => write!(f, "invalid input: {s}"),
Self::FeatureNotCompiled(s) => write!(f, "feature not compiled: {s}"),
Self::InternalError(s) => write!(f, "internal error: {s}"),
}
}
}
impl std::error::Error for CccCryptoError {}
impl From<ccc_crypto_core::CryptoError> for CccCryptoError {
fn from(e: ccc_crypto_core::CryptoError) -> Self {
match e {
ccc_crypto_core::CryptoError::UnsupportedAlgorithm(s) => Self::UnsupportedAlgorithm(s),
ccc_crypto_core::CryptoError::InvalidKey(s) => Self::InvalidKey(s),
ccc_crypto_core::CryptoError::InvalidNonce(s) => Self::InvalidNonce(s),
ccc_crypto_core::CryptoError::AuthenticationFailed => Self::AuthenticationFailed,
ccc_crypto_core::CryptoError::InvalidInput(s) => Self::InvalidInput(s),
ccc_crypto_core::CryptoError::FeatureNotCompiled(s) => Self::FeatureNotCompiled(s),
ccc_crypto_core::CryptoError::InternalError(s) => Self::InternalError(s),
}
}
}

View File

@ -1 +1,3 @@
pub mod crypto;
pub mod dto;
pub mod simple;

File diff suppressed because it is too large Load Diff