Skip to content

Commit 95f6f45

Browse files
committed
[code-review] Rename Crypto to CryptoApi
* make charset static const * Inject CryptoApi via constructor
1 parent e81e4f3 commit 95f6f45

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

examples/flutter_firebase_login/packages/authentication_repository/lib/src/authentication_repository.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:async';
22

33
import 'package:authentication_repository/authentication_repository.dart';
4-
import 'package:authentication_repository/src/crypto.dart';
4+
import 'package:authentication_repository/src/crypto_api.dart';
55
import 'package:cache/cache.dart';
66
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
77
import 'package:google_sign_in/google_sign_in.dart';
@@ -31,15 +31,17 @@ class AuthenticationRepository {
3131
AuthenticationRepository({
3232
CacheClient? cache,
3333
firebase_auth.FirebaseAuth? firebaseAuth,
34-
GoogleSignIn? googleSignIn
34+
GoogleSignIn? googleSignIn,
35+
CryptoApi? cryptoApi
3536
}) : _cache = cache ?? CacheClient(),
3637
_firebaseAuth = firebaseAuth ?? firebase_auth.FirebaseAuth.instance,
37-
_googleSignIn = googleSignIn ?? GoogleSignIn.standard()
38+
_googleSignIn = googleSignIn ?? GoogleSignIn.standard(),
39+
_crypto = cryptoApi ?? CryptoApi()
3840

3941
final CacheClient _cache;
4042
final firebase_auth.FirebaseAuth _firebaseAuth;
4143
final GoogleSignIn _googleSignIn;
42-
final Crypto _crypto = Crypto();
44+
final Crypto _crypto;
4345

4446
/// User cache key.
4547
/// Should only be used for testing purposes.

examples/flutter_firebase_login/packages/authentication_repository/lib/src/crypto.dart examples/flutter_firebase_login/packages/authentication_repository/lib/src/crypto_api.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import 'dart:convert';
33

44
import 'package:crypto/crypto.dart';
55

6-
class Crypto {
6+
class CryptoApi {
7+
8+
static const charset =
9+
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
710

811
/// Generates a cryptographically secure random nonce, to be included in a
912
/// credential request.
1013
String generateNonce([int length = 32]) {
11-
const charset =
12-
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
1314
var random = Random.secure();
1415
return List.generate(length, (_) => charset[random.nextInt(charset.length)])
1516
.join();

0 commit comments

Comments
 (0)