Add JoseHeader.builder()

Closes gh-215
This commit is contained in:
Joe Grandja 2021-02-05 05:24:20 -05:00
parent adf96b4e25
commit 1fa0161164

View File

@ -175,6 +175,15 @@ public final class JoseHeader {
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 JwsAlgorithm}.
*
@ -201,6 +210,9 @@ public final class JoseHeader {
public static final class Builder {
private final Map<String, Object> headers = new HashMap<>();
private Builder() {
}
private Builder(JwsAlgorithm jwsAlgorithm) {
Assert.notNull(jwsAlgorithm, "jwsAlgorithm cannot be null");
header(JoseHeaderNames.ALG, jwsAlgorithm);
@ -211,6 +223,16 @@ public final class JoseHeader {
this.headers.putAll(headers.getHeaders());
}
/**
* Sets the {@link JwsAlgorithm JWS algorithm} used to digitally sign the JWS.
*
* @param jwsAlgorithm the JWS algorithm
* @return the {@link Builder}
*/
public Builder jwsAlgorithm(JwsAlgorithm jwsAlgorithm) {
return header(JoseHeaderNames.ALG, jwsAlgorithm);
}
/**
* 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 or encrypt the JWE.