Skip to content

Commit 8d86dfe

Browse files
committed
Implemented ECEIS.
1 parent 9977995 commit 8d86dfe

File tree

13 files changed

+760
-42
lines changed

13 files changed

+760
-42
lines changed

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ dependencies {
1818
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.62'
1919
implementation group: 'org.bouncycastle', name: 'bcpg-jdk15on', version: '1.62'
2020

21-
implementation group: 'com.github.softwareverde', name: 'java-util', version: 'v2.1.0'
21+
implementation group: 'com.github.softwareverde', name: 'java-util', version: 'v2.1.3'
2222
implementation group: 'com.github.softwareverde', name: 'java-logging', version: 'v2.1.0'
2323

2424
implementation group: 'commons-codec', name: 'commons-codec', version: '1.13'
2525

26-
testCompile group: 'junit', name: 'junit', version: '4.12'
26+
testImplementation group: 'junit', name: 'junit', version: '4.12'
2727
}
2828

2929
test {
3030
maxHeapSize = "4096m"
31-
jvmArgs "-XX:MaxPermSize=4096m"
3231
jvmArgs "-XX:MaxMetaspaceSize=4096m"
3332
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Fri May 15 17:54:33 EDT 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
13
distributionBase=GRADLE_USER_HOME
24
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS='"-Xmx64m"'
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"
@@ -66,6 +82,7 @@ esac
6682

6783
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6884

85+
6986
# Determine the Java command to use to start the JVM.
7087
if [ -n "$JAVA_HOME" ] ; then
7188
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
109126
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110127
fi
111128

112-
# For Cygwin, switch paths to Windows format before running java
113-
if $cygwin ; then
129+
# For Cygwin or MSYS, switch paths to Windows format before running java
130+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
114131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
116134
JAVACMD=`cygpath --unix "$JAVACMD"`
117135

118136
# We build the pattern for arguments to be converted via cygpath
@@ -138,19 +156,19 @@ if $cygwin ; then
138156
else
139157
eval `echo args$i`="\"$arg\""
140158
fi
141-
i=$((i+1))
159+
i=`expr $i + 1`
142160
done
143161
case $i in
144-
(0) set -- ;;
145-
(1) set -- "$args0" ;;
146-
(2) set -- "$args0" "$args1" ;;
147-
(3) set -- "$args0" "$args1" "$args2" ;;
148-
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149-
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150-
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151-
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152-
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153-
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
162+
0) set -- ;;
163+
1) set -- "$args0" ;;
164+
2) set -- "$args0" "$args1" ;;
165+
3) set -- "$args0" "$args1" "$args2" ;;
166+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154172
esac
155173
fi
156174

@@ -159,14 +177,9 @@ save () {
159177
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160178
echo " "
161179
}
162-
APP_ARGS=$(save "$@")
180+
APP_ARGS=`save "$@"`
163181

164182
# Collect all arguments for the java command, following the shell quoting and substitution rules
165183
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166184

167-
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168-
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169-
cd "$(dirname "$0")"
170-
fi
171-
172185
exec "$JAVACMD" "$@"

gradlew.bat

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
1329
set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
1635
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS="-Xmx64m"
36+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1837

1938
@rem Find java.exe
2039
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%*
6584

6685
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
6786

87+
6888
@rem Execute Gradle
6989
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
7090

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.softwareverde.security.hash.sha512;
2+
3+
import com.softwareverde.constable.Const;
4+
import com.softwareverde.logging.Logger;
5+
import com.softwareverde.security.hash.ImmutableHash;
6+
import com.softwareverde.util.ByteUtil;
7+
import com.softwareverde.util.HexUtil;
8+
9+
public class ImmutableSha512Hash extends ImmutableHash implements Sha512Hash, Const {
10+
public static ImmutableSha512Hash fromHexString(final String hexString) {
11+
if (hexString == null) { return null; }
12+
13+
final byte[] hashBytes = HexUtil.hexStringToByteArray(hexString);
14+
if (hashBytes == null) { return null; }
15+
if (hashBytes.length != BYTE_COUNT) { return null; }
16+
17+
return new ImmutableSha512Hash(hashBytes);
18+
}
19+
20+
public static ImmutableSha512Hash copyOf(final byte[] bytes) {
21+
if (bytes == null) { return null; }
22+
if (bytes.length != BYTE_COUNT) {
23+
Logger.warn("NOTICE: Unable to wrap bytes as hash. Invalid byte count: "+ bytes.length);
24+
return null;
25+
}
26+
return new ImmutableSha512Hash(bytes);
27+
}
28+
29+
protected ImmutableSha512Hash(final byte[] bytes) {
30+
super(new byte[BYTE_COUNT]);
31+
32+
if (bytes.length != BYTE_COUNT) {
33+
throw new RuntimeException("Invalid byte count: " + bytes.length);
34+
}
35+
36+
ByteUtil.setBytes(_bytes, bytes);
37+
}
38+
39+
public ImmutableSha512Hash() {
40+
super(new byte[BYTE_COUNT]);
41+
}
42+
43+
public ImmutableSha512Hash(final Sha512Hash hash) {
44+
super(hash);
45+
}
46+
47+
@Override
48+
public MutableSha512Hash toReversedEndian() {
49+
return MutableSha512Hash.wrap(ByteUtil.reverseEndian(_bytes));
50+
}
51+
52+
@Override
53+
public ImmutableSha512Hash asConst() {
54+
return this;
55+
}
56+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.softwareverde.security.hash.sha512;
2+
3+
import com.softwareverde.logging.Logger;
4+
import com.softwareverde.security.hash.MutableHash;
5+
import com.softwareverde.util.ByteUtil;
6+
import com.softwareverde.util.HexUtil;
7+
8+
public class MutableSha512Hash extends MutableHash implements Sha512Hash {
9+
public static MutableSha512Hash fromHexString(final String hexString) {
10+
if (hexString == null) { return null; }
11+
12+
final byte[] hashBytes = HexUtil.hexStringToByteArray(hexString);
13+
return MutableSha512Hash.wrap(hashBytes);
14+
}
15+
16+
public static MutableSha512Hash wrap(final byte[] bytes) {
17+
if (bytes == null) { return null; }
18+
19+
if (bytes.length != BYTE_COUNT) {
20+
Logger.warn("NOTICE: Unable to wrap bytes as hash. Invalid byte count: " + bytes.length);
21+
return null;
22+
}
23+
return new MutableSha512Hash(bytes);
24+
}
25+
26+
public static MutableSha512Hash copyOf(final byte[] bytes) {
27+
if (bytes == null) { return null; }
28+
29+
if (bytes.length != BYTE_COUNT) {
30+
Logger.warn("NOTICE: Unable to wrap bytes as hash. Invalid byte count: " + bytes.length);
31+
return null;
32+
}
33+
return new MutableSha512Hash(ByteUtil.copyBytes(bytes));
34+
}
35+
36+
protected MutableSha512Hash(final byte[] bytes) {
37+
super(bytes);
38+
39+
if (bytes.length != BYTE_COUNT) {
40+
throw new RuntimeException("Invalid byte count: " + bytes.length);
41+
}
42+
}
43+
44+
public MutableSha512Hash() {
45+
super(BYTE_COUNT);
46+
}
47+
48+
public MutableSha512Hash(final Sha512Hash hash) {
49+
super(hash);
50+
}
51+
52+
@Override
53+
public MutableSha512Hash toReversedEndian() {
54+
return MutableSha512Hash.wrap(ByteUtil.reverseEndian(_bytes));
55+
}
56+
57+
public void setBytes(final byte[] bytes) {
58+
if (bytes.length != BYTE_COUNT) {
59+
Logger.warn("NOTICE: Attempted to set hash bytes of incorrect length: " + bytes.length);
60+
return;
61+
}
62+
63+
if (_bytes.length != bytes.length) {
64+
_bytes = new byte[bytes.length];
65+
}
66+
ByteUtil.setBytes(_bytes, bytes);
67+
}
68+
69+
public void setBytes(final Sha512Hash hash) {
70+
ByteUtil.setBytes(_bytes, hash.getBytes());
71+
}
72+
73+
@Override
74+
public ImmutableSha512Hash asConst() {
75+
return new ImmutableSha512Hash(this);
76+
}
77+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.softwareverde.security.hash.sha512;
2+
3+
import com.softwareverde.security.hash.Hash;
4+
import com.softwareverde.util.ByteUtil;
5+
6+
import java.util.Comparator;
7+
8+
public interface Sha512Hash extends Hash, Comparable<Sha512Hash> {
9+
Comparator<Sha512Hash> COMPARATOR = new Comparator<Sha512Hash>() {
10+
@Override
11+
public int compare(final Sha512Hash hash0, final Sha512Hash hash1) {
12+
for (int i = 0; i < BYTE_COUNT; ++i) {
13+
final int b0 = ByteUtil.byteToInteger(hash0.getByte(i));
14+
final int b1 = ByteUtil.byteToInteger(hash1.getByte(i));
15+
16+
if (b0 < b1) { return -1; }
17+
if (b0 > b1) { return 1; }
18+
}
19+
return 0;
20+
}
21+
};
22+
23+
static Sha512Hash fromHexString(final String hexString) {
24+
return ImmutableSha512Hash.fromHexString(hexString);
25+
}
26+
27+
static Sha512Hash copyOf(final byte[] bytes) {
28+
return ImmutableSha512Hash.copyOf(bytes);
29+
}
30+
31+
static Sha512Hash wrap(final byte[] bytes) {
32+
return MutableSha512Hash.wrap(bytes);
33+
}
34+
35+
Integer BYTE_COUNT = 64;
36+
ImmutableSha512Hash EMPTY_HASH = new ImmutableSha512Hash();
37+
38+
@Override
39+
Sha512Hash toReversedEndian();
40+
41+
@Override
42+
ImmutableSha512Hash asConst();
43+
44+
@Override
45+
default int compareTo(final Sha512Hash sha512Hash) {
46+
return COMPARATOR.compare(this, sha512Hash);
47+
}
48+
}

0 commit comments

Comments
 (0)