public abstract class Header extends Object implements Serializable
alg=none
), JSON Web Signature
(JWS) and JSON Web Encryption (JWE) headers.
The header may also include custom
parameters
; these will be serialised and parsed along the registered ones.
Modifier | Constructor and Description |
---|---|
protected |
Header(Algorithm alg,
JOSEObjectType typ,
String cty,
Set<String> crit,
Map<String,Object> customParams,
Base64URL parsedBase64URL)
Creates a new abstract header.
|
protected |
Header(Header header)
Deep copy constructor.
|
Modifier and Type | Method and Description |
---|---|
Algorithm |
getAlgorithm()
Gets the algorithm (
alg ) parameter. |
String |
getContentType()
Gets the content type (
cty ) parameter. |
Set<String> |
getCriticalParams()
Gets the critical header parameters (
crit ) parameter. |
Object |
getCustomParam(String name)
Gets a custom (non-registered) parameter.
|
Map<String,Object> |
getCustomParams()
Gets the custom (non-registered) parameters.
|
Set<String> |
getIncludedParams()
Gets the names of all included parameters (registered and custom) in
the header instance.
|
Base64URL |
getParsedBase64URL()
Gets the original Base64URL used to create this header.
|
JOSEObjectType |
getType()
Gets the type (
typ ) parameter. |
static Header |
parse(Base64URL base64URL)
|
static Header |
parse(net.minidev.json.JSONObject jsonObject)
|
static Header |
parse(net.minidev.json.JSONObject jsonObject,
Base64URL parsedBase64URL)
|
static Header |
parse(String jsonString)
|
static Header |
parse(String jsonString,
Base64URL parsedBase64URL)
|
static Algorithm |
parseAlgorithm(net.minidev.json.JSONObject json)
Parses an algorithm (
alg ) parameter from the specified
header JSON object. |
Base64URL |
toBase64URL()
Returns a Base64URL representation of the header.
|
net.minidev.json.JSONObject |
toJSONObject()
Returns a JSON object representation of the header.
|
String |
toString()
Returns a JSON string representation of the header.
|
protected Header(Algorithm alg, JOSEObjectType typ, String cty, Set<String> crit, Map<String,Object> customParams, Base64URL parsedBase64URL)
alg
- The algorithm (alg
) parameter. Must
not be null
.typ
- The type (typ
) parameter,
null
if not specified.cty
- The content type (cty
) parameter,
null
if not specified.crit
- The names of the critical header
(crit
) parameters, empty set or
null
if none.customParams
- The custom parameters, empty map or
null
if none.parsedBase64URL
- The parsed Base64URL, null
if the
header is created from scratch.public Algorithm getAlgorithm()
alg
) parameter.public JOSEObjectType getType()
typ
) parameter.null
if not specified.public String getContentType()
cty
) parameter.null
if not specified.public Set<String> getCriticalParams()
crit
) parameter.null
if not specified.public Object getCustomParam(String name)
name
- The name of the custom parameter. Must not be
null
.null
if not specified.public Map<String,Object> getCustomParams()
public Base64URL getParsedBase64URL()
null
if the header was created
from scratch.public Set<String> getIncludedParams()
public net.minidev.json.JSONObject toJSONObject()
public String toString()
public Base64URL toBase64URL()
public static Algorithm parseAlgorithm(net.minidev.json.JSONObject json) throws ParseException
alg
) parameter from the specified
header JSON object. Intended for initial parsing of unsecured
(plain), JWS and JWE headers.
The algorithm type (none, JWS or JWE) is determined by inspecting the algorithm name for "none" and the presence of an "enc" parameter.
json
- The JSON object to parse. Must not be null
.Algorithm.NONE
,
JWSAlgorithm
or JWEAlgorithm
. null
if not found.ParseException
- If the alg
parameter couldn't be
parsed.public static Header parse(net.minidev.json.JSONObject jsonObject) throws ParseException
jsonObject
- The JSON object to parse. Must not be
null
.ParseException
- If the specified JSON object doesn't
represent a valid header.public static Header parse(net.minidev.json.JSONObject jsonObject, Base64URL parsedBase64URL) throws ParseException
jsonObject
- The JSON object to parse. Must not be
null
.parsedBase64URL
- The original parsed Base64URL, null
if not applicable.ParseException
- If the specified JSON object doesn't
represent a valid header.public static Header parse(String jsonString) throws ParseException
jsonString
- The JSON object string to parse. Must not be
null
.ParseException
- If the specified JSON object string doesn't
represent a valid header.public static Header parse(String jsonString, Base64URL parsedBase64URL) throws ParseException
jsonString
- The JSON object string to parse. Must not be
null
.parsedBase64URL
- The original parsed Base64URL, null
if not applicable.ParseException
- If the specified JSON object string doesn't
represent a valid header.public static Header parse(Base64URL base64URL) throws ParseException
base64URL
- The Base64URL to parse. Must not be null
.ParseException
- If the specified Base64URL doesn't represent
a valid header.Copyright © 2019 Connect2id Ltd.. All rights reserved.