Skip to content

Commit

Permalink
[code-review] Rename Crypto to CryptoApi
Browse files Browse the repository at this point in the history
* make charset static const
* Inject CryptoApi via constructor
  • Loading branch information
juzerali committed Oct 2, 2021
1 parent e81e4f3 commit 95f6f45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:authentication_repository/authentication_repository.dart';
import 'package:authentication_repository/src/crypto.dart';
import 'package:authentication_repository/src/crypto_api.dart';
import 'package:cache/cache.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:google_sign_in/google_sign_in.dart';
Expand Down Expand Up @@ -31,15 +31,17 @@ class AuthenticationRepository {
AuthenticationRepository({
CacheClient? cache,
firebase_auth.FirebaseAuth? firebaseAuth,
GoogleSignIn? googleSignIn
GoogleSignIn? googleSignIn,
CryptoApi? cryptoApi
}) : _cache = cache ?? CacheClient(),
_firebaseAuth = firebaseAuth ?? firebase_auth.FirebaseAuth.instance,
_googleSignIn = googleSignIn ?? GoogleSignIn.standard()
_googleSignIn = googleSignIn ?? GoogleSignIn.standard(),
_crypto = cryptoApi ?? CryptoApi()

final CacheClient _cache;
final firebase_auth.FirebaseAuth _firebaseAuth;
final GoogleSignIn _googleSignIn;
final Crypto _crypto = Crypto();
final Crypto _crypto;

/// User cache key.
/// Should only be used for testing purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import 'dart:convert';

import 'package:crypto/crypto.dart';

class Crypto {
class CryptoApi {

static const charset =
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';

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

0 comments on commit 95f6f45

Please sign in to comment.