Skip to content

Commit 5cf5f4a

Browse files
committed
Cleaning up sonar issues
1 parent 299e82e commit 5cf5f4a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

lib/mcapi/crypto/crypto.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,7 @@ function Crypto(config) {
1818
this.encryptionCertificate = readPublicCertificate(config.encryptionCertificate);
1919

2020
// Load private key (for decryption)
21-
if (config.privateKey) {
22-
this.privateKey = loadPrivateKey(config.privateKey);
23-
} else if (config.keyStore) {
24-
if(config.keyStore.includes(".p12")) {
25-
this.privateKey = getPrivateKey12(config.keyStore, config.keyStoreAlias, config.keyStorePassword);
26-
}
27-
if(config.keyStore.includes(".pem")) {
28-
this.privateKey = getPrivateKeyPem(config.keyStore);
29-
}
30-
if(config.keyStore.includes(".der")) {
31-
this.privateKey = getPrivateKeyDer(config.keyStore);
32-
}
33-
}
34-
35-
21+
this.privateKey = getPrivateKey(config)
3622

3723
this.encoding = config.dataEncoding;
3824

@@ -203,6 +189,26 @@ function readPublicCertificate(publicCertificatePath) {
203189
return forge.pki.certificateFromPem(certificateContent);
204190
}
205191

192+
/**
193+
* @private
194+
*/
195+
function getPrivateKey(config) {
196+
if (config.privateKey) {
197+
return loadPrivateKey(config.privateKey);
198+
} else if (config.keyStore) {
199+
if (config.keyStore.includes(".p12")) {
200+
return getPrivateKey12(config.keyStore, config.keyStoreAlias, config.keyStorePassword);
201+
}
202+
if (config.keyStore.includes(".pem")) {
203+
return getPrivateKeyPem(config.keyStore);
204+
}
205+
if (config.keyStore.includes(".der")) {
206+
return getPrivateKeyDer(config.keyStore);
207+
}
208+
}
209+
return null
210+
}
211+
206212
/**
207213
* @private
208214
*/
@@ -240,7 +246,6 @@ function getPrivateKey12(p12Path, alias, password) {
240246
return keyObj.key;
241247
}
242248

243-
244249
/**
245250
* @private
246251
*/

0 commit comments

Comments
 (0)