Renamed some methods and variables.
authorMarco Zanon <info@marcozanon.com>
Sat, 2 Mar 2024 17:22:29 +0000 (17:22 +0000)
committerMarco Zanon <info@marcozanon.com>
Sat, 2 Mar 2024 17:22:29 +0000 (17:22 +0000)
CHANGELOG
src/main/java/com/marcozanon/macaco/MConstants.java
src/main/java/com/marcozanon/macaco/licensing/MLicenseManager.java

index 5ca2149bd5576da30a79706840f52dce7a448b5c..cab32f43f1110a6431c6d7b239d07bbe2a7543c3 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,11 @@ Macaco
 Copyright (c) 2009-2024 Marco Zanon <info@marcozanon.com>.
 See LICENSE for details.
 
+===================
+10.0.0 (2024-03-02)
+===================
+* Renamed some methods and variables.
+
 ------------------
 9.2.1 (2024-03-02)
 ------------------
index e3e391fcf6be26b267dd41741fa30007379c2c93..a64c57f357bf951451cb8913eb2b741c8f72fe28 100644 (file)
@@ -13,7 +13,7 @@ public class MConstants extends MObject {
 
     /* Generic information. */
 
-    public static final String MACACO_VERSION = "9.x";
+    public static final String MACACO_VERSION = "10.x";
 
     /* Environment configuration. */
 
index 7969d2bd2f31e25c7c3e3858753d45e369360e10..f99df29e0965970549cd543765048e4a717ea938 100644 (file)
@@ -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);
         }
     }