Skip to content

Commit

Permalink
Merge pull request #38 from tekartik/dart3a
Browse files Browse the repository at this point in the history
Dart3a
  • Loading branch information
alextekartik authored Jul 23, 2023
2 parents 0f2d897 + dd064d6 commit 2f22cab
Show file tree
Hide file tree
Showing 98 changed files with 301 additions and 4,321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dart: [2.19.6, stable, beta, dev]
dart: [3.0.5, stable, beta, dev]
steps:
- uses: actions/checkout@v3
- uses: dart-lang/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In `pubspec.yaml`
tekartik_app_common_utils:
git:
url: https://github.com/tekartik/app_common_utils.dart
ref: dart2_3
ref: dart3a
path: app
version: '>=0.1.0'
```
8 changes: 4 additions & 4 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ homepage: https://www.example.com
publish_to: none

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
pub_semver:
tekartik_common_utils:
git:
url: https://github.com/tekartik/common_utils.dart
ref: dart2_3
ref: dart3a
version: '>=0.10.7'
# tekartik_app_pager:
# git:
# url: https://github.com/tekartik/app_common_utils.dart
# ref: dart2_3
# ref: dart3a
# path: app_pager
# version: '>=0.1.3'

Expand All @@ -35,4 +35,4 @@ dependency_overrides:
# path: ../app_pager
# tmp
# tekartik_common_utils:
# path: ../../common_utils.dart
# path: ../../common_utils.dart
2 changes: 1 addition & 1 deletion app_bloc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
tekartik_app_bloc:
git:
url: https://github.com/tekartik/app_common_utils.dart
ref: dart2_3
ref: dart3a
path: app_bloc
version: '>=0.1.0'
```
6 changes: 3 additions & 3 deletions app_bloc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version: 0.2.0
publish_to: none

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
tekartik_common_utils:
git:
url: https://github.com/tekartik/common_utils.dart
ref: dart2_3
ref: dart3a
version: '>=0.10.7'
meta:

