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 4, 2021
1 parent 0666613 commit 62e0861
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:flutter/foundation.dart' show kIsWeb;
Expand Down Expand Up @@ -32,15 +32,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;

/// Whether or not the current environment is web
/// Should only be overriden for testing purposes. Otherwise,
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 62e0861

Please sign in to comment.