Skip to content

Commit ecb226f

Browse files
authored
Merge pull request #130 from preuss-adam/apreuss/reduce-dependencies
Reduce/change 3rd party dependencies
2 parents f43938f + 9340b20 commit ecb226f

45 files changed

Lines changed: 1857 additions & 2045 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
<protobuf.version>3.25.5</protobuf.version>
3737
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
3838
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
39-
<vavr.version>0.10.3</vavr.version>
4039
<re2j.version>1.6</re2j.version>
41-
<gson.version>2.8.9</gson.version>
40+
<jackson.version>2.17.3</jackson.version>
4241
<bcprov.version>1.80</bcprov.version>
4342

4443
<!-- test dependencies -->
@@ -285,20 +284,15 @@
285284
<artifactId>protobuf-java</artifactId>
286285
<version>${protobuf.version}</version>
287286
</dependency>
288-
<dependency>
289-
<groupId>io.vavr</groupId>
290-
<artifactId>vavr</artifactId>
291-
<version>${vavr.version}</version>
292-
</dependency>
293287
<dependency>
294288
<groupId>com.google.re2j</groupId>
295289
<artifactId>re2j</artifactId>
296290
<version>${re2j.version}</version>
297291
</dependency>
298292
<dependency>
299-
<groupId>com.google.code.gson</groupId>
300-
<artifactId>gson</artifactId>
301-
<version>${gson.version}</version>
293+
<groupId>com.fasterxml.jackson.core</groupId>
294+
<artifactId>jackson-databind</artifactId>
295+
<version>${jackson.version}</version>
302296
</dependency>
303297
<dependency>
304298
<groupId>org.bouncycastle</groupId>

src/main/java/org/eclipse/biscuit/crypto/BlockSignatureBuffer.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55

66
package org.eclipse.biscuit.crypto;
77

8-
import static io.vavr.API.Left;
9-
import static io.vavr.API.Right;
10-
118
import biscuit.format.schema.Schema;
12-
import io.vavr.control.Either;
139
import java.nio.ByteBuffer;
1410
import java.nio.ByteOrder;
1511
import java.nio.charset.StandardCharsets;
1612
import java.util.Optional;
1713
import java.util.stream.Stream;
1814
import org.eclipse.biscuit.error.Error;
15+
import org.eclipse.biscuit.error.Result;
1916
import org.eclipse.biscuit.token.format.ExternalSignature;
2017
import org.eclipse.biscuit.token.format.SerializedBiscuit;
2118
import org.eclipse.biscuit.token.format.SignedBlock;
@@ -59,21 +56,21 @@ public static int blockSignatureVersion(
5956
return previousSigVersions.mapToInt(Integer::intValue).max().orElse(0);
6057
}
6158

