diff --git a/packages/native_crypto/analysis_options.yaml b/packages/native_crypto/analysis_options.yaml index a5744c1..db48808 100644 --- a/packages/native_crypto/analysis_options.yaml +++ b/packages/native_crypto/analysis_options.yaml @@ -1,4 +1 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +include: package:wyatt_analysis/analysis_options.flutter.experimental.yaml \ No newline at end of file diff --git a/packages/native_crypto/example/lib/home.dart b/packages/native_crypto/example/lib/home.dart index 50e65e8..8357b7e 100644 --- a/packages/native_crypto/example/lib/home.dart +++ b/packages/native_crypto/example/lib/home.dart @@ -22,11 +22,7 @@ class Home extends StatefulWidget { class _HomeState extends State { int _currentIndex = 0; - final List _children = [ - KdfPage(), - CipherPage(), - BenchmarkPage() - ]; + final List _children = [KdfPage(), CipherPage(), BenchmarkPage()]; void onTabTapped(int index) { setState(() { diff --git a/packages/native_crypto/example/lib/pages/benchmark_page.dart b/packages/native_crypto/example/lib/pages/benchmark_page.dart index 27552ec..71c4bea 100644 --- a/packages/native_crypto/example/lib/pages/benchmark_page.dart +++ b/packages/native_crypto/example/lib/pages/benchmark_page.dart @@ -34,21 +34,22 @@ class BenchmarkPage extends ConsumerWidget { int size = 64; benchmarkStatus.print("Benchmark Test\n"); - + // Encryption var before = DateTime.now(); var encryptedBigFile = await cipher.encrypt(Uint8List(size * 1000000)); var after = DateTime.now(); var benchmark = - after.millisecondsSinceEpoch - before.millisecondsSinceEpoch; - benchmarkStatus.append('[$size MB] Encryption took $benchmark ms\n'); - + after.millisecondsSinceEpoch - before.millisecondsSinceEpoch; + benchmarkStatus.append('[$size MB] Encryption took $benchmark ms\n'); + // Decryption var befored = DateTime.now(); await cipher.decrypt(encryptedBigFile); var afterd = DateTime.now(); - var benchmarkd = afterd.millisecondsSinceEpoch - befored.millisecondsSinceEpoch; - benchmarkStatus.append('[$size MB] Decryption took $benchmarkd ms\n'); + var benchmarkd = + afterd.millisecondsSinceEpoch - befored.millisecondsSinceEpoch; + benchmarkStatus.append('[$size MB] Decryption took $benchmarkd ms\n'); } Future _benchmark(WidgetRef ref, Cipher cipher) async { diff --git a/packages/native_crypto/example/lib/session.dart b/packages/native_crypto/example/lib/session.dart index 8c25499..7636866 100644 --- a/packages/native_crypto/example/lib/session.dart +++ b/packages/native_crypto/example/lib/session.dart @@ -16,9 +16,11 @@ class Session { SecretKey secretKey; Session() : secretKey = SecretKey(Uint8List(0)); - void setKey(SecretKey sk) { secretKey = sk; } + void setKey(SecretKey sk) { + secretKey = sk; + } } // Providers -final sessionProvider = StateProvider((ref) => Session()); \ No newline at end of file +final sessionProvider = StateProvider((ref) => Session()); diff --git a/packages/native_crypto/example/lib/utils.dart b/packages/native_crypto/example/lib/utils.dart index 874b778..d93a923 100644 --- a/packages/native_crypto/example/lib/utils.dart +++ b/packages/native_crypto/example/lib/utils.dart @@ -23,12 +23,12 @@ extension StringX on String { bytes = base64.decode(this); break; case Encoding.hex: - bytes = Uint8List.fromList( - List.generate( - length ~/ 2, - (i) => int.parse(substring(i * 2, (i * 2) + 2), radix: 16), - ).toList(), - ); + bytes = Uint8List.fromList( + List.generate( + length ~/ 2, + (i) => int.parse(substring(i * 2, (i * 2) + 2), radix: 16), + ).toList(), + ); } return bytes; } diff --git a/packages/native_crypto/example/lib/widgets/button.dart b/packages/native_crypto/example/lib/widgets/button.dart index 30c28a5..2244bb4 100644 --- a/packages/native_crypto/example/lib/widgets/button.dart +++ b/packages/native_crypto/example/lib/widgets/button.dart @@ -15,7 +15,6 @@ class Button extends StatelessWidget { const Button(this.onPressed, this.label, {Key? key}) : super(key: key); - @override Widget build(BuildContext context) { return ElevatedButton( diff --git a/packages/native_crypto/lib/native_crypto.dart b/packages/native_crypto/lib/native_crypto.dart index 015dab2..12076c7 100644 --- a/packages/native_crypto/lib/native_crypto.dart +++ b/packages/native_crypto/lib/native_crypto.dart @@ -3,7 +3,7 @@ // ----- // File: native_crypto.dart // Created Date: 16/12/2021 16:28:00 -// Last Modified: 28/12/2021 15:06:48 +// Last Modified: 23/05/2022 21:43:54 // ----- // Copyright (c) 2021 @@ -21,7 +21,10 @@ export 'src/keyderivation.dart'; export 'src/keys/secret_key.dart'; export 'src/utils.dart'; -const String version = "0.1.0"; -const String author = "Hugo Pointcheval"; -const String website = "https://hugo.pointcheval.fr/"; -const List repositories = ["https://github.com/hugo-pcl/native-crypto-flutter", "https://git.pointcheval.fr/NativeCrypto/native-crypto-flutter"]; +const String version = '0.1.0'; +const String author = 'Hugo Pointcheval'; +const String website = 'https://hugo.pointcheval.fr/'; +const List repositories = [ + 'https://github.com/hugo-pcl/native-crypto-flutter', + 'https://git.pointcheval.fr/NativeCrypto/native-crypto-flutter' +]; diff --git a/packages/native_crypto/lib/src/builder.dart b/packages/native_crypto/lib/src/builder.dart index 2ed8d17..4817768 100644 --- a/packages/native_crypto/lib/src/builder.dart +++ b/packages/native_crypto/lib/src/builder.dart @@ -9,4 +9,4 @@ abstract class Builder { Future build(); -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/builders/aes_builder.dart b/packages/native_crypto/lib/src/builders/aes_builder.dart index 8073490..898d79a 100644 --- a/packages/native_crypto/lib/src/builders/aes_builder.dart +++ b/packages/native_crypto/lib/src/builders/aes_builder.dart @@ -3,14 +3,14 @@ // ----- // File: aes_builder.dart // Created Date: 28/12/2021 12:03:11 -// Last Modified: 28/12/2021 13:39:23 +// Last Modified: 23/05/2022 21:46:33 // ----- // Copyright (c) 2021 -import '../builder.dart'; -import '../ciphers/aes.dart'; -import '../exceptions.dart'; -import '../keys/secret_key.dart'; +import 'package:native_crypto/src/builder.dart'; +import 'package:native_crypto/src/ciphers/aes.dart'; +import 'package:native_crypto/src/exceptions.dart'; +import 'package:native_crypto/src/keys/secret_key.dart'; class AESBuilder implements Builder { SecretKey? _sk; @@ -36,11 +36,11 @@ class AESBuilder implements Builder { Future build() async { if (_sk == null) { if (_fsk == null) { - throw CipherInitException("You must specify or generate a secret key."); + throw CipherInitException('You must specify or generate a secret key.'); } else { _sk = await _fsk; } } return AES(_sk!, _mode); } -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/byte_array.dart b/packages/native_crypto/lib/src/byte_array.dart index 8343a34..18c2fcf 100644 --- a/packages/native_crypto/lib/src/byte_array.dart +++ b/packages/native_crypto/lib/src/byte_array.dart @@ -3,14 +3,14 @@ // ----- // File: byte_array.dart // Created Date: 16/12/2021 17:54:16 -// Last Modified: 27/12/2021 21:51:36 +// Last Modified: 23/05/2022 21:44:38 // ----- // Copyright (c) 2021 +import 'dart:convert' as convert; import 'dart:typed_data'; -import 'utils.dart'; -import 'dart:convert' as convert; +import 'package:native_crypto/src/utils.dart'; class ByteArray { Uint8List _bytes; @@ -18,7 +18,8 @@ class ByteArray { ByteArray(this._bytes); /// Creates an ByteArray object from a hexdecimal string. - ByteArray.fromBase16(String encoded) : _bytes = Utils.decodeHexString(encoded); + ByteArray.fromBase16(String encoded) + : _bytes = Utils.decodeHexString(encoded); /// Creates an ByteArray object from a Base64 string. ByteArray.fromBase64(String encoded) @@ -46,17 +47,17 @@ class ByteArray { String get base64 => convert.base64.encode(_bytes); @override - bool operator ==(other) { + bool operator ==(Object other) { if (other is ByteArray) { for (int i = 0; i < _bytes.length; i++) { if (_bytes[i] != other._bytes[i]) { return false; } } - + return true; } - + return false; } @@ -66,7 +67,7 @@ class ByteArray { for (int i = 0; i < _bytes.length; i++) { hash = _bytes[i] + (hash << 6) + (hash << 16) - hash; } - + return hash; } -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/cipher.dart b/packages/native_crypto/lib/src/cipher.dart index fec80ca..9d5dee8 100644 --- a/packages/native_crypto/lib/src/cipher.dart +++ b/packages/native_crypto/lib/src/cipher.dart @@ -34,4 +34,4 @@ abstract class Cipher { /// Takes [CipherText] as parameter. /// And returns plain text data as [Uint8List]. Future decrypt(CipherText cipherText); -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/cipher_text.dart b/packages/native_crypto/lib/src/cipher_text.dart index c4b53f2..bf79c27 100644 --- a/packages/native_crypto/lib/src/cipher_text.dart +++ b/packages/native_crypto/lib/src/cipher_text.dart @@ -3,21 +3,25 @@ // ----- // File: cipher_text.dart // Created Date: 16/12/2021 16:59:53 -// Last Modified: 27/12/2021 22:32:06 +// Last Modified: 23/05/2022 21:48:27 // ----- // Copyright (c) 2021 import 'dart:typed_data'; -import 'byte_array.dart'; +import 'package:native_crypto/src/byte_array.dart'; class CipherText extends ByteArray { final int _ivLength; final int _dataLength; final int _tagLength; - - CipherText(Uint8List iv, Uint8List data, Uint8List tag) : _ivLength = iv.length, _dataLength = data.length, _tagLength = tag.length, super(Uint8List.fromList(iv + data + tag)); - + + CipherText(Uint8List iv, Uint8List data, Uint8List tag) + : _ivLength = iv.length, + _dataLength = data.length, + _tagLength = tag.length, + super(Uint8List.fromList(iv + data + tag)); + /// Gets the CipherText IV. Uint8List get iv => bytes.sublist(0, _ivLength); @@ -25,7 +29,10 @@ class CipherText extends ByteArray { Uint8List get data => bytes.sublist(_ivLength, _ivLength + _dataLength); /// Gets the CipherText tag. - Uint8List get tag => bytes.sublist(_ivLength + _dataLength, _ivLength + _dataLength + _tagLength); + Uint8List get tag => bytes.sublist( + _ivLength + _dataLength, + _ivLength + _dataLength + _tagLength, + ); /// Gets the CipherText IV length. int get ivLength => _ivLength; @@ -41,11 +48,13 @@ class CipherTextList extends CipherText { static const int chunkSize = 33554432; final List _list; - CipherTextList() : _list = [], super(Uint8List(0), Uint8List(0), Uint8List(0)); + CipherTextList() + : _list = [], + super(Uint8List(0), Uint8List(0), Uint8List(0)); void add(CipherText cipherText) { _list.add(cipherText); } - get list => _list; -} \ No newline at end of file + List get list => _list; +} diff --git a/packages/native_crypto/lib/src/ciphers/aes.dart b/packages/native_crypto/lib/src/ciphers/aes.dart index 592a7ce..56c19a8 100644 --- a/packages/native_crypto/lib/src/ciphers/aes.dart +++ b/packages/native_crypto/lib/src/ciphers/aes.dart @@ -3,18 +3,18 @@ // ----- // File: aes.dart // Created Date: 16/12/2021 16:28:00 -// Last Modified: 28/12/2021 13:39:00 +// Last Modified: 23/05/2022 21:47:08 // ----- // Copyright (c) 2021 import 'dart:typed_data'; -import '../cipher.dart'; -import '../cipher_text.dart'; -import '../exceptions.dart'; -import '../keys/secret_key.dart'; -import '../platform.dart'; -import '../utils.dart'; +import 'package:native_crypto/src/cipher.dart'; +import 'package:native_crypto/src/cipher_text.dart'; +import 'package:native_crypto/src/exceptions.dart'; +import 'package:native_crypto/src/keys/secret_key.dart'; +import 'package:native_crypto/src/platform.dart'; +import 'package:native_crypto/src/utils.dart'; /// Defines the AES modes of operation. enum AESMode { gcm } @@ -47,31 +47,37 @@ class AES implements Cipher { AES(this.key, this.mode, {this.padding = AESPadding.none}) { if (!AESKeySizeExtension.supportedSizes.contains(key.bytes.length * 8)) { - throw CipherInitException("Invalid key length!"); + throw CipherInitException('Invalid key length!'); } - Map> _supported = { + final Map> _supported = { AESMode.gcm: [AESPadding.none], }; if (!_supported[mode]!.contains(padding)) { - throw CipherInitException("Invalid padding!"); + throw CipherInitException('Invalid padding!'); } } @override Future decrypt(CipherText cipherText) async { - BytesBuilder decryptedData = BytesBuilder(copy: false); + final BytesBuilder decryptedData = BytesBuilder(copy: false); if (cipherText is CipherTextList) { - for (CipherText ct in cipherText.list) { - Uint8List d = await platform.decrypt( - ct.bytes, key.bytes, Utils.enumToStr(algorithm)) ?? + for (final CipherText ct in cipherText.list) { + final Uint8List d = await platform.decrypt( + ct.bytes, + key.bytes, + Utils.enumToStr(algorithm), + ) ?? Uint8List(0); decryptedData.add(d); } } else { - Uint8List d = await platform.decrypt( - cipherText.bytes, key.bytes, Utils.enumToStr(algorithm)) ?? + final Uint8List d = await platform.decrypt( + cipherText.bytes, + key.bytes, + Utils.enumToStr(algorithm), + ) ?? Uint8List(0); decryptedData.add(d); } @@ -82,29 +88,41 @@ class AES implements Cipher { @override Future encrypt(Uint8List data) async { Uint8List dataToEncrypt; - CipherTextList cipherTextList = CipherTextList(); + final CipherTextList cipherTextList = CipherTextList(); // If data is bigger than 32mB -> split in chunks if (data.length > CipherTextList.chunkSize) { - int chunkNb = (data.length / CipherTextList.chunkSize).ceil(); + final int chunkNb = (data.length / CipherTextList.chunkSize).ceil(); for (var i = 0; i < chunkNb; i++) { dataToEncrypt = i < (chunkNb - 1) - ? data.sublist(i * CipherTextList.chunkSize, (i + 1) * CipherTextList.chunkSize) + ? data.sublist( + i * CipherTextList.chunkSize, + (i + 1) * CipherTextList.chunkSize, + ) : data.sublist(i * CipherTextList.chunkSize); - Uint8List c = await platform.encrypt( - dataToEncrypt, - key.bytes, - Utils.enumToStr(algorithm) - ) ?? Uint8List(0); - cipherTextList.add(CipherText(c.sublist(0, 12), c.sublist(12, c.length - 16), c.sublist(c.length - 16, c.length))); // TODO: generify this + final Uint8List c = await platform.encrypt( + dataToEncrypt, + key.bytes, + Utils.enumToStr(algorithm), + ) ?? + Uint8List(0); + cipherTextList.add( + CipherText( + c.sublist(0, 12), + c.sublist(12, c.length - 16), + c.sublist(c.length - 16, c.length), + ), + ); // TODO(hpcl): generify this } } else { - Uint8List c = await platform.encrypt( - data, - key.bytes, - Utils.enumToStr(algorithm) - ) ?? Uint8List(0); + final Uint8List c = + await platform.encrypt(data, key.bytes, Utils.enumToStr(algorithm)) ?? + Uint8List(0); - return CipherText(c.sublist(0, 12), c.sublist(12, c.length - 16), c.sublist(c.length - 16, c.length)); // TODO: generify this + return CipherText( + c.sublist(0, 12), + c.sublist(12, c.length - 16), + c.sublist(c.length - 16, c.length), + ); // TODO(hpcl): generify this } return cipherTextList; diff --git a/packages/native_crypto/lib/src/exceptions.dart b/packages/native_crypto/lib/src/exceptions.dart index 3a5d2ce..10af511 100644 --- a/packages/native_crypto/lib/src/exceptions.dart +++ b/packages/native_crypto/lib/src/exceptions.dart @@ -3,39 +3,39 @@ // ----- // File: exceptions.dart // Created Date: 16/12/2021 16:28:00 -// Last Modified: 27/12/2021 23:28:31 +// Last Modified: 23/05/2022 21:51:55 // ----- // Copyright (c) 2021 class NativeCryptoException implements Exception { - String message; - NativeCryptoException(this.message); + final String message; + const NativeCryptoException(this.message); } class UtilsException extends NativeCryptoException { - UtilsException(message) : super(message); + UtilsException(String message) : super(message); } class KeyException extends NativeCryptoException { - KeyException(message) : super(message); + KeyException(String message) : super(message); } class KeyDerivationException extends NativeCryptoException { - KeyDerivationException(message) : super(message); + KeyDerivationException(String message) : super(message); } class CipherInitException extends NativeCryptoException { - CipherInitException(message) : super(message); + CipherInitException(String message) : super(message); } class EncryptionException extends NativeCryptoException { - EncryptionException(message) : super(message); + EncryptionException(String message) : super(message); } class DecryptionException extends NativeCryptoException { - DecryptionException(message) : super(message); + DecryptionException(String message) : super(message); } class NotImplementedException extends NativeCryptoException { - NotImplementedException(message) : super(message); + NotImplementedException(String message) : super(message); } diff --git a/packages/native_crypto/lib/src/hasher.dart b/packages/native_crypto/lib/src/hasher.dart index bacf4bd..d81b7cc 100644 --- a/packages/native_crypto/lib/src/hasher.dart +++ b/packages/native_crypto/lib/src/hasher.dart @@ -20,8 +20,10 @@ abstract class Hasher { /// Hashes a message Future digest(Uint8List data) async { - Uint8List hash = (await platform.digest(data, Utils.enumToStr(algorithm))) ?? Uint8List(0); - + Uint8List hash = + (await platform.digest(data, Utils.enumToStr(algorithm))) ?? + Uint8List(0); + return hash; } } diff --git a/packages/native_crypto/lib/src/hashers/sha256.dart b/packages/native_crypto/lib/src/hashers/sha256.dart index 6c1284a..8f88189 100644 --- a/packages/native_crypto/lib/src/hashers/sha256.dart +++ b/packages/native_crypto/lib/src/hashers/sha256.dart @@ -3,13 +3,13 @@ // ----- // File: sha256.dart // Created Date: 17/12/2021 11:31:20 -// Last Modified: 18/12/2021 12:09:33 +// Last Modified: 23/05/2022 21:47:23 // ----- // Copyright (c) 2021 -import '../hasher.dart'; +import 'package:native_crypto/src/hasher.dart'; -class SHA256 extends Hasher{ +class SHA256 extends Hasher { @override HashAlgorithm get algorithm => HashAlgorithm.sha256; -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/hashers/sha384.dart b/packages/native_crypto/lib/src/hashers/sha384.dart index b9f44dd..f7630eb 100644 --- a/packages/native_crypto/lib/src/hashers/sha384.dart +++ b/packages/native_crypto/lib/src/hashers/sha384.dart @@ -3,13 +3,13 @@ // ----- // File: sha384.dart // Created Date: 17/12/2021 11:31:53 -// Last Modified: 18/12/2021 12:09:45 +// Last Modified: 23/05/2022 21:47:28 // ----- // Copyright (c) 2021 -import '../hasher.dart'; +import 'package:native_crypto/src/hasher.dart'; -class SHA384 extends Hasher{ +class SHA384 extends Hasher { @override HashAlgorithm get algorithm => HashAlgorithm.sha384; -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/hashers/sha512.dart b/packages/native_crypto/lib/src/hashers/sha512.dart index d4f7d6b..881887c 100644 --- a/packages/native_crypto/lib/src/hashers/sha512.dart +++ b/packages/native_crypto/lib/src/hashers/sha512.dart @@ -3,13 +3,13 @@ // ----- // File: sha512.dart // Created Date: 17/12/2021 11:32:14 -// Last Modified: 18/12/2021 12:09:58 +// Last Modified: 23/05/2022 21:47:35 // ----- // Copyright (c) 2021 -import '../hasher.dart'; +import 'package:native_crypto/src/hasher.dart'; -class SHA512 extends Hasher{ +class SHA512 extends Hasher { @override HashAlgorithm get algorithm => HashAlgorithm.sha512; -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/kdf/pbkdf2.dart b/packages/native_crypto/lib/src/kdf/pbkdf2.dart index 8d5a004..8d8aa55 100644 --- a/packages/native_crypto/lib/src/kdf/pbkdf2.dart +++ b/packages/native_crypto/lib/src/kdf/pbkdf2.dart @@ -3,18 +3,18 @@ // ----- // File: pbkdf2.dart // Created Date: 17/12/2021 14:50:42 -// Last Modified: 28/12/2021 13:38:50 +// Last Modified: 23/05/2022 21:47:43 // ----- // Copyright (c) 2021 import 'dart:typed_data'; -import '../exceptions.dart'; -import '../hasher.dart'; -import '../keyderivation.dart'; -import '../keys/secret_key.dart'; -import '../platform.dart'; -import '../utils.dart'; +import 'package:native_crypto/src/exceptions.dart'; +import 'package:native_crypto/src/hasher.dart'; +import 'package:native_crypto/src/keyderivation.dart'; +import 'package:native_crypto/src/keys/secret_key.dart'; +import 'package:native_crypto/src/platform.dart'; +import 'package:native_crypto/src/utils.dart'; class PBKDF2 extends KeyDerivation { final int _keyBytesCount; @@ -38,13 +38,14 @@ class PBKDF2 extends KeyDerivation { throw KeyDerivationException("Password or Salt can't be null!"); } - Uint8List derivation = (await platform.pbkdf2( - password, - salt, - _keyBytesCount, - _iterations, - Utils.enumToStr(_hash), - )) ?? Uint8List(0); + final Uint8List derivation = (await platform.pbkdf2( + password, + salt, + _keyBytesCount, + _iterations, + Utils.enumToStr(_hash), + )) ?? + Uint8List(0); return SecretKey(derivation); } diff --git a/packages/native_crypto/lib/src/key.dart b/packages/native_crypto/lib/src/key.dart index b86c1d2..ed7d98c 100644 --- a/packages/native_crypto/lib/src/key.dart +++ b/packages/native_crypto/lib/src/key.dart @@ -17,4 +17,4 @@ class Key extends ByteArray { Key.fromBase16(String encoded) : super.fromBase16(encoded); Key.fromBase64(String encoded) : super.fromBase64(encoded); Key.fromUtf8(String input) : super.fromUtf8(input); -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/keyderivation.dart b/packages/native_crypto/lib/src/keyderivation.dart index 279346e..b3cba30 100644 --- a/packages/native_crypto/lib/src/keyderivation.dart +++ b/packages/native_crypto/lib/src/keyderivation.dart @@ -18,4 +18,4 @@ abstract class KeyDerivation { /// Derive key Future derive(); -} \ No newline at end of file +} diff --git a/packages/native_crypto/lib/src/keys/secret_key.dart b/packages/native_crypto/lib/src/keys/secret_key.dart index 4579496..7fbdd5f 100644 --- a/packages/native_crypto/lib/src/keys/secret_key.dart +++ b/packages/native_crypto/lib/src/keys/secret_key.dart @@ -3,7 +3,7 @@ // ----- // File: secret_key.dart // Created Date: 28/12/2021 13:36:54 -// Last Modified: 28/12/2021 13:37:45 +// Last Modified: 23/05/2022 21:52:05 // ----- // Copyright (c) 2021 @@ -11,9 +11,9 @@ import 'dart:typed_data'; import 'package:flutter/services.dart'; -import '../exceptions.dart'; -import '../key.dart'; -import '../platform.dart'; +import 'package:native_crypto/src/exceptions.dart'; +import 'package:native_crypto/src/key.dart'; +import 'package:native_crypto/src/platform.dart'; /// A class representing a secret key. /// A secret key is a key that is not accessible by anyone else. @@ -26,11 +26,12 @@ class SecretKey extends Key { static Future fromSecureRandom(int bitsCount) async { try { - Uint8List _key = (await platform.generateSecretKey(bitsCount)) ?? Uint8List(0); - + final Uint8List _key = + (await platform.generateSecretKey(bitsCount)) ?? Uint8List(0); + return SecretKey(_key); } on PlatformException catch (e) { - throw KeyException(e); + throw KeyException(e.toString()); } } } diff --git a/packages/native_crypto/lib/src/platform.dart b/packages/native_crypto/lib/src/platform.dart index 9834907..c4c13c1 100644 --- a/packages/native_crypto/lib/src/platform.dart +++ b/packages/native_crypto/lib/src/platform.dart @@ -9,4 +9,4 @@ import 'package:native_crypto_platform_interface/native_crypto_platform_interface.dart'; -NativeCryptoPlatform platform = NativeCryptoPlatform.instance; \ No newline at end of file +NativeCryptoPlatform platform = NativeCryptoPlatform.instance; diff --git a/packages/native_crypto/lib/src/utils.dart b/packages/native_crypto/lib/src/utils.dart index df0dff2..67a6411 100644 --- a/packages/native_crypto/lib/src/utils.dart +++ b/packages/native_crypto/lib/src/utils.dart @@ -3,16 +3,16 @@ // ----- // File: utils.dart // Created Date: 16/12/2021 16:28:00 -// Last Modified: 27/12/2021 22:04:07 +// Last Modified: 23/05/2022 21:45:56 // ----- // Copyright (c) 2021 import 'dart:typed_data'; -import 'cipher.dart'; -import 'exceptions.dart'; -import 'hasher.dart'; -import 'keyderivation.dart'; +import 'package:native_crypto/src/cipher.dart'; +import 'package:native_crypto/src/exceptions.dart'; +import 'package:native_crypto/src/hasher.dart'; +import 'package:native_crypto/src/keyderivation.dart'; class Utils { /// Returns enum value to string, without the enum name @@ -22,17 +22,17 @@ class Utils { /// Returns enum list as string list static List enumToList(List enumValues) { - List _res = []; - for (T enumValue in enumValues) { + final List _res = []; + for (final T enumValue in enumValues) { _res.add(enumToStr(enumValue)); } - + return _res; } /// Returns enum from string static T strToEnum(String str, List enumValues) { - for (T enumValue in enumValues) { + for (final T enumValue in enumValues) { if (enumToStr(enumValue) == str) { return enumValue; } @@ -42,7 +42,10 @@ class Utils { /// Returns [HashAlgorithm] from his name. static HashAlgorithm getHashAlgorithm(String algorithm) { - return strToEnum(algorithm.toLowerCase(), HashAlgorithm.values); + return strToEnum( + algorithm.toLowerCase(), + HashAlgorithm.values, + ); } /// Returns all available [HashAlgorithm] as String list @@ -52,7 +55,10 @@ class Utils { /// Returns [KdfAlgorithm] from his name. static KdfAlgorithm getKdfAlgorithm(String algorithm) { - return strToEnum(algorithm.toLowerCase(), KdfAlgorithm.values); + return strToEnum( + algorithm.toLowerCase(), + KdfAlgorithm.values, + ); } /// Returns all available [KdfAlgorithm] as String list @@ -62,7 +68,10 @@ class Utils { /// Returns [CipherAlgorithm] from his name. static CipherAlgorithm getCipherAlgorithm(String algorithm) { - return strToEnum(algorithm.toLowerCase(), CipherAlgorithm.values); + return strToEnum( + algorithm.toLowerCase(), + CipherAlgorithm.values, + ); } /// Returns all available [CipherAlgorithm] as String list @@ -70,8 +79,8 @@ class Utils { return enumToList(CipherAlgorithm.values); } - static Uint8List decodeHexString(String input) { - assert(input.length % 2 == 0, 'Input needs to be an even length.'); + static Uint8List decodeHexString(String input) { + assert(input.length.isEven, 'Input needs to be an even length.'); return Uint8List.fromList( List.generate( diff --git a/packages/native_crypto/pubspec.yaml b/packages/native_crypto/pubspec.yaml index 5a63d48..2f2648e 100644 --- a/packages/native_crypto/pubspec.yaml +++ b/packages/native_crypto/pubspec.yaml @@ -1,6 +1,7 @@ name: native_crypto description: Fast and secure cryptography for Flutter. version: 0.1.0 + publish_to: 'none' environment: @@ -12,18 +13,32 @@ dependencies: sdk: flutter native_crypto_android: - path: ../native_crypto_android - + git: + url: https://github.com/hugo-pcl/native-crypto-flutter.git + ref: native_crypto_android-v0.1.0 + path: packages/native_crypto_android + native_crypto_ios: - path: ../native_crypto_ios + git: + url: https://github.com/hugo-pcl/native-crypto-flutter.git + ref: native_crypto_ios-v0.1.0 + path: packages/native_crypto_ios native_crypto_platform_interface: - path: ../native_crypto_platform_interface + git: + url: https://github.com/hugo-pcl/native-crypto-flutter.git + ref: native_crypto_platform_interface-v0.1.0 + path: packages/native_crypto_platform_interface dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^1.0.4 + + wyatt_analysis: + git: + url: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages + ref: wyatt_analysis-v2.1.0 + path: packages/wyatt_analysis flutter: plugin: