Class SDObjectBuilder
Map
instance that represents a JSON object
which may contain the "_sd
" array and the "_sd_alg
" claim.
Example:
Disclosure disclosure = Disclosure.parse( "WyI2cU1RdlJMNWhhaiIsICJmYW1pbHlfbmFtZSIsICJNw7ZiaXVzIl0"); // Create an SDObjectBuilder instance with the default // hash algorithm "sha-256". SDObjectBuilder builder = new SDObjectBuilder(); // Add the digest of the disclosure. builder.putSDClaim(disclosure); // Add an arbitrary claim. String claimName = "my_claim_name"; String claimValue = "my_claim_value"; builder.putClaim(claimName, claimValue); // Build a map that represents a JSON object. Map<String, Object> map = builder.build(true); // map -> // { // "my_claim_name": "my_claim_value", // "_sd": [ // "uutlBuYeMDyjLLTpf6Jxi7yNkEF35jdyWMn9U7b_RYY" // ], // "_sd_alg": "sha-256" // }
- Since:
- 1.0
-
Constructor Summary
ConstructorDescriptionConstructor with the default hash algorithm ("sha-256
").SDObjectBuilder
(String hashAlgorithm) Constructor with the specified hash algorithm. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Create aMap
instance that represents a JSON object which may include the "_sd
" array.build
(boolean hashAlgorithmIncluded) Create aMap
instance that represents a JSON object which may include the "_sd
" array and the "_sd_alg
" claim.Get the hash algorithm that has been specified by the constructor.void
Put a normal claim.Put a decoy digest value, which will appear in the "_sd
" array.putDecoyDigests
(int count) Put decoy digest values, which will appear in the "_sd
" array.putSDClaim
(Disclosure disclosure) Put the digest value of a selectively-disclosable claim.putSDClaim
(String claimName, Object claimValue) Put the digest value of a selectively-disclosable claim.putSDClaim
(String salt, String claimName, Object claimValue) Put the digest value of a selectively-disclosable claim.
-
Constructor Details
-
SDObjectBuilder
public SDObjectBuilder()Constructor with the default hash algorithm ("sha-256
").The hash algorithm is used when computing digest values that are to be listed in the "
_sd
" array. -
SDObjectBuilder
Constructor with the specified hash algorithm.The hash algorithm is used when computing digest values that are to be listed in the "
_sd
" array.- Parameters:
hashAlgorithm
- A hash algorithm. Ifnull
is given, the default hash algorithm ("sha-256
") is used.
-
-
Method Details
-
getHashAlgorithm
Get the hash algorithm that has been specified by the constructor.The hash algorithm is used when computing digest values that are to be listed in the "
_sd
" array.- Returns:
- The hash algorithm.
-
putClaim
Put a normal claim.- Parameters:
claimName
- A claim name. Must not be null.claimValue
- A claim value. May be null.- Throws:
IllegalArgumentException
- The given claim name is null or a key reserved by the SD-JWT specification.
-
putSDClaim
Put the digest value of a selectively-disclosable claim.The digest of the given disclosure will appear in the "
_sd
" array.- Parameters:
disclosure
- The disclosure of the claim.- Returns:
- The
Disclosure
instance given to this method. - Throws:
IllegalArgumentException
- The given disclosure is null, or the disclosure is not for an object property.
-
putSDClaim
Put the digest value of a selectively-disclosable claim.This method is an alias of
putSDClaim
(new
Disclosure
(claimName, claimValue))
.- Parameters:
claimName
- A claim name. Must not be null.claimValue
- A claim value. May be null.- Returns:
- A
Disclosure
instance that was created for the specified claim. - Throws:
IllegalArgumentException
- The given claim name is null.
-
putSDClaim
Put the digest value of a selectively-disclosable claim.This method is an alias of
putSDClaim
(new
Disclosure
(salt, claimName, claimValue))
.- Parameters:
salt
- A salt. Must not be null.claimName
- A claim name. Must not be null.claimValue
- A claim value. May be null.- Returns:
- A
Disclosure
instance that was created for the specified claim. - Throws:
IllegalArgumentException
- The given salt and/or claim name are null.
-
putDecoyDigest
Put a decoy digest value, which will appear in the "_sd
" array.- Returns:
- The base64url-encoded digest value of a randomly-generated value computed with the hash algorithm.
-
putDecoyDigests
-
build
-
build
Create aMap
instance that represents a JSON object which may include the "_sd
" array and the "_sd_alg
" claim.The "
_sd
" array will not appear in the created map if no digest value has been put to this builder. In other words, if none of theputSDClaim
method variants, theputDecoyDigest()
method and theputDecoyDigests(int
) method have been called, the "_sd
" array will not appear.- Parameters:
hashAlgorithmIncluded
-true
to include the "_sd_alg
" claim in the created map.- Returns:
- A
Map
instance that represents a JSON object.
-