mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
98 lines
3.6 KiB
Dart
98 lines
3.6 KiB
Dart
// This file is automatically generated, so please do not edit it.
|
|
// @generated by `flutter_rust_bridge`@ 2.12.0.
|
|
|
|
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
|
|
|
|
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
|
|
import 'package:localsend_isolates/rust/api/cancel.dart';
|
|
import 'package:localsend_isolates/rust/frb_generated.dart';
|
|
|
|
part 'crypto.freezed.dart';
|
|
|
|
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`
|
|
|
|
Future<void> verifyCert({required String cert, required String publicKey}) =>
|
|
RustLib.instance.api.crateApiCryptoVerifyCert(cert: cert, publicKey: publicKey);
|
|
|
|
Future<KeyPair> generateKeyPair() => RustLib.instance.api.crateApiCryptoGenerateKeyPair();
|
|
|
|
/// Generates a new device identity: an RSA-2048 key pair and a self-signed
|
|
/// certificate whose SHA-256 fingerprint identifies the device.
|
|
Future<SecurityContext> generateSecurityContext() => RustLib.instance.api.crateApiCryptoGenerateSecurityContext();
|
|
|
|
/// Computes the SHA-256 checksum of a file, reported as the final
|
|
/// [RsHashFileEvent::Done] event of the returned stream.
|
|
///
|
|
/// The file is read chunk by chunk, so it is never fully loaded into memory.
|
|
/// Cancelling [cancel_token] aborts the read, so hashing a large file does not
|
|
/// have to be waited out.
|
|
///
|
|
/// Exactly one content source must be provided:
|
|
/// a [path] to a regular file, a [file_descriptor] (Android only), or [bytes]
|
|
/// for a file that only lives in memory.
|
|
Stream<RsHashFileEvent> hashFile({String? path, int? fileDescriptor, Uint8List? bytes, required RsCancellationToken cancelToken}) =>
|
|
RustLib.instance.api.crateApiCryptoHashFile(path: path, fileDescriptor: fileDescriptor, bytes: bytes, cancelToken: cancelToken);
|
|
|
|
class KeyPair {
|
|
final String privateKey;
|
|
final String publicKey;
|
|
|
|
const KeyPair({
|
|
required this.privateKey,
|
|
required this.publicKey,
|
|
});
|
|
|
|
@override
|
|
int get hashCode => privateKey.hashCode ^ publicKey.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is KeyPair && runtimeType == other.runtimeType && privateKey == other.privateKey && publicKey == other.publicKey;
|
|
}
|
|
|
|
@freezed
|
|
sealed class RsHashFileEvent with _$RsHashFileEvent {
|
|
const RsHashFileEvent._();
|
|
|
|
/// Cumulative number of bytes hashed so far.
|
|
/// Throttled, so not every hashed chunk is reported.
|
|
const factory RsHashFileEvent.progress({
|
|
required BigInt bytes,
|
|
}) = RsHashFileEvent_Progress;
|
|
|
|
/// Hashing has finished; [hash] is the checksum, encoded as lowercase hex.
|
|
/// Always the last event of the stream.
|
|
const factory RsHashFileEvent.done({
|
|
required String hash,
|
|
}) = RsHashFileEvent_Done;
|
|
}
|
|
|
|
class SecurityContext {
|
|
final String privateKey;
|
|
final String publicKey;
|
|
final String certificate;
|
|
final String certificateHash;
|
|
|
|
const SecurityContext({
|
|
required this.privateKey,
|
|
required this.publicKey,
|
|
required this.certificate,
|
|
required this.certificateHash,
|
|
});
|
|
|
|
@override
|
|
int get hashCode => privateKey.hashCode ^ publicKey.hashCode ^ certificate.hashCode ^ certificateHash.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is SecurityContext &&
|
|
runtimeType == other.runtimeType &&
|
|
privateKey == other.privateKey &&
|
|
publicKey == other.publicKey &&
|
|
certificate == other.certificate &&
|
|
certificateHash == other.certificateHash;
|
|
}
|