forked from firka/firka
add tests for fmbcrypt
This commit is contained in:
@@ -7,7 +7,7 @@ import 'dart:convert';
|
||||
/// since fmb works quite interesting, it may not throw an error on an un-decomposable string,
|
||||
/// so it is recommended to check the string to see if it is intact
|
||||
|
||||
class fmbCrypt {
|
||||
class FMBCrypt {
|
||||
static Uint8List generateKey(String password) {
|
||||
final key = Uint8List(32);
|
||||
int hash = 0;
|
||||
@@ -75,13 +75,12 @@ class fmbCrypt {
|
||||
}
|
||||
|
||||
/// basic usage:
|
||||
/// String? encrypted = fmbCrypt.handleText('encrypt', 'Hello World', 'myPassword');
|
||||
/// String? decrypted = fmbCrypt.handleText('decrypt', encrypted!, 'myPassword');
|
||||
/// String? encrypted = FMBCrypt.handleText('encrypt', 'Hello World', 'myPassword');
|
||||
/// String? decrypted = FMBCrypt.handleText('decrypt', encrypted!, 'myPassword');
|
||||
|
||||
static String? handleText(String action, String input, String password) {
|
||||
if (password.isEmpty || input.isEmpty) {
|
||||
throw ArgumentError('Password and input cannot be empty');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -95,12 +94,10 @@ class fmbCrypt {
|
||||
return utf8.decode(decrypted);
|
||||
} catch (e) {
|
||||
throw Exception('Failed to decrypt data: ${e.toString()}');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
throw Exception('Failed to $action data: ${error.toString()}');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
filc/test/fmb_test.dart
Normal file
28
filc/test/fmb_test.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:filc/fmb_crypt.dart';
|
||||
|
||||
void main() {
|
||||
test('encryption and decryption test', () async {
|
||||
String? encrypted = FMBCrypt.handleText('encrypt', 'Hello World!', 'test password');
|
||||
expect(encrypted, isNotNull);
|
||||
expect(encrypted, equals('eBzx7LhjOE7NW5Ba'));
|
||||
if (kDebugMode) {
|
||||
print('encrypted: $encrypted');
|
||||
}
|
||||
String? decrypted = FMBCrypt.handleText('decrypt', encrypted!, 'test password');
|
||||
expect(decrypted, isNotNull);
|
||||
expect(decrypted, equals('Hello World!'));
|
||||
if (kDebugMode) {
|
||||
print('decrypted: $decrypted');
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user