62-
public static Either<Error.FormatError, byte[]> generateBlockSignaturePayload(
59+
public static Result<byte[], Error.FormatError> generateBlockSignaturePayload(
6360
byte[] payload,
6461
PublicKey nextKey,
6562
Optional<ExternalSignature> externalSignature,
6663
Optional<byte[]> previousSignature,
6764
int version) {
6865
switch (version) {
6966
case 0:
70-
return Right(generateBlockSignaturePayloadV0(payload, nextKey, externalSignature));
67+
return Result.ok(generateBlockSignaturePayloadV0(payload, nextKey, externalSignature));
7168
case 1:
72-
return Right(
69+
return Result.ok(
7370
generateBlockSignaturePayloadV1(
7471
payload, nextKey, externalSignature, previousSignature, version));
7572
default:
76-
return Left(
73+
return Result.err(
7774
new Error.FormatError.DeserializationError("unsupported block version " + version));
7875
}
7976
}

src/main/java/org/eclipse/biscuit/crypto/KeyDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package org.eclipse.biscuit.crypto;
77

8-
import io.vavr.control.Option;
8+
import java.util.Optional;
99

1010
/**
1111
* Used to find the key associated with a key id
@@ -14,5 +14,5 @@
1414
* time. Tokens can carry a root key id, that can be used to indicate which key will verify it.
1515
*/
1616
public interface KeyDelegate {
17-
Option<PublicKey> getRootKey(Option<Integer> keyId);
17+
Optional<PublicKey> getRootKey(Optional<Integer> keyId);
1818
}

src/main/java/org/eclipse/biscuit/crypto/Token.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
package org.eclipse.biscuit.crypto;
77

8-
import static io.vavr.API.Left;
9-
import static io.vavr.API.Right;
10-
11-
import io.vavr.control.Either;
128
import java.security.InvalidKeyException;
139
import java.security.NoSuchAlgorithmException;
1410
import java.security.SignatureException;
1511
import java.util.ArrayList;
1612
import java.util.Optional;
1713
import org.eclipse.biscuit.error.Error;
14+
import org.eclipse.biscuit.error.Result;
1815

1916
class Token {
2017
private final ArrayList<byte[]> blocks;
@@ -65,7 +62,7 @@ Token append(KeyPair keyPair, byte[] message)
6562
}
6663

6764
// FIXME: rust version returns a Result<(), error::Signature>
68-
public Either<Error, Void> verify(PublicKey root)
65+
public Result<Void, Error> verify(PublicKey root)
6966
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
7067
PublicKey currentKey = root;
7168
for (int i = 0; i < this.blocks.size(); i++) {
@@ -78,16 +75,16 @@ public Either<Error, Void> verify(PublicKey root)
7875
if (currentKey.verify(payload, signature)) {
7976
currentKey = nextKey;
8077
} else {
81-
return Left(
78+
return Result.err(
8279
new Error.FormatError.Signature.InvalidSignature(
8380
"signature error: Verification equation was not satisfied"));
8481
}
8582
}
8683

8784
if (this.next.getPublicKey().equals(currentKey)) {
88-
return Right(null);
85+
return Result.ok(null);
8986
} else {
90-
return Left(
87+
return Result.err(
9188
new Error.FormatError.Signature.InvalidSignature(
9289
"signature error: Verification equation was not satisfied"));
9390
}

src/main/java/org/eclipse/biscuit/datalog/Check.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
package org.eclipse.biscuit.datalog;
77

88
import static biscuit.format.schema.Schema.CheckV2.Kind.All;
9-
import static io.vavr.API.Left;
10-
import static io.vavr.API.Right;
119

1210
import biscuit.format.schema.Schema;
13-
import io.vavr.control.Either;
1411
import java.util.ArrayList;
1512
import java.util.List;
1613
import java.util.Objects;
1714
import org.eclipse.biscuit.error.Error;
15+
import org.eclipse.biscuit.error.Result;
1816

1917
public final class Check {
2018
public enum Kind {
@@ -59,7 +57,7 @@ public Schema.CheckV2 serialize() {
5957
return b.build();
6058
}
6159

62-
public static Either<Error.FormatError, Check> deserializeV2(Schema.CheckV2 check) {
60+
public static Result<Check, Error.FormatError> deserializeV2(Schema.CheckV2 check) {
6361
ArrayList<Rule> queries = new ArrayList<>();
6462

6563
Kind kind;
@@ -76,16 +74,15 @@ public static Either<Error.FormatError, Check> deserializeV2(Schema.CheckV2 chec
7674
}
7775

7876
for (Schema.RuleV2 query : check.getQueriesList()) {
79-
Either<Error.FormatError, Rule> res = Rule.deserializeV2(query);
80-
if (res.isLeft()) {
81-
Error.FormatError e = res.getLeft();
82-
return Left(e);
77+
var res = Rule.deserializeV2(query);
78+
if (res.isErr()) {
79+
return Result.err(res.getErr());
8380
} else {
84-
queries.add(res.get());
81+
queries.add(res.getOk());
8582
}
8683
}
8784

88-
return Right(new Check(kind, queries));
85+
return Result.ok(new Check(kind, queries));
8986
}
9087

9188
@Override

src/main/java/org/eclipse/biscuit/datalog/Combinator.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@
55

66
package org.eclipse.biscuit.datalog;
77

8-
import io.vavr.Tuple2;
9-
import io.vavr.control.Option;
108
import java.io.Serializable;
119
import java.util.HashSet;
1210
import java.util.Iterator;
1311
import java.util.List;
1412
import java.util.Map;
1513
import java.util.NoSuchElementException;
14+
import java.util.Optional;
1615
import java.util.Set;
1716
import java.util.function.Supplier;
1817
import java.util.stream.Stream;
1918

20-
public final class Combinator implements Serializable, Iterator<Tuple2<Origin, Map<Long, Term>>> {
19+
public final class Combinator implements Serializable, Iterator<Pair<Origin, Map<Long, Term>>> {
2120
private MatchedVariables variables;
22-
private final Supplier<Stream<Tuple2<Origin, Fact>>> allFacts;
21+
private final Supplier<Stream<Pair<Origin, Fact>>> allFacts;
2322
private final List<Predicate> predicates;
24-
private final Iterator<Tuple2<Origin, Fact>> currentFacts;
23+
private final Iterator<Pair<Origin, Fact>> currentFacts;
2524
private Combinator currentIt;
2625
private final SymbolTable symbolTable;
2726

2827
private Origin currentOrigin;
2928

30-
private Option<Tuple2<Origin, Map<Long, Term>>> nextElement;
29+
private Optional<Pair<Origin, Map<Long, Term>>> nextElement;
3130

3231
@Override
3332
public boolean hasNext() {
34-
if (this.nextElement != null && this.nextElement.isDefined()) {
33+
if (this.nextElement != null && this.nextElement.isPresent()) {
3534
return true;
3635
}
3736
this.nextElement = getNext();
38-
return this.nextElement.isDefined();
37+
return this.nextElement.isPresent();
3938
}
4039

4140
@Override
42-
public Tuple2<Origin, Map<Long, Term>> next() {
43-
if (this.nextElement == null || !this.nextElement.isDefined()) {
41+
public Pair<Origin, Map<Long, Term>> next() {
42+
if (this.nextElement == null || !this.nextElement.isPresent()) {
4443
this.nextElement = getNext();
4544
}
46-
if (this.nextElement == null || !this.nextElement.isDefined()) {
45+
if (this.nextElement == null || !this.nextElement.isPresent()) {
4746
throw new NoSuchElementException();
4847
} else {
49-
Tuple2<Origin, Map<Long, Term>> t = this.nextElement.get();
50-
this.nextElement = Option.none();
48+
Pair<Origin, Map<Long, Term>> t = this.nextElement.get();
49+
this.nextElement = Optional.empty();
5150
return t;
5251
}
5352
}
5453

55-
public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
54+
public Optional<Pair<Origin, Map<Long, Term>>> getNext() {
5655
if (this.predicates.isEmpty()) {
57-
final Option<Map<Long, Term>> vOpt = this.variables.complete();
56+
final Optional<Map<Long, Term>> vOpt = this.variables.complete();
5857
if (vOpt.isEmpty()) {
59-
return Option.none();
58+
return Optional.empty();
6059
} else {
6160
Map<Long, Term> variables = vOpt.get();
6261
// if there were no predicates,
@@ -67,7 +66,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
6766
set.add((long) 0);
6867

6968
this.variables = new MatchedVariables(set);
70-
return Option.some(new Tuple2<>(new Origin(), variables));
69+
return Optional.of(new Pair<>(new Origin(), variables));
7170
}
7271
}
7372

@@ -78,7 +77,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
7877
while (true) {
7978
// we iterate over the facts that match the current predicate
8079
if (this.currentFacts.hasNext()) {
81-
final Tuple2<Origin, Fact> t = this.currentFacts.next();
80+
final Pair<Origin, Fact> t = this.currentFacts.next();
8281
Origin currentOrigin = t._1.clone();
8382
Fact fact = t._2;
8483

@@ -111,11 +110,11 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
111110

112111
// there are no more predicates to check
113112
if (this.predicates.size() == 1) {
114-
final Option<Map<Long, Term>> vOpt = vars.complete();
113+
final Optional<Map<Long, Term>> vOpt = vars.complete();
115114
if (vOpt.isEmpty()) {
116115
continue;
117116
} else {
118-
return Option.some(new Tuple2<>(currentOrigin, vOpt.get()));
117+
return Optional.of(new Pair<>(currentOrigin, vOpt.get()));
119118
}
120119
} else {
121120
this.currentOrigin = currentOrigin;
@@ -132,20 +131,20 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
132131
break;
133132

134133
} else {
135-
return Option.none();
134+
return Optional.empty();
136135
}
137136
}
138137
}
139138

140139
if (this.currentIt == null) {
141-
return Option.none();
140+
return Optional.empty();
142141
}
143142

144-
Option<Tuple2<Origin, Map<Long, Term>>> opt = this.currentIt.getNext();
143+
Optional<Pair<Origin, Map<Long, Term>>> opt = this.currentIt.getNext();
145144

146-
if (opt.isDefined()) {
147-
Tuple2<Origin, Map<Long, Term>> t = opt.get();
148-
return Option.some(new Tuple2<>(t._1.union(currentOrigin), t._2));
145+
if (opt.isPresent()) {
146+
Pair<Origin, Map<Long, Term>> t = opt.get();
147+
return Optional.of(new Pair<>(t._1.union(currentOrigin), t._2));
149148
} else {
150149
currentOrigin = null;
151150
currentIt = null;
@@ -156,7 +155,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
156155
public Combinator(
157156
final MatchedVariables variables,
158157
final List<Predicate> predicates,
159-
Supplier<Stream<Tuple2<Origin, Fact>>> allFacts,
158+
Supplier<Stream<Pair<Origin, Fact>>> allFacts,
160159
final SymbolTable symbolTable) {
161160
this.variables = variables;
162161
this.allFacts = allFacts;

src/main/java/org/eclipse/biscuit/datalog/Fact.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55

66
package org.eclipse.biscuit.datalog;
77

8-
import static io.vavr.API.Left;
9-
import static io.vavr.API.Right;
10-
118
import biscuit.format.schema.Schema;
12-
import io.vavr.control.Either;
139
import java.io.Serializable;
1410
import java.util.List;
1511
import java.util.Objects;
1612
import org.eclipse.biscuit.error.Error;
13+
import org.eclipse.biscuit.error.Result;
1714

1815
public final class Fact implements Serializable {
1916
private final Predicate predicate;
@@ -60,13 +57,12 @@ public Schema.FactV2 serialize() {
6057
return Schema.FactV2.newBuilder().setPredicate(this.predicate.serialize()).build();
6158
}
6259

63-
public static Either<Error.FormatError, Fact> deserializeV2(Schema.FactV2 fact) {
64-
Either<Error.FormatError, Predicate> res = Predicate.deserializeV2(fact.getPredicate());
65-
if (res.isLeft()) {
66-
Error.FormatError e = res.getLeft();
67-
return Left(e);
60+
public static Result<Fact, Error.FormatError> deserializeV2(Schema.FactV2 fact) {
61+
var res = Predicate.deserializeV2(fact.getPredicate());
62+
if (res.isErr()) {
63+
return Result.err(res.getErr());
6864
} else {
69-
return Right(new Fact(res.get()));
65+
return Result.ok(new Fact(res.getOk()));
7066
}
7167
}
7268
}

src/main/java/org/eclipse/biscuit/datalog/FactSet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.eclipse.biscuit.datalog;
77

8-
import io.vavr.Tuple2;
98
import java.util.HashMap;
109
import java.util.HashSet;
1110
import java.util.Map;
@@ -71,8 +70,7 @@ public Stream stream(TrustedOrigins blockIds) {
7170
Origin o = entry.getKey();
7271
return blockIds.contains(o);
7372
})
74-
.flatMap(
75-
entry -> entry.getValue().stream().map(fact -> new Tuple2<>(entry.getKey(), fact)));
73+
.flatMap(entry -> entry.getValue().stream().map(fact -> new Pair<>(entry.getKey(), fact)));
7674
}
7775

7876
public Stream<Fact> stream() {

0 commit comments

Comments
 (0)