From ac8106476330c4b93a1ed9c763dc7cb846740cbc Mon Sep 17 00:00:00 2001
From: Marco Zanon <info@marcozanon.com>
Date: Sat, 2 Mar 2024 17:10:21 +0000
Subject: [PATCH] Renamed methods and variables.

---
 CHANGELOG                                     |  1 +
 .../macaco/licensing/MLicenseManager.java     | 60 +++++++++----------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 5ca2149..2e1eebf 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ See LICENSE for details.
 ------------------
 9.2.1 (2024-03-02)
 ------------------
+* Renamed methods and variables.
 * Added missing checks.
 * Fixed a bug which prevented full license files to be written properly.
 
diff --git a/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java b/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java
index 7969d2b..f99df29 100644
--- a/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java
+++ b/src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java
@@ -32,31 +32,31 @@ public class MLicenseManager {
 
     /* License generation. */
 
-    public static void generateFullLicense(Path privateKeyFile, Path licenseSkeletonFile, Path fullLicenseFile) throws MLicensingException {
+    public static void generateLicense(Path privateKeyFile, Path licenseSkeletonFile, Path licenseFile) throws MLicensingException {
         if (null == privateKeyFile) {
             throw new IllegalArgumentException("Invalid 'privateKeyFile': null.");
         }
         if (null == licenseSkeletonFile) {
             throw new IllegalArgumentException("Invalid 'licenseSkeletonFile': null.");
         }
-        if (null == fullLicenseFile) {
-            throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+        if (null == licenseFile) {
+            throw new IllegalArgumentException("Invalid 'licenseFile': null.");
         }
         //
         try {
             String privateKeyPemString = new String(Files.readAllBytes(privateKeyFile), MConstants.DEFAULT_CHARSET);
             String licenseSkeletonJsonString = new String(Files.readAllBytes(licenseSkeletonFile), MConstants.DEFAULT_CHARSET);
             //
-            MJsonObject fullLicense = MLicenseManager.generateFullLicense(privateKeyPemString, licenseSkeletonJsonString);
+            MJsonObject license = MLicenseManager.generateLicense(privateKeyPemString, licenseSkeletonJsonString);
             //
-            Files.write(fullLicenseFile, fullLicense.getJsonValue(true).getBytes(MConstants.DEFAULT_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
+            Files.write(licenseFile, license.getJsonValue(true).getBytes(MConstants.DEFAULT_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
         }
         catch (IOException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
     }
 
-    public static MJsonObject generateFullLicense(String privateKeyPemString, String licenseSkeletonJsonString) throws MLicensingException {
+    public static MJsonObject generateLicense(String privateKeyPemString, String licenseSkeletonJsonString) throws MLicensingException {
         if (MText.isBlank(privateKeyPemString)) {
             throw new IllegalArgumentException("Invalid 'privateKeyPemString': null or empty.");
         }
@@ -83,61 +83,61 @@ public class MLicenseManager {
             return licenseSkeleton;
         }
         catch (InvalidKeyException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
         catch (InvalidKeySpecException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
         catch (MInvalidJsonValueException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
         catch (NoSuchAlgorithmException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
         catch (SignatureException exception) {
-            throw new MLicensingException("Could not generate full license.", exception);
+            throw new MLicensingException("Could not generate license.", exception);
         }
     }
 
     /* License verification. */
 
-    public static MJsonObject verifyFullLicense(Path publicKeyFile, Path fullLicenseFile) throws MLicensingException {
+    public static MJsonObject verifyLicense(Path publicKeyFile, Path licenseFile) throws MLicensingException {
         if (null == publicKeyFile) {
             throw new IllegalArgumentException("Invalid 'publicKeyFile': null.");
         }
-        if (null == fullLicenseFile) {
-            throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+        if (null == licenseFile) {
+            throw new IllegalArgumentException("Invalid 'licenseFile': null.");
         }
         //
         try {
             String publicKeyPemString = new String(Files.readAllBytes(publicKeyFile), MConstants.DEFAULT_CHARSET);
-            String fullLicenseJsonString = new String(Files.readAllBytes(fullLicenseFile), MConstants.DEFAULT_CHARSET);
+            String licenseJsonString = new String(Files.readAllBytes(licenseFile), MConstants.DEFAULT_CHARSET);
             //
-            return MLicenseManager.verifyFullLicense(publicKeyPemString, fullLicenseJsonString);
+            return MLicenseManager.verifyLicense(publicKeyPemString, licenseJsonString);
         }
         catch (IOException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
     }
 
-    public static MJsonObject verifyFullLicense(String publicKeyPemString, String fullLicenseJsonString) throws MLicensingException {
+    public static MJsonObject verifyLicense(String publicKeyPemString, String licenseJsonString) throws MLicensingException {
         if (MText.isBlank(publicKeyPemString)) {
             throw new IllegalArgumentException("Invalid 'publicKeyPemString': null or empty.");
         }
-        if (MText.isBlank(fullLicenseJsonString)) {
-            throw new IllegalArgumentException("Invalid 'fullLicenseJsonString': null or empty.");
+        if (MText.isBlank(licenseJsonString)) {
+            throw new IllegalArgumentException("Invalid 'licenseJsonString': null or empty.");
         }
         //
         try {
             byte[] publicKeyContent = Base64.getDecoder().decode(publicKeyPemString.replace("-----BEGIN PUBLIC KEY-----", "").replaceAll("\\R", "").replace("-----END PUBLIC KEY-----", ""));
             RSAPublicKey publicKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyContent));
             //
-            MJsonObject fullLicense = new MJsonObject(fullLicenseJsonString);
+            MJsonObject license = new MJsonObject(licenseJsonString);
             //
-            MJsonObject licenseData = (MJsonObject)fullLicense.getValue("licenseData");
+            MJsonObject licenseData = (MJsonObject)license.getValue("licenseData");
             byte[] licenseDataHashContent = MessageDigest.getInstance("SHA-256").digest(licenseData.getJsonValue().getBytes(MConstants.DEFAULT_CHARSET));
             //
-            MJsonString licenseDataSignature = (MJsonString)fullLicense.getValue("licenseDataSignature");
+            MJsonString licenseDataSignature = (MJsonString)license.getValue("licenseDataSignature");
             byte[] licenseDataSignatureContent = Base64.getDecoder().decode(licenseDataSignature.getValue());
             //
             Signature signature = Signature.getInstance("SHA256withRSA");
@@ -145,22 +145,22 @@ public class MLicenseManager {
             signature.update(licenseDataHashContent);
             signature.verify(licenseDataSignatureContent);
             //
-            return fullLicense;
+            return license;
         }
         catch (InvalidKeyException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
         catch (InvalidKeySpecException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
         catch (MInvalidJsonValueException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
         catch (NoSuchAlgorithmException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
         catch (SignatureException exception) {
-            throw new MLicensingException("Could not verify full license.", exception);
+            throw new MLicensingException("Could not verify license.", exception);
         }
     }
 
-- 
2.30.2