Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpubnub committed Oct 2, 2023
1 parent 9de18f1 commit ca15732
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions pubnub/lib/src/crypto/aesCbcCryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import 'dart:typed_data' show Uint8List;

import 'package:pubnub/core.dart';

/// AesCbcCryptor is new and enhanced cryptor to encrypt/decrypt
/// PubNub messages.
/// It's always preferred to use this cryptor instead old cryptor.
class AesCbcCryptor implements ICryptor {
CipherKey cipherKey;

Expand Down
2 changes: 2 additions & 0 deletions pubnub/lib/src/crypto/crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:pubnub/src/crypto/legacyCryptor.dart';
import 'cryptoConfiguration.dart';
import 'cryptorHeader.dart';

/// CryptoModule is responsible for encryption and decryption
/// of PubNub messages.
class CryptoModule implements ICryptoModule {
final ICryptor defaultCryptor;
List<ICryptor>? cryptors;
Expand Down
2 changes: 2 additions & 0 deletions pubnub/lib/src/crypto/cryptorHeader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert' show utf8;

import 'package:pubnub/core.dart';

/// @nodoc
class CryptorHeader {
static const SENTINEL = 'PNED';
static const LEGACY_IDENTIFIER = '';
Expand Down Expand Up @@ -49,6 +50,7 @@ class CryptorHeader {
}
}

/// @nodoc
class CryptorHeaderV1 {
static const VERSION = 1;
final String _identifier;
Expand Down
16 changes: 8 additions & 8 deletions pubnub/lib/src/crypto/legacyCryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'cryptoConfiguration.dart';
import 'encryption_mode.dart';
import 'crypto.dart';

/// Legacy cryptor exists so that SDK will be able to decrypt old contents
/// Which encrypted in past
class LegacyCryptor implements ICryptor {
final CryptoConfiguration cryptoConfiguration;
final CipherKey cipherKey;
Expand Down Expand Up @@ -44,7 +46,7 @@ class LegacyCryptor implements ICryptor {
}
}

/// Default cryptography module used in PubNub SDK.
/// Legacy CryptoModule module used in PubNub SDK when CipherKey is not provided.
class LegacyCryptoModule implements ICryptoModule {
final CryptoConfiguration defaultConfiguration;

Expand Down Expand Up @@ -155,18 +157,16 @@ class LegacyCryptoModule implements ICryptoModule {

@override
List<int> decrypt(List<int> input) {
// TODO: implement decrypt
throw UnimplementedError();
// Note: Unreachable code. Till the time legacy encryption supported.
return List.empty();
}

@override
List<int> encrypt(List<int> input) {
// TODO: implement encrypt
throw UnimplementedError();
// Note: Unreachable code. Till the time legacy encryption supported.
return List.empty();
}

@override
void register(Core core) {
// TODO: implement register
}
void register(Core core) {}
}
7 changes: 1 addition & 6 deletions pubnub/test/unit/dx/file_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'package:pubnub/crypto.dart';
import 'package:test/test.dart';

import 'package:pubnub/pubnub.dart';
Expand All @@ -10,16 +9,12 @@ part 'fixtures/files.dart';
void main() {
late PubNub pubnub;
var keyset =
Keyset(subscribeKey: 'test', publishKey: 'test', uuid: UUID('test'));
Keyset(subscribeKey: 'test', publishKey: 'test', userId: UserId('test'));
group('DX [file]', () {
setUp(() {
pubnub = PubNub(
defaultKeyset: keyset,
networking: FakeNetworkingModule(),
// crypto: CryptoModule.legacyCryptoModule(CipherKey.fromUtf8('secret')),
// CryptoModule(
// defaultConfiguration:
// CryptoConfiguration(useRandomInitializationVector: false),)
);
});

Expand Down

0 comments on commit ca15732

Please sign in to comment.