Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update samples format #81

Merged
merged 8 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading