+ //
/**
* Create a new binary feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -597,6 +507,7 @@ public static Feature binaryFeature(String name, byte[] value) {
/**
* Create a new string feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -608,6 +519,7 @@ public static Feature stringFeature(String name, String value) {
/**
* Create a new byte feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -619,6 +531,7 @@ public static Feature byteFeature(String name, Byte value) {
/**
* Create a new short feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -630,6 +543,7 @@ public static Feature shortFeature(String name, Short value) {
/**
* Create a new int feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -641,6 +555,7 @@ public static Feature intFeature(String name, Integer value) {
/**
* Create a new long feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -652,6 +567,7 @@ public static Feature longFeature(String name, Long value) {
/**
* Create a new float feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -663,6 +579,7 @@ public static Feature floatFeature(String name, Float value) {
/**
* Create a new double feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -674,6 +591,7 @@ public static Feature doubleFeature(String name, Double value) {
/**
* Create a new bigInteger feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -685,6 +603,7 @@ public static Feature bigIntegerFeature(String name, BigInteger value) {
/**
* Create a new uuid feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -696,6 +615,7 @@ public static Feature uuidFeature(String name, java.util.UUID value) {
/**
* Create a new date feature.
+ *
* @param name the name of the new feature
* @param value the value for the new feature. {@code null} value will throw an exception
* @return the newly created feature object
@@ -705,8 +625,8 @@ public static Feature dateFeature(String name, Date value) {
return new Feature(name, Type.DATE, ByteBuffer.allocate(Long.BYTES).putLong(value.getTime()).array());
}
+
//
- //__END__
/**
* Create a new BigDecimal feature.
@@ -719,9 +639,9 @@ public static Feature bigDecimalFeature(String name, BigDecimal value) {
Objects.requireNonNull(value);
byte[] b = value.unscaledValue().toByteArray();
return new Feature(name, Type.BIGDECIMAL, ByteBuffer.allocate(Integer.BYTES + b.length)
- .put(b)
- .putInt(value.scale())
- .array());
+ .put(b)
+ .putInt(value.scale())
+ .array());
}
/**
@@ -787,7 +707,7 @@ public static Feature from(byte[] serialized) {
public static void throwBinaryWayTooShort(int len) {
throw new IllegalArgumentException("Cannot load feature from a byte array that has "
- + len + " bytes which is < " + (2 * Integer.BYTES));
+ + len + " bytes which is < " + (2 * Integer.BYTES));
}
public static void throwBinaryTooShort(int len) {
@@ -796,7 +716,7 @@ public static void throwBinaryTooShort(int len) {
public static void throwBinaryTooLong(int len, int extra) {
throw new IllegalArgumentException("Cannot load feature from a byte array that has "
- + len + " bytes which is " + extra + " bytes too long");
+ + len + " bytes which is " + extra + " bytes too long");
}
public static void throwBinaryTooLong(String s) {
diff --git a/src/main/java/javax0/license3j/crypto/LicenseKeyPair.java b/src/main/java/javax0/license3j/crypto/LicenseKeyPair.java
index fb32d94..3c886e9 100644
--- a/src/main/java/javax0/license3j/crypto/LicenseKeyPair.java
+++ b/src/main/java/javax0/license3j/crypto/LicenseKeyPair.java
@@ -2,13 +2,7 @@
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
+import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
@@ -53,31 +47,11 @@ public KeyPair getPair() {
return pair;
}
- /*!jamal
- //
- {%!@for ($Type) in (Public,Private)=
- /**
- * Get the byte representation of the {%@case:lower $Type%} key as it is returned
- * by the underlying security library. This is NOT the byte array
- * that contains the algorithm at the start. This is the key in raw
- * format.
- *
- * @return the key as bytes
- *{%@comment%}/
- public byte[] get$Type() {
- keyNotNull(pair.get$Type());
- final var key = pair.get$Type();
- return getKeyBytes(key);
- }
- %}
- //
- */
- //
-
- /**
+ //
+ /**GENERATED CODE
* Get the byte representation of the public key as it is returned
- * by the underlying security library. This is NOT the byte array
- * that contains the algorithm at the start. This is the key in raw
+ * by the underlying security library. It is NOT the byte array
+ * that contains the algorithm at the start. It is the key in raw
* format.
*
* @return the key as bytes
@@ -87,11 +61,10 @@ public byte[] getPublic() {
final var key = pair.getPublic();
return getKeyBytes(key);
}
-
- /**
+ /**GENERATED CODE
* Get the byte representation of the private key as it is returned
- * by the underlying security library. This is NOT the byte array
- * that contains the algorithm at the start. This is the key in raw
+ * by the underlying security library. It is NOT the byte array
+ * that contains the algorithm at the start. It is the key in raw
* format.
*
* @return the key as bytes
@@ -102,8 +75,9 @@ public byte[] getPrivate() {
return getKeyBytes(key);
}
- //
- //__END__
+
+//
+
private byte[] getKeyBytes(final Key key) {
final var algorithm = cipherTransformation.getBytes(StandardCharsets.UTF_8);
@@ -148,7 +122,7 @@ public static LicenseKeyPair from(final KeyPair keyPair, final String cipher) {
private static String algorithmPrefix(final String cipher) {
if (cipher.contains("/")) {
- return cipher .substring(0, cipher.indexOf("/"));
+ return cipher.substring(0, cipher.indexOf("/"));
} else {
return cipher;
}
@@ -157,7 +131,7 @@ private static String algorithmPrefix(final String cipher) {
/**
* Create a new key pair using the algorithm and the size for the key. The cipher transformation may optionally
* contain the mode and the padding as {@code algorithm/mode/padding}. Note that the mode and the padding is
- * not needed for the key generation. Nevertheless these are also stored in the generated {@link LicenseKeyPair}
+ * not needed for the key generation. Nevertheless, these are also stored in the generated {@link LicenseKeyPair}
* and will be used to sign/verify the license.
*
* It is recommended to use the full cipher. Using only the algorithm will let the encryption provider to
@@ -181,16 +155,17 @@ public static LicenseKeyPair from(final String cipher, final int size) throws No
/**
* Create a new {@link LicenseKeyPair} that contains only one of the keys, either the private or the public.
* The key is provided in binary format as a byte array.
+ *
* @param encoded the key encoded as byte array. This is the format that contains the algorithm at the start
* of the byte array as zero byte terminated string.
- * @param type either 1 for public key specification or 2 for private key specification. These commands are
- * defined in the JDK in the {@link Modifier} class as {@link Modifier#PUBLIC} and
- * {@link Modifier#PRIVATE}.
+ * @param type either 1 for public key specification or 2 for private key specification. These commands are
+ * defined in the JDK in the {@link Modifier} class as {@link Modifier#PUBLIC} and
+ * {@link Modifier#PRIVATE}.
* @return the newly created {@link LicenseKeyPair}
* @throws NoSuchAlgorithmException if the algorithm in the encoded key is not implemented by the actual
- * encryption provider
- * @throws InvalidKeySpecException if the bytes of the key are garbage and cannot be decoded by the actual
- * encryption provider.
+ * encryption provider
+ * @throws InvalidKeySpecException if the bytes of the key are garbage and cannot be decoded by the actual
+ * encryption provider.
*/
public static LicenseKeyPair from(final byte[] encoded, final int type) throws NoSuchAlgorithmException, InvalidKeySpecException {
final String cipher = getCipher(encoded);
@@ -202,18 +177,19 @@ public static LicenseKeyPair from(final byte[] encoded, final int type) throws N
/**
* Create a new {@link LicenseKeyPair} from the public and the private key pairs.
- *
- * The method does not check that the encoded cipher specification at the start of the keys are the same or not.
+ *
+ * The method does not check that the encoded cipher specification at the start of the keys is the same or not.
* They are supposed to be the same. There is also no check that the private and the public key are a pair.
+ *
* @param privateEncoded the private key encoded including the cipher specification with a zero byte
* terminated at the start of the byte array
- * @param publicEncoded the public key encoded including the cipher specification with a zero byte
- * terminated at the start of the byte array
+ * @param publicEncoded the public key encoded including the cipher specification with a zero byte
+ * terminated at the start of the byte array
* @return the newly created {@link LicenseKeyPair}
* @throws NoSuchAlgorithmException if the algorithm in the encoded key is not implemented by the actual
- * encryption provider
- * @throws InvalidKeySpecException if the bytes of the key are garbage and cannot be decoded by the actual
- * encryption provider.
+ * encryption provider
+ * @throws InvalidKeySpecException if the bytes of the key are garbage and cannot be decoded by the actual
+ * encryption provider.
*/
public static LicenseKeyPair from(final byte[] privateEncoded, final byte[] publicEncoded) throws NoSuchAlgorithmException, InvalidKeySpecException {
final String cipher = getCipher(publicEncoded);
diff --git a/src/main/java/javax0/license3j/hardware/Network.java b/src/main/java/javax0/license3j/hardware/Network.java
index b87feb8..af7d1e2 100644
--- a/src/main/java/javax0/license3j/hardware/Network.java
+++ b/src/main/java/javax0/license3j/hardware/Network.java
@@ -1,5 +1,6 @@
package javax0.license3j.hardware;
+import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
@@ -16,50 +17,37 @@ private NetworkInterface(java.net.NetworkInterface ni) {
this.ni = ni;
}
- /*!jamal
- {%!@for [separator="\\s*\n\\s*" skipEmpty]($rettype,$name,$exceptions) in
- `LOOP`
- String|getName|
- byte[]|getHardwareAddress|SocketException
- String|getDisplayName|
- boolean|isLoopback|SocketException
- boolean|isVirtual|SocketException
- boolean|isPointToPoint|SocketException
- `LOOP`=
- public $rettype $name(){%#if/$exceptions/ throws $exceptions/%}{
- return ni.$name();
- }
- %}
- */
-
- public String getName(){
+ //
+
+ public String getName() {
return ni.getName();
- }
-
- public byte[] getHardwareAddress() throws SocketException{
+ }
+
+ public byte[] getHardwareAddress() throws SocketException {
return ni.getHardwareAddress();
- }
-
- public String getDisplayName(){
+ }
+
+ public String getDisplayName() {
return ni.getDisplayName();
- }
-
- public boolean isLoopback() throws SocketException{
+ }
+
+ public boolean isLoopback() throws SocketException {
return ni.isLoopback();
- }
-
- public boolean isVirtual() throws SocketException{
+ }
+
+ public boolean isVirtual() throws SocketException {
return ni.isVirtual();
- }
-
- public boolean isPointToPoint() throws SocketException{
+ }
+
+ public boolean isPointToPoint() throws SocketException {
return ni.isPointToPoint();
- }
+ }
+
- //__END__
+ //
public static Enumeration getNetworkInterfaces()
- throws SocketException {
+ throws SocketException {
return Collections.enumeration(Collections.list(java.net.NetworkInterface.getNetworkInterfaces()).stream().map(ni -> new NetworkInterface(ni)).collect(Collectors.toList()));
}
}
@@ -80,8 +68,8 @@ private Data(final NetworkInterface networkInterface) {
static Stream gatherUsing(Network.Interface.Selector selector) throws SocketException {
return Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
- .filter(selector::usable)
- .map(Network.Interface.Data::new);
+ .filter(selector::usable)
+ .map(Network.Interface.Data::new);
}
}
@@ -128,9 +116,9 @@ private boolean matchesRegexLists(final NetworkInterface netIf) {
final String name = netIf.getDisplayName();
return !matchesAny(name, deniedInterfaceNames)
- &&
- (allowedInterfaceNames.isEmpty() ||
- matchesAny(name, allowedInterfaceNames));
+ &&
+ (allowedInterfaceNames.isEmpty() ||
+ matchesAny(name, allowedInterfaceNames));
}
/**
@@ -165,7 +153,7 @@ public void interfaceDenied(String regex) {
*/
boolean usable(final NetworkInterface netIf) {
return !isSpecial(netIf)
- && matchesRegexLists(netIf);
+ && matchesRegexLists(netIf);
}
/**