Skip to content

Commit

Permalink
add web impl, separate memory impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 7, 2024
1 parent 8dabb71 commit f85989b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/celest_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,23 @@ jobs:
# - name: Test (Windows)
# working-directory: packages/celest_core/example
# run: flutter test -d windows integration_test/secure_storage_test.dart
test_web:
needs: analyze_and_format
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Git Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1
- name: Setup Flutter
uses: subosito/flutter-action@62f096cacda5168a3bd7b95793373be14fa4fbaf # 2.13.0
with:
cache: true
- name: Get Packages
working-directory: packages/celest_core
run: dart pub get
- name: Test (Chrome, dart2js)
working-directory: packages/celest_core
run: dart test -p chrome
- name: Test (Chrome, dart2wasm)
working-directory: packages/celest_core
run: dart test -p chrome -c dart2wasm
22 changes: 22 additions & 0 deletions packages/celest_core/lib/src/secure_storage/secure_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,25 @@ abstract interface class SecureStorage {
String? delete(String key);
void clear();
}

/// An in-memory implementation of [SecureStorage].
final class MemorySecureStorage implements SecureStorage {
MemorySecureStorage({
required this.scope,
});

final _storage = <String, String>{};
final String scope;

@override
void clear() => _storage.removeWhere((key, _) => key.startsWith('$scope/'));

@override
String? delete(String key) => _storage.remove('$scope/$key');

@override
String? read(String key) => _storage['$scope/$key'];

@override
String write(String key, String value) => _storage['$scope/$key'] = value;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import 'package:celest_core/src/secure_storage/secure_storage.dart';
import 'package:celest_core/src/secure_storage/secure_storage.stub.dart';
import 'package:meta/meta.dart';

abstract base class SecureStoragePlatform implements SecureStorage {
factory SecureStoragePlatform({
final class SecureStoragePlatform implements SecureStorage {
SecureStoragePlatform({
String? scope,
}) =>
SecureStoragePlatformStub(scope: scope ?? _defaultScope);
}) : _impl = MemorySecureStorage(scope: scope ?? _defaultScope);

final SecureStorage _impl;

static const _defaultScope = 'dev.celest.celest';

@protected
const SecureStoragePlatform.base();
@override
void clear() => _impl.clear();

@override
String? delete(String key) => _impl.delete(key);

@override
String? read(String key) => _impl.read(key);

@override
String write(String key, String value) => _impl.write(key, value);
}

0 comments on commit f85989b

Please sign in to comment.