Skip to content

Commit

Permalink
Merge pull request #1757 from ardriveapp/PE-6212-pass-transaction-id-…
Browse files Browse the repository at this point in the history
…on-transaction-decryption-exception-and-filter-log-if-corrupted-data-app-version-2-32-0

PE-6213: task(logging)
  • Loading branch information
thiagocarvalhodev authored May 31, 2024
2 parents c6caa68 + e7eb69d commit 3f7567e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/core/crypto/crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class ArDriveCrypto {
final cipherIvTag = transaction.getTag(EntityTag.cipherIv);

if (cipher == null || cipherIvTag == null) {
throw MissingCipherTagException();
throw MissingCipherTagException(
corruptedDataAppVersion: transaction.getTag(EntityTag.appVersion),
corruptedTransactionId: transaction.id,
);
}

final cipherIv = utils.decodeBase64ToBytes(cipherIvTag);
Expand Down Expand Up @@ -128,6 +131,7 @@ class ArDriveCrypto {
} else {
throw UnknownCipherException(
corruptedDataAppVersion: transaction.getTag(EntityTag.appVersion),
corruptedTransactionId: transaction.id,
);
}

Expand All @@ -143,6 +147,7 @@ class ArDriveCrypto {
/// Unknow error
throw TransactionDecryptionException(
corruptedDataAppVersion: transaction.getTag(EntityTag.appVersion),
corruptedTransactionId: transaction.id,
);
}
}
Expand All @@ -161,6 +166,7 @@ class ArDriveCrypto {
if (cipher == null || cipherIvTag == null) {
throw MissingCipherTagException(
corruptedDataAppVersion: transaction.getTag(EntityTag.appVersion),
corruptedTransactionId: transaction.id,
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/utils/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ final Set<String> _knownTransactionDecryptionBugVersions = {
'2.30.0',
'2.30.1',
'2.30.2',
'2.32.0',
'2.36.0',
'2.37.0',
'2.37.1'
'2.37.1',
};

ShouldLogErrorCallback shouldLogErrorCallback = (error) {
Expand Down
29 changes: 21 additions & 8 deletions packages/ardrive_crypto/lib/src/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
class ArDriveDecryptionException implements Exception {
final String? corruptedDataAppVersion;
final String? corruptedTransactionId;

ArDriveDecryptionException({this.corruptedDataAppVersion});
ArDriveDecryptionException({
this.corruptedDataAppVersion,
this.corruptedTransactionId,
});

@override
String toString() {
return 'ARFSDecryptionException: corruptedDataAppVersion: $corruptedDataAppVersion';
return 'ArDriveDecryptionException: corruptedDataAppVersion: $corruptedDataAppVersion and corruptedTransactionId: $corruptedTransactionId';
}
}

class TransactionDecryptionException extends ArDriveDecryptionException {
TransactionDecryptionException({super.corruptedDataAppVersion});
TransactionDecryptionException({
super.corruptedDataAppVersion,
super.corruptedTransactionId,
});

@override
String toString() {
return 'TransactionDecryptionException: corruptedDataAppVersion: $corruptedDataAppVersion';
return 'TransactionDecryptionException: corruptedDataAppVersion: $corruptedDataAppVersion and corruptedTransactionId: $corruptedTransactionId';
}
}

class MissingCipherTagException extends ArDriveDecryptionException {
MissingCipherTagException({super.corruptedDataAppVersion});
MissingCipherTagException({
super.corruptedDataAppVersion,
super.corruptedTransactionId,
});

@override
String toString() {
return 'MissingCipherTagException: corruptedDataAppVersion: $corruptedDataAppVersion';
return 'MissingCipherTagException: corruptedDataAppVersion: $corruptedDataAppVersion and corruptedTransactionId: $corruptedTransactionId';
}
}

class UnknownCipherException extends ArDriveDecryptionException {
UnknownCipherException({super.corruptedDataAppVersion});
UnknownCipherException({
super.corruptedDataAppVersion,
super.corruptedTransactionId,
});

@override
String toString() {
return 'UnknowCipherException: corruptedDataAppVersion: $corruptedDataAppVersion';
return 'UnknowCipherException: corruptedDataAppVersion: $corruptedDataAppVersion and corruptedTransactionId: $corruptedTransactionId';
}
}
1 change: 1 addition & 0 deletions test/utils/logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
'2.30.0',
'2.30.1',
'2.30.2',
'2.32.0',
'2.36.0',
'2.37.0',
'2.37.1'
Expand Down

0 comments on commit 3f7567e

Please sign in to comment.