Skip to content

Commit

Permalink
Update samples format (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal authored Jan 8, 2024
1 parent 5658ad4 commit ac7015c
Show file tree
Hide file tree
Showing 35 changed files with 4,553 additions and 753 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public String print_scope(final Scope scope) {
case PublicKey:
Option<PublicKey> pk = this.get_pk((int) scope.publicKey);
if(pk.isDefined()) {
return pk.toString();
return pk.get().toString();
}
}
return "?";
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/biscuitsec/biscuit/datalog/expressions/Op.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ public String print(Deque<String> stack, SymbolTable symbols) {
String _s = "";
switch (this.op) {
case Negate:
_s = "! " + prec;
_s = "!" + prec;
stack.push(_s);
break;
case Parens:
_s = "(" + prec + ")";
stack.push(_s);
break;
case Length:
_s = prec+".length()";
stack.push(_s);
break;
}
return _s;
}
Expand Down Expand Up @@ -307,6 +311,10 @@ public boolean evaluate(Deque<Term> stack, Map<Long, Term> variables, TemporaryS
}
break;
case Equal:
if (right instanceof Term.Bool && left instanceof Term.Bool) {
stack.push(new Term.Bool(((Term.Bool) left).value() == ((Term.Bool) right).value()));
return true;
}
if (right instanceof Term.Integer && left instanceof Term.Integer) {
stack.push(new Term.Bool(((Term.Integer) left).value() == ((Term.Integer) right).value()));
return true;
Expand All @@ -331,6 +339,10 @@ public boolean evaluate(Deque<Term> stack, Map<Long, Term> variables, TemporaryS
}
break;
case NotEqual:
if (right instanceof Term.Bool && left instanceof Term.Bool) {
stack.push(new Term.Bool(((Term.Bool) left).value() == ((Term.Bool) right).value()));
return true;
}
if (right instanceof Term.Integer && left instanceof Term.Integer) {
stack.push(new Term.Bool(((Term.Integer) left).value() != ((Term.Integer) right).value()));
return true;
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/org/biscuitsec/biscuit/token/Authorizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,37 +630,49 @@ public String print_world() {
"\n\t]\n}";
}

public List<Fact> facts() {
return this.world.facts().stream()
.map((f) -> org.biscuitsec.biscuit.token.builder.Fact.convert_from(f, this.symbols))
.collect(Collectors.toList());
public FactSet facts() {
return this.world.facts();
}

public List<org.biscuitsec.biscuit.token.builder.Rule> rules() {
return this.world.rules().stream()
.map((r) -> org.biscuitsec.biscuit.token.builder.Rule.convert_from(r, this.symbols))
.collect(Collectors.toList());
public RuleSet rules() {
return this.world.rules();
}

public List<Check> checks() {
List<Check> checks = new ArrayList<>(this.checks);
public List<Tuple2<Long, List<Check>>> checks() {
List<Tuple2<Long, List<Check>>> allChecks = new ArrayList<>();
if(!this.checks.isEmpty()) {
allChecks.add(new Tuple2(Long.MAX_VALUE, this.checks));
}

List<Check> authorityChecks = new ArrayList<>();
for(org.biscuitsec.biscuit.datalog.Check check: this.token.authority.checks) {
checks.add(Check.convert_from(check, token.symbols));
authorityChecks.add(Check.convert_from(check, this.token.symbols));
}
if(!authorityChecks.isEmpty()) {
allChecks.add(new Tuple2((long) 0, authorityChecks));
}

long count = 1;
for(Block block: this.token.blocks) {
List<Check> blockChecks = new ArrayList<>();

if(block.externalKey.isDefined()) {
SymbolTable blockSymbols = new SymbolTable(block.symbols.symbols, token.symbols.publicKeys());
for(org.biscuitsec.biscuit.datalog.Check check: block.checks) {
checks.add(Check.convert_from(check, blockSymbols));
blockChecks.add(Check.convert_from(check, blockSymbols));
}
} else {
for(org.biscuitsec.biscuit.datalog.Check check: block.checks) {
checks.add(Check.convert_from(check, token.symbols));
blockChecks.add(Check.convert_from(check, token.symbols));
}
}
if(!blockChecks.isEmpty()) {
allChecks.add(new Tuple2(count, blockChecks));
}
count += 1;
}

return checks;
return allChecks;
}

public List<Policy> policies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void testNegate() {
)));

assertEquals(
"! 1 < $var",
"!1 < $var",
e.print(symbols).get()
);

Expand Down Expand Up @@ -104,7 +104,7 @@ public void testNegativeContainsStr() {
)));

assertEquals(
"! \"ab\".contains(\"b\")",
"!\"ab\".contains(\"b\")",
e.print(symbols).get()
);

Expand Down
Loading

0 comments on commit ac7015c

Please sign in to comment.