Expand All @@ -20,4 +20,4 @@ dev_dependencies:
build_runner: '>=1.2.7'
build_test: any
build_web_compilers: any
process_run:
process_run:
2 changes: 1 addition & 1 deletion app_crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
tekartik_app_crypto:
git:
url: https://github.com/tekartik/app_common_utils.dart
ref: dart2_3
ref: dart3a
path: app_crypto
version: '>=0.2.2'
```
2 changes: 1 addition & 1 deletion app_crypto/lib/encrypt.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'package:tekartik_app_crypto/src/encrypt.dart'
show encrypt, decrypt, StringEncrypter;
show encrypt, decrypt, StringEncrypter, defaultEncryptedFromRawPassword;

export 'src/salsa20.dart' show salsa20EncrypterFromPassword;
2 changes: 2 additions & 0 deletions app_crypto/lib/encrypt_codec.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'package:tekartik_app_crypto/src/encrypt_codec.dart'
show defaultEncryptCodec, EncryptCodec, salsa20EncryptCodec;
41 changes: 39 additions & 2 deletions app_crypto/lib/src/encrypt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:encrypt/encrypt.dart';
/// returns a bast 64 encrypted string.
///
/// Encryption used is AES.
String encrypt(String decoded, String password) {
String _encrypt(String decoded, String password) {
final key = Key.fromUtf8(password);
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
Expand All @@ -20,15 +20,52 @@ String encrypt(String decoded, String password) {
/// [password]
///
/// Encryption used is AES.
String decrypt(String encoded, String password) {
String _decrypt(String encoded, String password) {
final key = Key.fromUtf8(password);
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
return encrypter.decrypt(Encrypted.fromBase64(encoded), iv: iv);
}

/// encrypt the [decoded] text using [password].
///
/// [password] must be ascii character of length 16, 24 or 32.
///
/// returns a bast 64 encrypted string.
///
/// Encryption used is AES.
String encrypt(String decoded, String password) => _encrypt(decoded, password);

/// decrypt the [encoded] text using [password].
///
/// [encoded] is base 64 string got from the encrypt method using the same
/// [password]
///
/// Encryption used is AES.
String decrypt(String encoded, String password) => _decrypt(encoded, password);

/// Encrypt, decrypt helper
abstract class StringEncrypter {
String encrypt(String input);

String decrypt(String encrypted);
}

/// Using AES,
/// [password] must be ascii character of length 16, 24 or 32.
class _DefaultEncrypter implements StringEncrypter {
final String password;

_DefaultEncrypter(this.password);

@override
String decrypt(String encrypted) => _decrypt(encrypted, password);

@override
String encrypt(String input) => _encrypt(input, password);
}

/// Using AES,
/// [password] must be ascii character of length 16, 24 or 32.
StringEncrypter defaultEncryptedFromRawPassword(String password) =>
_DefaultEncrypter(password);
42 changes: 42 additions & 0 deletions app_crypto/lib/src/encrypt_codec.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dart:convert';

import 'package:tekartik_app_crypto/encrypt.dart';

class EncryptConverter with Converter<String, String> {
final StringEncrypter encrypter;

EncryptConverter({required this.encrypter});
@override
String convert(String input) => encrypter.encrypt(input);
}

class DecryptConverter with Converter<String, String> {
final StringEncrypter encrypter;

DecryptConverter({required this.encrypter});
@override
String convert(String input) => encrypter.decrypt(input);
}

/// Encrypt codec.
class EncryptCodec with Codec<String, String> {
final StringEncrypter encrypter;

EncryptCodec({required this.encrypter});

@override
Converter<String, String> get decoder =>
DecryptConverter(encrypter: encrypter);

@override
Converter<String, String> get encoder =>
EncryptConverter(encrypter: encrypter);
}

/// String password
EncryptCodec defaultEncryptCodec({required String rawPassword}) =>
EncryptCodec(encrypter: defaultEncryptedFromRawPassword(rawPassword));

/// Any password can be used
EncryptCodec salsa20EncryptCodec({required String password}) =>
EncryptCodec(encrypter: salsa20EncrypterFromPassword(password));
2 changes: 1 addition & 1 deletion app_crypto/lib/src/salsa20.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Uint8List _generateEncryptPassword(String password) {
return blob;
}

/// Salsa 20 encrypted using any password (use MD5)
/// Salsa 20 encrypted using any password (use MD5), random data prepended
StringEncrypter salsa20EncrypterFromPassword(String password) {
final key = Key(_generateEncryptPassword(password));
return _Salsa20StringEncrypter(Encrypter(Salsa20(key)));
Expand Down
6 changes: 3 additions & 3 deletions app_crypto/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ homepage: https://www.example.com
publish_to: none

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
tekartik_common_utils:
git:
url: https://github.com/tekartik/common_utils.dart
ref: dart2_3
ref: dart3a
version: '>=0.10.7'
meta: '>=1.1.6'
encrypt: '>=3.0.0'
Expand All @@ -26,4 +26,4 @@ dev_dependencies:
build_runner: '>=1.2.7'
build_test: any
build_web_compilers: any
process_run: '>=0.12.0+1'
process_run: '>=0.12.0+1'
12 changes: 12 additions & 0 deletions app_crypto/test/codec_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:tekartik_app_crypto/encrypt_codec.dart';

import 'package:test/test.dart';

void main() {
test('test', () {
var password = r'E4x*$TwbkJC-xK4KGC4zJF9j*Rh&WLgR';
var encryptCodec = defaultEncryptCodec(rawPassword: password);
expect(encryptCodec.encode('test'), 'amGhyRRLUIoE59IiEys5Vw==');
expect(encryptCodec.decode('amGhyRRLUIoE59IiEys5Vw=='), 'test');
});
}
2 changes: 1 addition & 1 deletion app_csv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In `pubspec.yaml`
tekartik_app_csv:
git:
url: https://github.com/tekartik/app_common_utils.dart
ref: dart2_3
ref: dart3a
path: app_csv
version: '>=0.1.0'
```
6 changes: 3 additions & 3 deletions app_csv/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ homepage: https://github.com/tekartik/app_common_utils.dart
publish_to: none

environment:
sdk: '>=2.18.0 <4.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
csv: '>=5.0.0-0'
tekartik_common_utils:
git:
url: https://github.com/tekartik/common_utils.dart
ref: dart2_3
ref: dart3a
version: '>=0.10.7'
dev_dependencies:
path:
dev_test:
test: ^1.6.0
process_run:
build_runner:
build_test:
build_test:
13 changes: 0 additions & 13 deletions app_cv/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions app_cv/CHANGELOG.md

This file was deleted.

18 changes: 0 additions & 18 deletions app_cv/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions app_cv/analysis_options.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions app_cv/lib/app_cv.dart

This file was deleted.

29 changes: 0 additions & 29 deletions app_cv/lib/app_cv_v1.dart

This file was deleted.

Loading

0 comments on commit 2f22cab

Please sign in to comment.