From 752fd7953cbc2930ddb2656ee097d0703c2ca351 Mon Sep 17 00:00:00 2001 From: HamdaanAliQuatil Date: Wed, 8 May 2024 00:41:52 +0530 Subject: [PATCH 1/2] feat: override toString for _HmacSecretKey --- lib/src/impl_ffi/impl_ffi.hmac.dart | 5 +++++ lib/src/impl_js/impl_js.hmac.dart | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/src/impl_ffi/impl_ffi.hmac.dart b/lib/src/impl_ffi/impl_ffi.hmac.dart index d7f42282..72dfdbed 100644 --- a/lib/src/impl_ffi/impl_ffi.hmac.dart +++ b/lib/src/impl_ffi/impl_ffi.hmac.dart @@ -107,6 +107,11 @@ class _HmacSecretKey implements HmacSecretKey { _HmacSecretKey(this._keyData, this._hash); + @override + String toString() { + return 'Instance of \'HmacSecretKey\''; + } + @override Future signBytes(List data) => signStream(Stream.value(data)); diff --git a/lib/src/impl_js/impl_js.hmac.dart b/lib/src/impl_js/impl_js.hmac.dart index 770648f6..7857a71c 100644 --- a/lib/src/impl_js/impl_js.hmac.dart +++ b/lib/src/impl_js/impl_js.hmac.dart @@ -85,6 +85,11 @@ class _HmacSecretKey implements HmacSecretKey { final subtle.JSCryptoKey _key; _HmacSecretKey(this._key); + @override + String toString() { + return 'Instance of \'HmacSecretKey\''; + } + @override Future signBytes(List data) async { return await _sign(_hmacAlgorithm, _key, data); From b3dfcfed51905cef57a4309c3c406c7adcb0e615 Mon Sep 17 00:00:00 2001 From: HamdaanAliQuatil Date: Tue, 21 May 2024 22:38:38 +0530 Subject: [PATCH 2/2] feat: override toString in most Private Classes --- lib/src/impl_ffi/impl_ffi.aescbc.dart | 5 +++++ lib/src/impl_ffi/impl_ffi.aesctr.dart | 5 +++++ lib/src/impl_ffi/impl_ffi.aesgcm.dart | 5 +++++ lib/src/impl_ffi/impl_ffi.ecdh.dart | 10 ++++++++++ lib/src/impl_ffi/impl_ffi.ecdsa.dart | 10 ++++++++++ lib/src/impl_ffi/impl_ffi.hkdf.dart | 5 +++++ lib/src/impl_ffi/impl_ffi.pbkdf2.dart | 5 +++++ lib/src/impl_ffi/impl_ffi.rsaoaep.dart | 10 ++++++++++ lib/src/impl_ffi/impl_ffi.rsapss.dart | 10 ++++++++++ lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart | 5 +++++ lib/src/impl_js/impl_js.aescbc.dart | 5 +++++ lib/src/impl_js/impl_js.aesctr.dart | 5 +++++ lib/src/impl_js/impl_js.aesgcm.dart | 5 +++++ lib/src/impl_js/impl_js.ecdh.dart | 10 ++++++++++ lib/src/impl_js/impl_js.ecdsa.dart | 10 ++++++++++ lib/src/impl_js/impl_js.hkdf.dart | 5 +++++ lib/src/impl_js/impl_js.pbkdf2.dart | 5 +++++ lib/src/impl_js/impl_js.rsaoaep.dart | 10 ++++++++++ lib/src/impl_js/impl_js.rsapss.dart | 10 ++++++++++ lib/src/impl_js/impl_js.rsassapkcs1v15.dart | 5 +++++ 20 files changed, 140 insertions(+) diff --git a/lib/src/impl_ffi/impl_ffi.aescbc.dart b/lib/src/impl_ffi/impl_ffi.aescbc.dart index 777185bc..5622f3b5 100644 --- a/lib/src/impl_ffi/impl_ffi.aescbc.dart +++ b/lib/src/impl_ffi/impl_ffi.aescbc.dart @@ -97,6 +97,11 @@ class _AesCbcSecretKey implements AesCbcSecretKey { final Uint8List _key; _AesCbcSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesCbcSecretKey\''; + } + @override Future decryptBytes(List data, List iv) async => await _bufferStream(decryptStream(Stream.value(data), iv)); diff --git a/lib/src/impl_ffi/impl_ffi.aesctr.dart b/lib/src/impl_ffi/impl_ffi.aesctr.dart index df5c24af..a82aa811 100644 --- a/lib/src/impl_ffi/impl_ffi.aesctr.dart +++ b/lib/src/impl_ffi/impl_ffi.aesctr.dart @@ -204,6 +204,11 @@ class _AesCtrSecretKey implements AesCtrSecretKey { final Uint8List _key; _AesCtrSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesCtrSecretKey\''; + } + void _checkArguments( List counter, int length, diff --git a/lib/src/impl_ffi/impl_ffi.aesgcm.dart b/lib/src/impl_ffi/impl_ffi.aesgcm.dart index 81e8b59d..5adc463d 100644 --- a/lib/src/impl_ffi/impl_ffi.aesgcm.dart +++ b/lib/src/impl_ffi/impl_ffi.aesgcm.dart @@ -115,6 +115,11 @@ class _AesGcmSecretKey implements AesGcmSecretKey { final Uint8List _key; _AesGcmSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesGcmSecretKey\''; + } + @override Future decryptBytes( List data, diff --git a/lib/src/impl_ffi/impl_ffi.ecdh.dart b/lib/src/impl_ffi/impl_ffi.ecdh.dart index c7f831f2..530a7604 100644 --- a/lib/src/impl_ffi/impl_ffi.ecdh.dart +++ b/lib/src/impl_ffi/impl_ffi.ecdh.dart @@ -73,6 +73,11 @@ class _EcdhPrivateKey implements EcdhPrivateKey { _EcdhPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'EcdhPrivateKey\''; + } + @override Future deriveBits(int length, EcdhPublicKey publicKey) async { if (publicKey is! _EcdhPublicKey) { @@ -167,6 +172,11 @@ class _EcdhPublicKey implements EcdhPublicKey { _EcdhPublicKey(this._key); + @override + String toString() { + return 'Instance of \'EcdhPublicKey\''; + } + @override Future> exportJsonWebKey() async => // Neither Chrome or Firefox produces 'use': 'enc' for ECDH, we choose to diff --git a/lib/src/impl_ffi/impl_ffi.ecdsa.dart b/lib/src/impl_ffi/impl_ffi.ecdsa.dart index 8570e563..58072d85 100644 --- a/lib/src/impl_ffi/impl_ffi.ecdsa.dart +++ b/lib/src/impl_ffi/impl_ffi.ecdsa.dart @@ -185,6 +185,11 @@ class _EcdsaPrivateKey implements EcdsaPrivateKey { _EcdsaPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'EcdsaPrivateKey\''; + } + @override Future signBytes(List data, Hash hash) => signStream(Stream.value(data), hash); @@ -209,6 +214,11 @@ class _EcdsaPublicKey implements EcdsaPublicKey { _EcdsaPublicKey(this._key); + @override + String toString() { + return 'Instance of \'EcdsaPublicKey\''; + } + @override Future verifyBytes(List signature, List data, Hash hash) => verifyStream(signature, Stream.value(data), hash); diff --git a/lib/src/impl_ffi/impl_ffi.hkdf.dart b/lib/src/impl_ffi/impl_ffi.hkdf.dart index 5c1c21e6..52dcf908 100644 --- a/lib/src/impl_ffi/impl_ffi.hkdf.dart +++ b/lib/src/impl_ffi/impl_ffi.hkdf.dart @@ -24,6 +24,11 @@ class _HkdfSecretKey implements HkdfSecretKey { _HkdfSecretKey(this._key); + @override + String toString() { + return 'Instance of \'HkdfSecretKey\''; + } + @override Future deriveBits( int length, diff --git a/lib/src/impl_ffi/impl_ffi.pbkdf2.dart b/lib/src/impl_ffi/impl_ffi.pbkdf2.dart index edcdb380..153eaa26 100644 --- a/lib/src/impl_ffi/impl_ffi.pbkdf2.dart +++ b/lib/src/impl_ffi/impl_ffi.pbkdf2.dart @@ -25,6 +25,11 @@ class _Pbkdf2SecretKey implements Pbkdf2SecretKey { _Pbkdf2SecretKey(this._key); + @override + String toString() { + return 'Instance of \'Pbkdf2SecretKey\''; + } + @override Future deriveBits( int length, diff --git a/lib/src/impl_ffi/impl_ffi.rsaoaep.dart b/lib/src/impl_ffi/impl_ffi.rsaoaep.dart index 2b7dab22..bdd9c028 100644 --- a/lib/src/impl_ffi/impl_ffi.rsaoaep.dart +++ b/lib/src/impl_ffi/impl_ffi.rsaoaep.dart @@ -173,6 +173,11 @@ class _RsaOaepPrivateKey implements RsaOaepPrivateKey { _RsaOaepPrivateKey(this._key, this._hash); + @override + String toString() { + return 'Instance of \'RsaOaepPrivateKey\''; + } + @override Future decryptBytes(List data, {List? label}) async { return _rsaOaepeEncryptOrDecryptBytes( @@ -204,6 +209,11 @@ class _RsaOaepPublicKey implements RsaOaepPublicKey { _RsaOaepPublicKey(this._key, this._hash); + @override + String toString() { + return 'Instance of \'RsaOaepPublicKey\''; + } + @override Future encryptBytes(List data, {List? label}) async { return _rsaOaepeEncryptOrDecryptBytes( diff --git a/lib/src/impl_ffi/impl_ffi.rsapss.dart b/lib/src/impl_ffi/impl_ffi.rsapss.dart index ebac6a93..55ec6063 100644 --- a/lib/src/impl_ffi/impl_ffi.rsapss.dart +++ b/lib/src/impl_ffi/impl_ffi.rsapss.dart @@ -105,6 +105,11 @@ class _RsaPssPrivateKey implements RsaPssPrivateKey { _RsaPssPrivateKey(this._key, this._hash); + @override + String toString() { + return 'Instance of \'RsaPssPrivateKey\''; + } + @override Future signBytes(List data, int saltLength) { return signStream(Stream.value(data), saltLength); @@ -149,6 +154,11 @@ class _RsaPssPublicKey implements RsaPssPublicKey { _RsaPssPublicKey(this._key, this._hash); + @override + String toString() { + return 'Instance of \'RsaPssPublicKey\''; + } + @override Future verifyBytes( List signature, diff --git a/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart b/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart index e593f4cd..7e64fb43 100644 --- a/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart +++ b/lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart @@ -106,6 +106,11 @@ class _RsassaPkcs1V15PrivateKey implements RsassaPkcs1V15PrivateKey { _RsassaPkcs1V15PrivateKey(this._key, this._hash); + @override + String toString() { + return 'Instance of \'RsassaPkcs1V15PrivateKey\''; + } + @override Future signBytes(List data) => signStream(Stream.value(data)); diff --git a/lib/src/impl_js/impl_js.aescbc.dart b/lib/src/impl_js/impl_js.aescbc.dart index ce2e0b20..43f78015 100644 --- a/lib/src/impl_js/impl_js.aescbc.dart +++ b/lib/src/impl_js/impl_js.aescbc.dart @@ -51,6 +51,11 @@ class _AesCbcSecretKey implements AesCbcSecretKey { final subtle.JSCryptoKey _key; _AesCbcSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesCbcSecretKey\''; + } + @override Future decryptBytes(List data, List iv) async { return await _decrypt( diff --git a/lib/src/impl_js/impl_js.aesctr.dart b/lib/src/impl_js/impl_js.aesctr.dart index 10e13e69..17a8a53e 100644 --- a/lib/src/impl_js/impl_js.aesctr.dart +++ b/lib/src/impl_js/impl_js.aesctr.dart @@ -51,6 +51,11 @@ class _AesCtrSecretKey implements AesCtrSecretKey { final subtle.JSCryptoKey _key; _AesCtrSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesCtrSecretKey\''; + } + @override Future decryptBytes( List data, diff --git a/lib/src/impl_js/impl_js.aesgcm.dart b/lib/src/impl_js/impl_js.aesgcm.dart index 55474379..d1dae77b 100644 --- a/lib/src/impl_js/impl_js.aesgcm.dart +++ b/lib/src/impl_js/impl_js.aesgcm.dart @@ -51,6 +51,11 @@ class _AesGcmSecretKey implements AesGcmSecretKey { final subtle.JSCryptoKey _key; _AesGcmSecretKey(this._key); + @override + String toString() { + return 'Instance of \'AesGcmSecretKey\''; + } + @override Future decryptBytes( List data, diff --git a/lib/src/impl_js/impl_js.ecdh.dart b/lib/src/impl_js/impl_js.ecdh.dart index 1bea11cd..c9d732a6 100644 --- a/lib/src/impl_js/impl_js.ecdh.dart +++ b/lib/src/impl_js/impl_js.ecdh.dart @@ -128,6 +128,11 @@ class _EcdhPrivateKey implements EcdhPrivateKey { final subtle.JSCryptoKey _key; _EcdhPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'EcdhPrivateKey\''; + } + @override Future deriveBits(int length, EcdhPublicKey publicKey) async { if (publicKey is! _EcdhPublicKey) { @@ -175,6 +180,11 @@ class _EcdhPublicKey implements EcdhPublicKey { final subtle.JSCryptoKey _key; _EcdhPublicKey(this._key); + @override + String toString() { + return 'Instance of \'EcdhPublicKey\''; + } + @override Future> exportJsonWebKey() async { return await _exportJsonWebKey(_key); diff --git a/lib/src/impl_js/impl_js.ecdsa.dart b/lib/src/impl_js/impl_js.ecdsa.dart index 6912d441..2d0326b0 100644 --- a/lib/src/impl_js/impl_js.ecdsa.dart +++ b/lib/src/impl_js/impl_js.ecdsa.dart @@ -116,6 +116,11 @@ class _EcdsaPrivateKey implements EcdsaPrivateKey { final subtle.JSCryptoKey _key; _EcdsaPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'EcdsaPrivateKey\''; + } + @override Future signBytes(List data, Hash hash) async { return await _sign( @@ -148,6 +153,11 @@ class _EcdsaPublicKey implements EcdsaPublicKey { final subtle.JSCryptoKey _key; _EcdsaPublicKey(this._key); + @override + String toString() { + return 'Instance of \'EcdsaPublicKey\''; + } + @override Future verifyBytes( List signature, List data, Hash hash) async { diff --git a/lib/src/impl_js/impl_js.hkdf.dart b/lib/src/impl_js/impl_js.hkdf.dart index 9fcfb1e9..3ef8e807 100644 --- a/lib/src/impl_js/impl_js.hkdf.dart +++ b/lib/src/impl_js/impl_js.hkdf.dart @@ -35,6 +35,11 @@ class _HkdfSecretKey implements HkdfSecretKey { final subtle.JSCryptoKey _key; _HkdfSecretKey(this._key); + @override + String toString() { + return 'Instance of \'HkdfSecretKey\''; + } + @override Future deriveBits( int length, diff --git a/lib/src/impl_js/impl_js.pbkdf2.dart b/lib/src/impl_js/impl_js.pbkdf2.dart index 797c7902..b8479971 100644 --- a/lib/src/impl_js/impl_js.pbkdf2.dart +++ b/lib/src/impl_js/impl_js.pbkdf2.dart @@ -35,6 +35,11 @@ class _Pbkdf2SecretKey implements Pbkdf2SecretKey { final subtle.JSCryptoKey _key; _Pbkdf2SecretKey(this._key); + @override + String toString() { + return 'Instance of \'Pbkdf2SecretKey\''; + } + @override Future deriveBits( int length, diff --git a/lib/src/impl_js/impl_js.rsaoaep.dart b/lib/src/impl_js/impl_js.rsaoaep.dart index f0be378a..0cc42210 100644 --- a/lib/src/impl_js/impl_js.rsaoaep.dart +++ b/lib/src/impl_js/impl_js.rsaoaep.dart @@ -105,6 +105,11 @@ class _RsaOaepPrivateKey implements RsaOaepPrivateKey { final subtle.JSCryptoKey _key; _RsaOaepPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'RsaOaepPrivateKey\''; + } + @override Future decryptBytes(List data, {List? label}) async { return _decrypt( @@ -134,6 +139,11 @@ class _RsaOaepPublicKey implements RsaOaepPublicKey { final subtle.JSCryptoKey _key; _RsaOaepPublicKey(this._key); + @override + String toString() { + return 'Instance of \'RsaOaepPublicKey\''; + } + @override Future encryptBytes(List data, {List? label}) async { return _encrypt( diff --git a/lib/src/impl_js/impl_js.rsapss.dart b/lib/src/impl_js/impl_js.rsapss.dart index a6ea1f9a..daff864c 100644 --- a/lib/src/impl_js/impl_js.rsapss.dart +++ b/lib/src/impl_js/impl_js.rsapss.dart @@ -92,6 +92,11 @@ class _RsaPssPrivateKey implements RsaPssPrivateKey { final subtle.JSCryptoKey _key; _RsaPssPrivateKey(this._key); + @override + String toString() { + return 'Instance of \'RsaPssPrivateKey\''; + } + @override Future signBytes(List data, int saltLength) async { if (saltLength < 0) { @@ -129,6 +134,11 @@ class _RsaPssPublicKey implements RsaPssPublicKey { final subtle.JSCryptoKey _key; _RsaPssPublicKey(this._key); + @override + String toString() { + return 'Instance of \'RsaPssPublicKey\''; + } + @override Future verifyBytes( List signature, diff --git a/lib/src/impl_js/impl_js.rsassapkcs1v15.dart b/lib/src/impl_js/impl_js.rsassapkcs1v15.dart index 5b9ab4f5..1c7b1b6a 100644 --- a/lib/src/impl_js/impl_js.rsassapkcs1v15.dart +++ b/lib/src/impl_js/impl_js.rsassapkcs1v15.dart @@ -117,6 +117,11 @@ class _RsassaPkcs1V15PublicKey implements RsassaPkcs1V15PublicKey { final subtle.JSCryptoKey _key; _RsassaPkcs1V15PublicKey(this._key); + @override + String toString() { + return 'Instance of \'RsassaPkcs1V15PublicKey\''; + } + @override Future verifyBytes(List signature, List data) async { return await _verify(_rsassaPkcs1V15Algorithm, _key, signature, data);