Skip to content

Commit 3ad37d7

Browse files
authored
Merge pull request #138 from preuss-adam/apreuss/make-blocks-visible
Add examining the blocks (readonly) of the biscuit.
2 parents d4f3673 + d784ca8 commit 3ad37d7

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

src/main/java/org/eclipse/biscuit/token/Biscuit.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,8 @@ public static Biscuit fromBytesWithSymbols(
253253
*/
254254
static Biscuit fromSerializedBiscuit(SerializedBiscuit ser, SymbolTable symbolTable)
255255
throws Error {
256-
Pair<Block, ArrayList<Block>> t = ser.extractBlocks(symbolTable);
257-
Block authority = t._1;
258-
ArrayList<Block> blocks = t._2;
259-
260-
return new Biscuit(authority, blocks, symbolTable, ser);
256+
Pair<Block, List<Block>> t = ser.extractBlocks(symbolTable);
257+
return new Biscuit(t._1, t._2, symbolTable, ser);
261258
}
262259

263260
/**

src/main/java/org/eclipse/biscuit/token/UnverifiedBiscuit.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.eclipse.biscuit.crypto.KeyPair;
2222
import org.eclipse.biscuit.crypto.PublicKey;
2323
import org.eclipse.biscuit.datalog.Check;
24-
import org.eclipse.biscuit.datalog.Pair;
2524
import org.eclipse.biscuit.datalog.SymbolTable;
2625
import org.eclipse.biscuit.error.Error;
2726
import org.eclipse.biscuit.token.format.ExternalSignature;
@@ -92,11 +91,8 @@ public static UnverifiedBiscuit fromBytesWithSymbols(byte[] data, SymbolTable sy
9291
*/
9392
private static UnverifiedBiscuit fromSerializedBiscuit(
9493
SerializedBiscuit ser, SymbolTable symbolTable) throws Error {
95-
Pair<Block, ArrayList<Block>> t = ser.extractBlocks(symbolTable);
96-
Block authority = t._1;
97-
ArrayList<Block> blocks = t._2;
98-
99-
return new UnverifiedBiscuit(authority, blocks, symbolTable, ser);
94+
var t = ser.extractBlocks(symbolTable);
95+
return new UnverifiedBiscuit(t._1, t._2, symbolTable, ser);
10096
}
10197

10298
/**
@@ -201,15 +197,12 @@ public List<Optional<PublicKey>> externalPublicKeys() {
201197
.collect(Collectors.toList());
202198
}
203199

204-
public List<List<Check>> getChecks() {
205-
ArrayList<List<Check>> l = new ArrayList<>();
206-
l.add(new ArrayList<>(this.authority.getChecks()));
207-
208-
for (Block b : this.blocks) {
209-
l.add(new ArrayList<>(b.getChecks()));
210-
}
200+
public List<Block> getBlocks() {
201+
return Stream.concat(Stream.of(authority), blocks.stream()).collect(Collectors.toList());
202+
}
211203

212-
return l;
204+
public List<List<Check>> getChecks() {
205+
return getBlocks().stream().map(Block::getChecks).collect(Collectors.toList());
213206
}
214207

215208
public List<Optional<String>> getContext() {

src/main/java/org/eclipse/biscuit/token/format/SerializedBiscuit.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.security.NoSuchAlgorithmException;
1515
import java.security.SignatureException;
1616
import java.util.ArrayList;
17+
import java.util.Collections;
1718
import java.util.List;
1819
import java.util.Optional;
1920
import java.util.stream.Stream;
@@ -489,7 +490,7 @@ static Result<org.eclipse.biscuit.crypto.PublicKey, Error> verifyBlockSignature(
489490
return Result.ok(signedBlock.getKey());
490491
}
491492

492-
public Pair<Block, ArrayList<Block>> extractBlocks(SymbolTable symbolTable) throws Error {
493+
public Pair<Block, List<Block>> extractBlocks(SymbolTable symbolTable) throws Error {
493494
ArrayList<Optional<org.eclipse.biscuit.crypto.PublicKey>> blockExternalKeys = new ArrayList<>();
494495
var authRes = Block.fromBytes(this.authority.getBlock(), Optional.empty());
495496
if (authRes.isErr()) {
@@ -534,7 +535,7 @@ public Pair<Block, ArrayList<Block>> extractBlocks(SymbolTable symbolTable) thro
534535
blocks.add(block);
535536
}
536537

537-
return new Pair<>(authority, blocks);
538+
return new Pair<>(authority, Collections.unmodifiableList(blocks));
538539
}
539540

540541
public Result<Void, Error> seal()

0 commit comments

Comments
 (0)