Skip to content

Commit d7947f2

Browse files
committed
Rename encrypt to sign fucntion
1 parent 608e646 commit d7947f2

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

lib/cipher.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ class Cipher {
2626
}
2727
}
2828

29-
/// encrypt the data using the private key from keystore
30-
static Future<String> encrypt(String plainData) async {
31-
const String encryptTag = 'ENCRYPT';
29+
/// sign the data using the private key from keystore
30+
static Future<String> sign(String plainData) async {
31+
const String signTag = 'SIGN';
3232
try {
33-
final String encryptedData = await _channel.invokeMethod(
33+
final String signedData = await _channel.invokeMethod(
3434
describeEnum(CallMethodType.encrypt), plainData);
35-
final formatedEncryptedData = CipherUtils.removeNewLines(encryptedData);
36-
return formatedEncryptedData;
35+
final formatedSignedData = CipherUtils.removeNewLines(signedData);
36+
return formatedSignedData;
3737
} catch (exception) {
3838
throw PlatformException(
39-
code: '$_packageTag:$encryptTag',
40-
message: ExceptionMessageConstant.encryptionFailed,
39+
code: '$_packageTag:$signTag',
40+
message: ExceptionMessageConstant.signingFailed,
4141
details: exception);
4242
}
4343
}

lib/exception_message_constant.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ExceptionMessageConstant {
2-
static const encryptionFailed = 'Could not encrypt the data';
2+
static const signingFailed = 'Could not sign the data with private key';
33
static const verificationFailed =
44
'Could not verify the plainText against signature';
55
static const getPublicKeyFailed =

test/cipher_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
TestWidgetsFlutterBinding.ensureInitialized();
88

99
String defaultPublicKey = 'PUBLIC_KEY';
10-
String defaultEncrptedValue = 'ENCRYPTED-XX';
10+
String defaultEncrptedValue = 'SIGNED-XX';
1111
group(
1212
'Cipher',
1313
() {
@@ -61,29 +61,29 @@ void main() {
6161
});
6262

6363
test(
64-
'should return a valid encrypted data from platform',
64+
'should return a valid signed data from platform',
6565
() async {
6666
// when
67-
final String encrypted = await Cipher.encrypt('some data');
67+
final String signed = await Cipher.sign('some data');
6868

6969
// then
70-
expect(encrypted, 'ENCRYPTED-XX');
70+
expect(signed, 'SIGNED-XX');
7171
},
7272
);
7373

7474
test(
7575
'should return single line value when multiline value is returned',
7676
() async {
7777
// given
78-
defaultEncrptedValue = 'encryptedLine1'
79-
'encryptedLine2\nencryptedLine3';
78+
defaultEncrptedValue = 'signedLine1'
79+
'signedLine2\nsignedLine3';
8080
expect(defaultPublicKey.contains('\n'), true);
8181

8282
// when
83-
final String encrypted = await Cipher.encrypt('some data');
83+
final String signed = await Cipher.sign('some data');
8484

8585
// then
86-
expect(encrypted, 'encryptedLine1encryptedLine2encryptedLine3');
86+
expect(signed, 'signedLine1signedLine2signedLine3');
8787
},
8888
);
8989
test(
@@ -108,7 +108,7 @@ void main() {
108108
(MethodCall methodCall) async {
109109
if (methodCall.method == 'getPublicKey') {
110110
throw Exception('Error getting public key');
111-
} else if (methodCall.method == 'encrypt') {
111+
} else if (methodCall.method == 'sign') {
112112
throw Exception('Error getting public key');
113113
} else if (methodCall.method == 'verify') {
114114
throw Exception('Error in verifying');
@@ -135,17 +135,17 @@ void main() {
135135
);
136136

137137
test(
138-
'should throw exception when platform cannot encrypt data',
138+
'should throw exception when platform cannot sign data',
139139
() async {
140140
try {
141141
// when
142-
await Cipher.encrypt(null);
142+
await Cipher.sign(null);
143143
} catch (exception) {
144144
// then
145145
expect(exception.runtimeType, PlatformException);
146-
expect(exception.code, 'CIPHER:ENCRYPT');
146+
expect(exception.code, 'CIPHER:SIGN');
147147
expect(exception.message,
148-
ExceptionMessageConstant.encryptionFailed);
148+
ExceptionMessageConstant.signingFailed);
149149
}
150150
},
151151
);
@@ -164,7 +164,7 @@ void main() {
164164
}
165165
},
166166
);
167-
},
167+
}
168168
);
169169
},
170170
);

0 commit comments

Comments
 (0)