Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cryptography/lib/src/browser/_javascript_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
library web_crypto_api;

import 'dart:convert' show base64Url;
import 'dart:html' show CryptoKey;
import 'dart:html' as html;
import 'dart:html' show CryptoKey;
import 'dart:typed_data';

import 'package:js/js.dart';
Expand All @@ -26,8 +26,7 @@ import 'package:js/js_util.dart' show promiseToFuture;
export 'dart:html' show CryptoKey;

/// Note that browsers support Web Cryptography only in secure contexts.
final bool isWebCryptoAvailable =
_subtle != null && (html.window.isSecureContext ?? false);
final bool isWebCryptoAvailable = _subtle != null && (html.window.isSecureContext ?? false);

@JS('crypto.subtle')
external Object? get _subtle;
Expand Down Expand Up @@ -203,9 +202,7 @@ Future<CryptoKey> importKeyWhenRaw(
ByteBuffer jsArrayBufferFrom(List<int> data) {
// Avoid copying if possible
//
if (data is Uint8List &&
data.offsetInBytes == 0 &&
data.lengthInBytes == data.buffer.lengthInBytes) {
if (data is Uint8List && data.offsetInBytes == 0 && data.lengthInBytes == data.buffer.lengthInBytes) {
// We need to check the type because UnmodifiableByteBufferView would cause
// an error.
final buffer = data.buffer;
Expand Down
6 changes: 3 additions & 3 deletions cryptography/lib/src/browser/aes_cbc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import 'dart:typed_data';

import 'package:cryptography_plus/cryptography_plus.dart';

import '_javascript_bindings.dart' show jsArrayBufferFrom;
import '_javascript_bindings.dart' as web_crypto;
import '_javascript_bindings.dart' show jsArrayBufferFrom;
import 'browser_secret_key.dart';

/// AES-CBC implementation that uses _Web Cryptography API_ in browsers.
Expand All @@ -38,9 +38,9 @@ class BrowserAesCbc extends AesCbc {
const BrowserAesCbc({
required this.macAlgorithm,
this.secretKeyLength = 32,
Random? random,
super.random,
}) : _random = random,
super.constructor(random: random);
super.constructor();

@override
PaddingAlgorithm get paddingAlgorithm => PaddingAlgorithm.pkcs7;
Expand Down
6 changes: 3 additions & 3 deletions cryptography/lib/src/browser/aes_ctr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import 'dart:typed_data';

import 'package:cryptography_plus/cryptography_plus.dart';

import '_javascript_bindings.dart' show jsArrayBufferFrom;
import '_javascript_bindings.dart' as web_crypto;
import '_javascript_bindings.dart' show jsArrayBufferFrom;
import 'browser_secret_key.dart';

/// AES-CTR implementation that uses _Web Cryptography API_ in browsers.
Expand All @@ -40,9 +40,9 @@ class BrowserAesCtr extends AesCtr {
required this.macAlgorithm,
this.secretKeyLength = 32,
this.counterBits = 64,
Random? random,
super.random,
}) : _random = random,
super.constructor(random: random);
super.constructor();

@override
Future<List<int>> decrypt(
Expand Down
6 changes: 3 additions & 3 deletions cryptography/lib/src/browser/aes_gcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import 'dart:typed_data';
import 'package:cryptography_plus/cryptography_plus.dart';
import 'package:cryptography_plus/src/browser/browser_secret_key.dart';

import '_javascript_bindings.dart' show jsArrayBufferFrom;
import '_javascript_bindings.dart' as web_crypto;
import '_javascript_bindings.dart' show jsArrayBufferFrom;

/// AES-GCM implementation that uses _Web Cryptography API_ in browsers.
class BrowserAesGcm extends AesGcm implements StreamingCipher {
Expand All @@ -43,9 +43,9 @@ class BrowserAesGcm extends AesGcm implements StreamingCipher {
this.secretKeyLength = 32,
this.nonceLength = AesGcm.defaultNonceLength,
this.fallback,
Random? random,
super.random,
}) : _random = random,
super.constructor(random: random);
super.constructor();

@override
Future<List<int>> decrypt(
Expand Down
15 changes: 5 additions & 10 deletions cryptography/lib/src/browser/browser_cryptography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import 'pbkdf2.dart';

class BrowserCryptography extends DartCryptography {
// Documented in browser_cryptography_when_not_browser.dart
static final Cryptography defaultInstance =
isSupported ? BrowserCryptography() : DartCryptography();
static final Cryptography defaultInstance = isSupported ? BrowserCryptography() : DartCryptography();

/// @nodoc
// TODO: Remove this
Expand All @@ -48,9 +47,8 @@ class BrowserCryptography extends DartCryptography {

// Documented in browser_cryptography_when_not_browser.dart
BrowserCryptography({
Random? random,
}) : _random = random,
super(random: random);
super.random,
}) : _random = random;

@override
AesCbc aesCbc({
Expand All @@ -59,9 +57,7 @@ class BrowserCryptography extends DartCryptography {
int secretKeyLength = 32,
}) {
// Web Cryptography API supports only 128 and 256 bit keys.
if (isSupported &&
secretKeyLength != 24 &&
identical(paddingAlgorithm, PaddingAlgorithm.pkcs7)) {
if (isSupported && secretKeyLength != 24 && identical(paddingAlgorithm, PaddingAlgorithm.pkcs7)) {
return BrowserAesCbc(
macAlgorithm: macAlgorithm,
secretKeyLength: secretKeyLength,
Expand Down Expand Up @@ -184,8 +180,7 @@ class BrowserCryptography extends DartCryptography {
@override
Hkdf hkdf({required Hmac hmac, required int outputLength}) {
if (isSupported) {
if (BrowserHashAlgorithmMixin.hashAlgorithmNameFor(hmac.hashAlgorithm) !=
null) {
if (BrowserHashAlgorithmMixin.hashAlgorithmNameFor(hmac.hashAlgorithm) != null) {
return BrowserHkdf(
hmac: hmac,
outputLength: outputLength,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class BrowserCryptography extends DartCryptography {
///
/// If [random] is not given, algorithms will use some cryptographically
/// secure random number generator (CSRNG) such as [Random.secure].
BrowserCryptography({Random? random}) : super(random: random);
BrowserCryptography({super.random});

@override
BrowserCryptography withRandom(Random? random) {
Expand Down
14 changes: 5 additions & 9 deletions cryptography/lib/src/browser/rsa_pss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ import 'dart:typed_data';

import 'package:cryptography_plus/cryptography_plus.dart';

import '_javascript_bindings.dart' as web_crypto;
import '_javascript_bindings.dart'
show
base64UrlDecodeUnmodifiable,
base64UrlDecodeUnmodifiableMaybe,
base64UrlEncode,
base64UrlEncodeMaybe;
show base64UrlDecodeUnmodifiable, base64UrlDecodeUnmodifiableMaybe, base64UrlEncode, base64UrlEncodeMaybe;
import '_javascript_bindings.dart' as web_crypto;
import 'hash.dart';

/// RSA-PSS implementation that uses _Web Cryptography API_ in browsers.
Expand Down Expand Up @@ -272,7 +268,7 @@ class _BrowserRsaPublicKey extends RsaPublicKey {
required this.jsCryptoKey,
required this.webCryptoAlgorithm,
required this.webCryptoHash,
required List<int> n,
required List<int> e,
}) : super(n: n, e: e);
required super.n,
required super.e,
});
}
9 changes: 4 additions & 5 deletions cryptography/lib/src/browser/rsa_ssa_pkcs1v15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import 'dart:typed_data';
import 'package:cryptography_plus/cryptography_plus.dart';

import '_javascript_bindings.dart' as web_crypto;
import '_javascript_bindings.dart'
show base64UrlDecodeUnmodifiable, base64UrlEncode, base64UrlEncodeMaybe;
import '_javascript_bindings.dart' show base64UrlDecodeUnmodifiable, base64UrlEncode, base64UrlEncodeMaybe;
import 'hash.dart';

/// RSA-SSA-PKCS1v15 implementation that uses _Web Cryptography API_ in browsers.
Expand Down Expand Up @@ -209,9 +208,9 @@ class _BrowserRsaPublicKey extends RsaPublicKey {
required this.jsCryptoKey,
required this.webCryptoAlgorithm,
required this.webCryptoHash,
required List<int> n,
required List<int> e,
}) : super(n: n, e: e);
required super.n,
required super.e,
});
}

class _BrowserRsaSsaPkcs1v15KeyPair extends KeyPair implements RsaKeyPair {
Expand Down
52 changes: 18 additions & 34 deletions cryptography/lib/src/cryptography/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ abstract class AesCbc extends Cipher {

/// Constructor for classes that extend this class.
const AesCbc.constructor({
Random? random,
}) : super(random: random);
super.random,
});

/// Constructs 128-bit AES-CBC.
factory AesCbc.with128bits({
Expand Down Expand Up @@ -215,7 +215,7 @@ abstract class AesCtr extends StreamingCipher {
static const int defaultCounterBits = 64;

/// Constructor for classes that extend this class.
const AesCtr.constructor({Random? random}) : super(random: random);
const AesCtr.constructor({super.random});

/// Constructs 128-bit AES-CTR.
factory AesCtr.with128bits({
Expand Down Expand Up @@ -268,9 +268,7 @@ abstract class AesCtr extends StreamingCipher {

@override
bool operator ==(other) =>
other is AesCtr &&
secretKeyLength == other.secretKeyLength &&
macAlgorithm == other.macAlgorithm;
other is AesCtr && secretKeyLength == other.secretKeyLength && macAlgorithm == other.macAlgorithm;

@override
void checkParameters({
Expand Down Expand Up @@ -368,7 +366,7 @@ abstract class AesGcm extends Cipher {
static const int defaultNonceLength = 12;

/// Constructor for classes that extend this class.
const AesGcm.constructor({Random? random}) : super(random: random);
const AesGcm.constructor({super.random});

factory AesGcm.with128bits({
int nonceLength = AesGcm.defaultNonceLength,
Expand Down Expand Up @@ -418,9 +416,7 @@ abstract class AesGcm extends Cipher {

@override
bool operator ==(other) =>
other is AesGcm &&
secretKeyLength == other.secretKeyLength &&
nonceLength == other.nonceLength;
other is AesGcm && secretKeyLength == other.secretKeyLength && nonceLength == other.nonceLength;

@override
String toString() {
Expand Down Expand Up @@ -878,7 +874,7 @@ abstract class Chacha20 extends StreamingCipher {
/// Constructor for classes that extend this class.
///
/// Optional parameter [random] is used by [newSecretKey] and [newNonce].
const Chacha20.constructor({Random? random}) : super(random: random);
const Chacha20.constructor({super.random});

/// Constructs ChaCha20-Poly1305-AEAD cipher
/// (([RFC 7539](https://tools.ietf.org/html/rfc7539), also known as
Expand Down Expand Up @@ -936,8 +932,7 @@ abstract class Chacha20 extends StreamingCipher {
int get secretKeyLength => 32;

@override
bool operator ==(other) =>
other is Chacha20 && macAlgorithm == other.macAlgorithm;
bool operator ==(other) => other is Chacha20 && macAlgorithm == other.macAlgorithm;

@override
String toString() {
Expand Down Expand Up @@ -1127,8 +1122,7 @@ abstract class Ecdsa extends SignatureAlgorithm {
Future<EcKeyPair> newKeyPairFromSeed(List<int> seed);

@override
String toString() =>
'$runtimeType.p${keyPairType.ellipticBits}($hashAlgorithm)';
String toString() => '$runtimeType.p${keyPairType.ellipticBits}($hashAlgorithm)';
}

/// _Ed25519_ ([RFC 8032](https://tools.ietf.org/html/rfc8032)) signature
Expand Down Expand Up @@ -1284,8 +1278,7 @@ abstract class Hkdf extends KdfAlgorithm {
int get outputLength;

@override
bool operator ==(other) =>
other is Hkdf && hmac == other.hmac && outputLength == other.outputLength;
bool operator ==(other) => other is Hkdf && hmac == other.hmac && outputLength == other.outputLength;

@override
Future<SecretKeyData> deriveKey({
Expand Down Expand Up @@ -1415,8 +1408,7 @@ abstract class Hmac extends MacAlgorithm {
int get macLength => hashAlgorithm.hashLengthInBytes;

@override
bool operator ==(other) =>
other is Hmac && hashAlgorithm == other.hashAlgorithm;
bool operator ==(other) => other is Hmac && hashAlgorithm == other.hashAlgorithm;

@override
String toString() {
Expand Down Expand Up @@ -1532,10 +1524,7 @@ abstract class Pbkdf2 extends KdfAlgorithm {

@override
bool operator ==(other) =>
other is Pbkdf2 &&
iterations == other.iterations &&
bits == other.bits &&
macAlgorithm == other.macAlgorithm;
other is Pbkdf2 && iterations == other.iterations && bits == other.bits && macAlgorithm == other.macAlgorithm;

@override
String toString() {
Expand Down Expand Up @@ -1686,9 +1675,7 @@ abstract class RsaPss extends SignatureAlgorithm {

@override
bool operator ==(other) =>
other is RsaPss &&
hashAlgorithm == other.hashAlgorithm &&
nonceLengthInBytes == other.nonceLengthInBytes;
other is RsaPss && hashAlgorithm == other.hashAlgorithm && nonceLengthInBytes == other.nonceLengthInBytes;

@override
Future<RsaKeyPair> newKeyPair({
Expand All @@ -1697,8 +1684,7 @@ abstract class RsaPss extends SignatureAlgorithm {
});

@override
String toString() =>
'$runtimeType($hashAlgorithm, nonceLengthInBytes: $nonceLengthInBytes)';
String toString() => '$runtimeType($hashAlgorithm, nonceLengthInBytes: $nonceLengthInBytes)';
}

/// _RSA-SSA-PKCS1v15_ [SignatureAlgorithm].
Expand Down Expand Up @@ -1770,8 +1756,7 @@ abstract class RsaSsaPkcs1v15 extends SignatureAlgorithm {
KeyPairType<KeyPairData, PublicKey> get keyPairType => KeyPairType.rsa;

@override
bool operator ==(other) =>
other is RsaSsaPkcs1v15 && hashAlgorithm == other.hashAlgorithm;
bool operator ==(other) => other is RsaSsaPkcs1v15 && hashAlgorithm == other.hashAlgorithm;

@override
Future<RsaKeyPair> newKeyPair({
Expand Down Expand Up @@ -2107,7 +2092,7 @@ abstract class StreamingCipher extends Cipher {
/// Constructor for subclasses.
///
/// Optional parameter [random] is used by [newSecretKey] and [newNonce].
const StreamingCipher({Random? random}) : super(random: random);
const StreamingCipher({super.random});

/// Decrypts a ciphertext.
///
Expand Down Expand Up @@ -2231,7 +2216,7 @@ abstract class Xchacha20 extends StreamingCipher {
}

/// Constructor for classes that extend this class.
const Xchacha20.constructor({Random? random}) : super(random: random);
const Xchacha20.constructor({super.random});

/// _XAEAD_CHACHA20_POLY1305_ ([draft-irtf-cfrg-xchacha](https://tools.ietf.org/html/draft-arciszewski-xchacha-03)) cipher.
///
Expand All @@ -2251,8 +2236,7 @@ abstract class Xchacha20 extends StreamingCipher {
int get secretKeyLength => 32;

@override
bool operator ==(other) =>
other is Xchacha20 && macAlgorithm == other.macAlgorithm;
bool operator ==(other) => other is Xchacha20 && macAlgorithm == other.macAlgorithm;

@override
String toString() {
Expand Down
Loading