Skip to content

Commit 3994d45

Browse files
committed
Review Feedback
1 parent 6b7cb9c commit 3994d45

39 files changed

+378
-387
lines changed

src/main/java/org/biscuitsec/biscuit/crypto/PublicKey.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public PublicKey(Algorithm algorithm, String hex) {
4747
}
4848

4949
public byte[] toBytes() {
50-
if (getAlgorithm() == Algorithm.Ed25519) {
50+
if (this.algorithm == Algorithm.Ed25519) {
5151
return ((EdDSAPublicKey) getKey()).getAbyte();
52-
} else if (getAlgorithm() == Algorithm.SECP256R1) {
52+
} else if (this.algorithm == Algorithm.SECP256R1) {
5353
return ((BCECPublicKey) getKey()).getQ().getEncoded(true); // true = compressed
5454
} else {
5555
throw new IllegalArgumentException("Invalid algorithm");
@@ -60,11 +60,10 @@ public String toHex() {
6060
return Utils.byteArrayToHexString(this.toBytes());
6161
}
6262

63-
6463
public Schema.PublicKey serialize() {
6564
Schema.PublicKey.Builder publicKey = Schema.PublicKey.newBuilder();
6665
publicKey.setKey(ByteString.copyFrom(this.toBytes()));
67-
publicKey.setAlgorithm(this.getAlgorithm());
66+
publicKey.setAlgorithm(this.algorithm);
6867
return publicKey.build();
6968
}
7069

@@ -105,7 +104,7 @@ public boolean equals(Object o) {
105104

106105
PublicKey publicKey = (PublicKey) o;
107106

108-
return getKey().equals(publicKey.getKey());
107+
return this.key.equals(publicKey.getKey());
109108
}
110109

111110
@Override
@@ -115,20 +114,20 @@ public int hashCode() {
115114

116115
@Override
117116
public String toString() {
118-
if (getAlgorithm() == Algorithm.Ed25519) {
117+
if (this.algorithm == Algorithm.Ed25519) {
119118
return "ed25519/" + toHex().toLowerCase();
120-
} else if (getAlgorithm() == Algorithm.SECP256R1) {
119+
} else if (this.algorithm == Algorithm.SECP256R1) {
121120
return "secp256r1/" + toHex().toLowerCase();
122121
} else {
123122
return null;
124123
}
125124
}
126125

127126
public java.security.PublicKey getKey() {
128-
return key;
127+
return this.key;
129128
}
130129

131130
public Algorithm getAlgorithm() {
132-
return algorithm;
131+
return this.algorithm;
133132
}
134133
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
public final class Check {
1515
public enum Kind {
16-
One,
17-
All
16+
ONE,
17+
ALL
1818
}
1919

2020
private static final int HASH_CODE_SEED = 31;
@@ -41,7 +41,7 @@ public Schema.CheckV2 serialize() {
4141

4242
// do not set the kind to One to keep compatibility with older library versions
4343
switch (this.kind) {
44-
case All:
44+
case ALL:
4545
b.setKind(All);
4646
break;
4747
default:
@@ -60,13 +60,13 @@ public static Either<Error.FormatError, Check> deserializeV2(Schema.CheckV2 chec
6060
Kind kind;
6161
switch (check.getKind()) {
6262
case One:
63-
kind = Kind.One;
63+
kind = Kind.ONE;
6464
break;
6565
case All:
66-
kind = Kind.All;
66+
kind = Kind.ALL;
6767
break;
6868
default:
69-
kind = Kind.One;
69+
kind = Kind.ONE;
7070
break;
7171
}
7272

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Combinator implements Serializable, Iterator<Tuple2<Origin, M
1818
private final List<Predicate> predicates;
1919
private final Iterator<Tuple2<Origin, Fact>> currentFacts;
2020
private Combinator currentIt;
21-
private final SymbolTable symbols;
21+
private final SymbolTable symbolTable;
2222

2323
private Origin currentOrigin;
2424

@@ -119,7 +119,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
119119
// no need to copy all the expressions at all levels
120120
this.currentIt =
121121
new Combinator(
122-
vars, predicates.subList(1, predicates.size()), this.allFacts, this.symbols);
122+
vars, predicates.subList(1, predicates.size()), this.allFacts, this.symbolTable);
123123
}
124124
break;
125125

@@ -149,14 +149,14 @@ public Combinator(
149149
final MatchedVariables variables,
150150
final List<Predicate> predicates,
151151
Supplier<Stream<Tuple2<Origin, Fact>>> allFacts,
152-
final SymbolTable symbols) {
152+
final SymbolTable symbolTable) {
153153
this.variables = variables;
154154
this.allFacts = allFacts;
155155
this.currentIt = null;
156156
this.predicates = predicates;
157157
this.currentFacts =
158158
allFacts.get().filter((tuple) -> tuple._2.matchPredicate(predicates.get(0))).iterator();
159-
this.symbols = symbols;
159+
this.symbolTable = symbolTable;
160160
this.currentOrigin = null;
161161
this.nextElement = null;
162162
}

src/main/java/org/biscuitsec/biscuit/datalog/MatchedVariables.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public MatchedVariables(final Set<Long> ids) {
6464
}
6565
}
6666

67-
public Option<Map<Long, Term>> checkExpressions(List<Expression> expressions, SymbolTable symbols)
67+
public Option<Map<Long, Term>> checkExpressions(List<Expression> expressions, SymbolTable symbolTable)
6868
throws Error {
6969
final Option<Map<Long, Term>> vars = this.complete();
7070
if (vars.isDefined()) {
7171
Map<Long, Term> variables = vars.get();
7272

7373
for (Expression e : expressions) {
74-
Term term = e.evaluate(variables, new TemporarySymbolTable(symbols));
74+
Term term = e.evaluate(variables, new TemporarySymbolTable(symbolTable));
7575

7676
if (!(term instanceof Term.Bool)) {
7777
throw new Error.InvalidType();

src/main/java/org/biscuitsec/biscuit/datalog/Rule.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public List<Scope> scopes() {
4949
public Stream<Either<Error, Tuple2<Origin, Fact>>> apply(
5050
final Supplier<Stream<Tuple2<Origin, Fact>>> factsSupplier,
5151
Long ruleOrigin,
52-
SymbolTable symbols) {
52+
SymbolTable symbolTable) {
5353
MatchedVariables variables = variablesSet();
5454

55-
Combinator combinator = new Combinator(variables, this.body, factsSupplier, symbols);
55+
Combinator combinator = new Combinator(variables, this.body, factsSupplier, symbolTable);
5656
Spliterator<Tuple2<Origin, Map<Long, Term>>> splitItr =
5757
Spliterators.spliteratorUnknownSize(combinator, Spliterator.ORDERED);
5858
Stream<Tuple2<Origin, Map<Long, Term>>> stream = StreamSupport.stream(splitItr, false);
@@ -63,7 +63,7 @@ public Stream<Either<Error, Tuple2<Origin, Fact>>> apply(
6363
t -> {
6464
Origin origin = t._1;
6565
Map<Long, Term> generatedVariables = t._2;
66-
TemporarySymbolTable temporarySymbols = new TemporarySymbolTable(symbols);
66+
TemporarySymbolTable temporarySymbols = new TemporarySymbolTable(symbolTable);
6767
for (Expression e : this.expressions) {
6868
try {
6969
Term term = e.evaluate(generatedVariables, temporarySymbols);
@@ -127,15 +127,15 @@ private MatchedVariables variablesSet() {
127127

128128
// do not produce new facts, only find one matching set of facts
129129
public boolean findMatch(
130-
final FactSet facts, Long origin, TrustedOrigins scope, SymbolTable symbols) throws Error {
130+
final FactSet facts, Long origin, TrustedOrigins scope, SymbolTable symbolTable) throws Error {
131131
MatchedVariables variables = variablesSet();
132132

133133
if (this.body.isEmpty()) {
134-
return variables.checkExpressions(this.expressions, symbols).isDefined();
134+
return variables.checkExpressions(this.expressions, symbolTable).isDefined();
135135
}
136136

137137
Supplier<Stream<Tuple2<Origin, Fact>>> factsSupplier = () -> facts.stream(scope);
138-
Stream<Either<Error, Tuple2<Origin, Fact>>> stream = this.apply(factsSupplier, origin, symbols);
138+
Stream<Either<Error, Tuple2<Origin, Fact>>> stream = this.apply(factsSupplier, origin, symbolTable);
139139

140140
Iterator<Either<Error, Tuple2<Origin, Fact>>> it = stream.iterator();
141141

@@ -152,24 +152,24 @@ public boolean findMatch(
152152
}
153153

154154
// verifies that the expressions return true for every matching set of facts
155-
public boolean checkMatchAll(final FactSet facts, TrustedOrigins scope, SymbolTable symbols)
155+
public boolean checkMatchAll(final FactSet facts, TrustedOrigins scope, SymbolTable symbolTable)
156156
throws Error {
157157
MatchedVariables variables = variablesSet();
158158

159159
if (this.body.isEmpty()) {
160-
return variables.checkExpressions(this.expressions, symbols).isDefined();
160+
return variables.checkExpressions(this.expressions, symbolTable).isDefined();
161161
}
162162

163163
Supplier<Stream<Tuple2<Origin, Fact>>> factsSupplier = () -> facts.stream(scope);
164-
Combinator combinator = new Combinator(variables, this.body, factsSupplier, symbols);
164+
Combinator combinator = new Combinator(variables, this.body, factsSupplier, symbolTable);
165165
boolean found = false;
166166

167167
for (Combinator it = combinator; it.hasNext(); ) {
168168
Tuple2<Origin, Map<Long, Term>> t = it.next();
169169
Map<Long, Term> generatedVariables = t._2;
170170
found = true;
171171

172-
TemporarySymbolTable temporarySymbols = new TemporarySymbolTable(symbols);
172+
TemporarySymbolTable temporarySymbols = new TemporarySymbolTable(symbolTable);
173173
for (Expression e : this.expressions) {
174174

175175
Term term = e.evaluate(generatedVariables, temporarySymbols);

src/main/java/org/biscuitsec/biscuit/datalog/RuleSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public Stream<Rule> stream() {
3838
}
3939

4040
public void clear() {
41-
rules.clear();
41+
this.rules.clear();
4242
}
4343

4444
public HashMap<TrustedOrigins, List<Tuple2<Long, Rule>>> getRules() {
45-
return rules;
45+
return this.rules;
4646
}
4747
}

src/main/java/org/biscuitsec/biscuit/datalog/RunLimits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public RunLimits(int maxFacts, int maxIterations, Duration maxTime) {
1616
}
1717

1818
public int getMaxFacts() {
19-
return maxFacts;
19+
return this.maxFacts;
2020
}
2121

2222
public int getMaxIterations() {
23-
return maxIterations;
23+
return this.maxIterations;
2424
}
2525

2626
public Duration getMaxTime() {
27-
return maxTime;
27+
return this.maxTime;
2828
}
2929
}

src/main/java/org/biscuitsec/biscuit/datalog/SchemaVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public SchemaVersion(List<Fact> facts, List<Rule> rules, List<Check> checks, Lis
3939

4040
containsCheckAll = false;
4141
for (Check check : checks) {
42-
if (check.kind() == Check.Kind.All) {
42+
if (check.kind() == Check.Kind.ALL) {
4343
containsCheckAll = true;
4444
break;
4545
}

src/main/java/org/biscuitsec/biscuit/datalog/SymbolTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ public String formatFact(final Fact f) {
237237
public String formatCheck(final Check c) {
238238
String prefix;
239239
switch (c.kind()) {
240-
case One:
240+
case ONE:
241241
prefix = "check if ";
242242
break;
243-
case All:
243+
case ALL:
244244
prefix = "check all ";
245245
break;
246246
default:

src/main/java/org/biscuitsec/biscuit/datalog/Term.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static Either<Error.FormatError, Term> deserializeEnumV2(Schema.TermV2 te
3636
}
3737
}
3838

39-
public abstract org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols);
39+
public abstract org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable);
4040

4141
public static final class Date extends Term implements Serializable {
4242
private final long value;
@@ -93,7 +93,7 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
9393
}
9494
}
9595

96-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
96+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
9797
return new org.biscuitsec.biscuit.token.builder.Term.Date(this.value);
9898
}
9999
}
@@ -156,7 +156,7 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
156156
}
157157
}
158158

159-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
159+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
160160
return new org.biscuitsec.biscuit.token.builder.Term.Integer(this.value);
161161
}
162162
}
@@ -219,7 +219,7 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
219219
}
220220
}
221221

222-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
222+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
223223
return new org.biscuitsec.biscuit.token.builder.Term.Bytes(this.value);
224224
}
225225
}
@@ -277,9 +277,9 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
277277
}
278278
}
279279

280-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
280+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
281281
return new org.biscuitsec.biscuit.token.builder.Term.Str(
282-
symbols.formatSymbol((int) this.value));
282+
symbolTable.formatSymbol((int) this.value));
283283
}
284284
}
285285

@@ -335,9 +335,9 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
335335
}
336336
}
337337

338-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
338+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
339339
return new org.biscuitsec.biscuit.token.builder.Term.Variable(
340-
symbols.formatSymbol((int) this.value));
340+
symbolTable.formatSymbol((int) this.value));
341341
}
342342
}
343343

@@ -399,7 +399,7 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
399399
}
400400
}
401401

402-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
402+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
403403
return new org.biscuitsec.biscuit.token.builder.Term.Bool(this.value);
404404
}
405405
}
@@ -491,11 +491,11 @@ public static Either<Error.FormatError, Term> deserializeV2(Schema.TermV2 term)
491491
}
492492
}
493493

494-
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbols) {
494+
public org.biscuitsec.biscuit.token.builder.Term toTerm(SymbolTable symbolTable) {
495495
HashSet<org.biscuitsec.biscuit.token.builder.Term> s = new HashSet<>();
496496

497497
for (Term i : this.value) {
498-
s.add(i.toTerm(symbols));
498+
s.add(i.toTerm(symbolTable));
499499
}
500500

501501
return new org.biscuitsec.biscuit.token.builder.Term.Set(s);

0 commit comments

Comments
 (0)