refactor: Make encryption utils null safe
This commit is contained in:
parent
4bee82dbe0
commit
8f35683120
|
|
@ -1,4 +1,3 @@
|
|||
// @dart=2.9
|
||||
/*
|
||||
* Famedly Matrix SDK
|
||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
||||
|
|
@ -23,10 +22,10 @@ import 'crypto.dart';
|
|||
|
||||
class EncryptedFile {
|
||||
EncryptedFile({
|
||||
this.data,
|
||||
this.k,
|
||||
this.iv,
|
||||
this.sha256,
|
||||
required this.data,
|
||||
required this.k,
|
||||
required this.iv,
|
||||
required this.sha256,
|
||||
});
|
||||
Uint8List data;
|
||||
String k;
|
||||
|
|
@ -47,7 +46,7 @@ Future<EncryptedFile> encryptFile(Uint8List input) async {
|
|||
);
|
||||
}
|
||||
|
||||
Future<Uint8List> decryptFile(EncryptedFile input) async {
|
||||
Future<Uint8List?> decryptFile(EncryptedFile input) async {
|
||||
if (base64.encode(await sha256(input.data)) !=
|
||||
base64.normalize(input.sha256)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// @dart=2.9
|
||||
// Copyright (c) 2020 Famedly GmbH
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
// ignore: import_of_legacy_library_into_null_safe
|
||||
import 'subtle.dart';
|
||||
// ignore: import_of_legacy_library_into_null_safe
|
||||
import 'subtle.dart' as subtle;
|
||||
|
||||
abstract class Hash {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// @dart=2.9
|
||||
// Copyright (c) 2020 Famedly GmbH
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
|
|
@ -16,21 +15,29 @@ class CryptoKey {}
|
|||
@JS()
|
||||
@anonymous
|
||||
class Pbkdf2Params {
|
||||
external factory Pbkdf2Params(
|
||||
{String name, String hash, Uint8List salt, int iterations});
|
||||
String name;
|
||||
String hash;
|
||||
Uint8List salt;
|
||||
int iterations;
|
||||
external factory Pbkdf2Params({
|
||||
String name,
|
||||
String hash,
|
||||
Uint8List salt,
|
||||
int iterations,
|
||||
});
|
||||
String? name;
|
||||
String? hash;
|
||||
Uint8List? salt;
|
||||
int? iterations;
|
||||
}
|
||||
|
||||
@JS()
|
||||
@anonymous
|
||||
class AesCtrParams {
|
||||
external factory AesCtrParams({String name, Uint8List counter, int length});
|
||||
String name;
|
||||
Uint8List counter;
|
||||
int length;
|
||||
external factory AesCtrParams({
|
||||
String name,
|
||||
Uint8List counter,
|
||||
int length,
|
||||
});
|
||||
String? name;
|
||||
Uint8List? counter;
|
||||
int? length;
|
||||
}
|
||||
|
||||
@JS('crypto.subtle.encrypt')
|
||||
|
|
|
|||
Loading…
Reference in New Issue