Skip to content

Commit

Permalink
Update Helpers.java
Browse files Browse the repository at this point in the history
  • Loading branch information
artemlos committed Mar 5, 2019
1 parent 18f92f3 commit 35e74f2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/io/cryptolens/methods/Helpers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cryptolens.methods;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.cryptolens.internal.BasicResult;
import io.cryptolens.models.ActivatedMachine;
import io.cryptolens.models.LicenseKey;
Expand All @@ -9,8 +11,11 @@
import oshi.hardware.HardwareAbstractionLayer;
import oshi.software.os.OperatingSystem;

import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.HashSet;

/**
* A collection of helper methods that operate on a license key.
Expand Down Expand Up @@ -194,6 +199,24 @@ public static boolean HasFeature(LicenseKey licenseKey, int feature) {
return false;
}

/**
* Use the notes field to determine if a certain feature exists (instead of the 8 feature flags).
* The notes field needs to be formatted as JSON array, eg. ["f1", "f2"] means f1 and f2 are true.
* @param licenseKey a license key object.
* @param featureName the name of the feature (case-sensitive).
* @return True if the feature exists and false otherwise.
*/
public static boolean HasFeature(LicenseKey licenseKey, String featureName) {

Type type = new TypeToken<HashSet<String>>(){}.getType();
HashSet<String> features = new Gson().fromJson(licenseKey.Notes, type);

if (features != null && features.contains(featureName)) {
return true;
}
return false;
}

/**
* Return the sha256 checksum of a string.
*/
Expand Down

0 comments on commit 35e74f2

Please sign in to comment.