-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only needed as test dependency now
- Loading branch information
Showing
18 changed files
with
258 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.nbaars</groupId> | ||
<artifactId>paseto4j</artifactId> | ||
<version>0.0.15-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>paseto4j-commons</artifactId> | ||
<packaging>jar</packaging> | ||
<name>paseto4j-commons</name> | ||
|
||
<properties> | ||
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths> | ||
</properties> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.paseto4j.commons; | ||
|
||
public class ByteUtils { | ||
|
||
private ByteUtils() { | ||
|
||
} | ||
|
||
public static byte[] concat(byte[]... arrays) { | ||
var length = 0; | ||
|
||
for (var i = 0; i < arrays.length; i++) { | ||
length = length + arrays[i].length; | ||
} | ||
|
||
var result = new byte[length]; | ||
var end = 0; | ||
for (var i = 0; i < arrays.length; i++) { | ||
System.arraycopy(arrays[i], 0, result, end, arrays[i].length); | ||
end += arrays[i].length; | ||
} | ||
|
||
return result; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
commons/src/main/java/org/paseto4j/commons/Conditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.paseto4j.commons; | ||
|
||
public class Conditions { | ||
|
||
private Conditions() { | ||
} | ||
|
||
public static void verify(boolean expression, String errorMessage) { | ||
if (!expression) { | ||
throw new PasetoException(errorMessage); | ||
} | ||
} | ||
|
||
public static boolean isNullOrEmpty(String str) { | ||
return str == null || str.isEmpty(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
commons/src/main/java/org/paseto4j/commons/PasetoException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.paseto4j.commons; | ||
|
||
public class PasetoException extends RuntimeException { | ||
|
||
public PasetoException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
commons/src/test/java/org/paseto4j/commons/HexToBytes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.paseto4j.commons; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
public class HexToBytes { | ||
|
||
public static byte[] hexToBytes(String hex) { | ||
return BaseEncoding.base16().lowerCase().decode(hex); | ||
} | ||
|
||
public static String hexEncode(byte[] bytes) { | ||
return BaseEncoding.base16().lowerCase().encode(bytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.