Skip to content

Commit 4c0f878

Browse files
committed
Add examining the blocks (readonly) of the biscuit.
1 parent 3ef87dd commit 4c0f878

3 files changed

Lines changed: 12 additions & 20 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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ public static UnverifiedBiscuit fromBytesWithSymbols(byte[] data, SymbolTable sy
9292
*/
9393
private static UnverifiedBiscuit fromSerializedBiscuit(
9494
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);
95+
var t = ser.extractBlocks(symbolTable);
96+
return new UnverifiedBiscuit(t._1, t._2, symbolTable, ser);
10097
}
10198

10299
/**
@@ -201,15 +198,12 @@ public List<Optional<PublicKey>> externalPublicKeys() {
201198
.collect(Collectors.toList());
202199
}
203200

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-
}
201+
public List<Block> getBlocks() {
202+
return Stream.concat(Stream.of(authority), blocks.stream()).collect(Collectors.toList());
203+
}
211204

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

215209
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)