Skip to content

Commit 62e0861

Browse files
committed
[code-review] Rename Crypto to CryptoApi
* make charset static const * Inject CryptoApi via constructor
1 parent 0666613 commit 62e0861

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:flutter/foundation.dart' show kIsWeb;
@@ -32,15 +32,17 @@ class AuthenticationRepository {
3232
AuthenticationRepository({
3333
CacheClient? cache,
3434
firebase_auth.FirebaseAuth? firebaseAuth,
35-
GoogleSignIn? googleSignIn
35+
GoogleSignIn? googleSignIn,
36+
CryptoApi? cryptoApi
3637
}) : _cache = cache ?? CacheClient(),
3738
_firebaseAuth = firebaseAuth ?? firebase_auth.FirebaseAuth.instance,
38-
_googleSignIn = googleSignIn ?? GoogleSignIn.standard()
39+
_googleSignIn = googleSignIn ?? GoogleSignIn.standard(),
40+
_crypto = cryptoApi ?? CryptoApi()
3941

4042
final CacheClient _cache;
4143
final firebase_auth.FirebaseAuth _firebaseAuth;
4244
final GoogleSignIn _googleSignIn;
43-
final Crypto _crypto = Crypto();
45+
final Crypto _crypto;
4446

4547
/// Whether or not the current environment is web
4648
/// Should only be overriden for testing purposes. Otherwise,

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)