Skip to content

Commit

Permalink
Add JoseHeader.builder()
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandja committed Feb 5, 2021
1 parent 8dc8539 commit b4cf524
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public <T> T getHeader(String name) {
return (T) getHeaders().get(name);
}

/**
* Returns a new {@link Builder}.
* @return the {@link Builder}
*/
public static Builder builder() {
return new Builder();
}

/**
* Returns a new {@link Builder}, initialized with the provided {@link JwaAlgorithm}.
* @param jwaAlgorithm the {@link JwaAlgorithm}
Expand All @@ -201,6 +209,9 @@ public static final class Builder {

private final Map<String, Object> headers = new HashMap<>();

private Builder() {
}

private Builder(JwaAlgorithm jwaAlgorithm) {
Assert.notNull(jwaAlgorithm, "jwaAlgorithm cannot be null");
header(JoseHeaderNames.ALG, jwaAlgorithm);
Expand All @@ -211,6 +222,16 @@ private Builder(JoseHeader headers) {
this.headers.putAll(headers.getHeaders());
}

/**
* Sets the {@link JwaAlgorithm JWA algorithm} used to digitally sign the JWS or
* encrypt the JWE.
* @param jwaAlgorithm the {@link JwaAlgorithm}
* @return the {@link Builder}
*/
public Builder algorithm(JwaAlgorithm jwaAlgorithm) {
return header(JoseHeaderNames.ALG, jwaAlgorithm);
}

/**
* Sets the JWK Set URL that refers to the resource of a set of JSON-encoded
* public keys, one of which corresponds to the key used to digitally sign the JWS
Expand Down

0 comments on commit b4cf524

Please sign in to comment.