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

remove vavr from public make methods #67

Merged
merged 1 commit into from
Aug 7, 2023
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
20 changes: 16 additions & 4 deletions src/main/java/com/clevercloud/biscuit/token/Biscuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,33 @@ public static com.clevercloud.biscuit.token.builder.Biscuit builder(final Secure
* @param rng random number generator
* @param root root private key
* @param authority authority block
* @return
* @return Biscuit
*/
@Deprecated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was it deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we wanted to expose the ability to pass a root_key_option using vavr. So this method without has been deprecated. But since we want to remove vavr from public methods we keep it and add the one with the root_key_id (not optional) so two methods one with root_key_id and one without.

static public Biscuit make(final SecureRandom rng, final KeyPair root, final SymbolTable symbols, final Block authority) throws Error.SymbolTableOverlap, Error.FormatError {
return Biscuit.make(rng, root, Option.none(), symbols, authority);
}

/**
* Creates a token
*
* @param rng random number generator
* @param root root private key
* @param authority authority block
* @return
* @return Biscuit
*/
static public Biscuit make(final SecureRandom rng, final KeyPair root, final Integer root_key_id, final SymbolTable symbols, final Block authority) throws Error.SymbolTableOverlap, Error.FormatError {
return Biscuit.make(rng, root, Option.of(root_key_id), symbols, authority);
}

/**
* Creates a token
*
* @param rng random number generator
* @param root root private key
* @param authority authority block
* @return Biscuit
*/
static public Biscuit make(final SecureRandom rng, final KeyPair root, final Option<Integer> root_key_id, final SymbolTable symbols, final Block authority) throws Error.SymbolTableOverlap, Error.FormatError {
static private Biscuit make(final SecureRandom rng, final KeyPair root, final Option<Integer> root_key_id, final SymbolTable symbols, final Block authority) throws Error.SymbolTableOverlap, Error.FormatError {
if (!Collections.disjoint(symbols.symbols, authority.symbols.symbols)) {
throw new Error.SymbolTableOverlap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Arrays;
import java.util.List;

import static com.clevercloud.biscuit.token.Biscuit.make;
import static com.clevercloud.biscuit.token.builder.Utils.*;

public class Biscuit {
Expand Down Expand Up @@ -132,7 +133,11 @@ public com.clevercloud.biscuit.token.Biscuit build() throws Error {
}

Block authority_block = new com.clevercloud.biscuit.token.Block(symbols, context, this.facts, this.rules, this.checks);
return com.clevercloud.biscuit.token.Biscuit.make(this.rng, this.root, this.root_key_id, base_symbols, authority_block);
if (this.root_key_id.isDefined()) {
return make(this.rng, this.root, this.root_key_id.get(), base_symbols, authority_block);
} else {
return make(this.rng, this.root, base_symbols, authority_block);
}
}

public Biscuit add_right(String resource, String right) throws Error.Language {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public void testRootKeyId() throws NoSuchAlgorithmException, SignatureException,
authority_builder.add_fact(fact("right", Arrays.asList(s("file2"), s("read"))));
authority_builder.add_fact(fact("right", Arrays.asList(s("file1"), s("write"))));

Biscuit b = Biscuit.make(rng, root, Option.some(1), Biscuit.default_symbol_table(), authority_builder.build());
Biscuit b = Biscuit.make(rng, root, 1, Biscuit.default_symbol_table(), authority_builder.build());

System.out.println(b.print());

Expand Down