Package se.digg.dgc.signatures.cwt
Class Cwt
- java.lang.Object
-
- se.digg.dgc.signatures.cwt.Cwt
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Cwt.CwtBuilder
A builder for creatingCwt
objects.
-
Field Summary
Fields Modifier and Type Field Description static int
EU_DGC_V1_MESSAGE_TAG
The message tag for eu_dgc_v1 that is added under the HCERT claim.static int
HCERT_CLAIM_KEY
HCERT message tag.static int
MESSAGE_TAG
The CBOR CWT message tag.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Cwt.CwtBuilder
builder()
Creates aCwt.CwtBuilder
.static Cwt
decode(byte[] data)
Decodes the supplied data into a Cwt object.byte[]
encode()
Gets the binary representation of the CWT.List<String>
getAudience()
Gets the values for the "aud" claimcom.upokecenter.cbor.CBORObject
getClaim(int claimKey)
Gets the claim identified byclaimKey
.com.upokecenter.cbor.CBORObject
getClaim(String claimKey)
Gets the claim identified byclaimKey
.byte[]
getCwtId()
Gets the value of the "cti" (CWT ID) claim.byte[]
getDgcV1()
Gets the CBOR encoding of a DGC v1 payload.Instant
getExpiration()
Gets the value of the "exp" (expiration time) claim.Instant
getIssuedAt()
Gets the value of the "iat" (issued at) claim.String
getIssuer()
Gets the "iss" (issuer) claim.Instant
getNotBefore()
Gets the value of the "nbf" (not before) claim.String
getSubject()
Gets the "sub" (subject) claim.void
setAudience(String audience)
Sets a single value to the "aud" (audience) claim.void
setAudience(List<String> audiences)
Sets multiple values to the "aud" (audience) claim.void
setClaim(int claimKey, byte[] value)
Sets a claim identified byclaimKey
.void
setClaim(int claimKey, com.upokecenter.cbor.CBORObject value)
Sets a claim identified byclaimKey
.void
setClaim(String claimKey, byte[] value)
Sets a claim identified byclaimKey
.void
setClaim(String claimKey, com.upokecenter.cbor.CBORObject value)
Sets a claim identified byclaimKey
.void
setCwtId(byte[] cti)
Sets the "cti" (CWT ID) claim.void
setDgcV1(byte[] dgcPayload)
Adds DGC v1 payload.void
setExpiration(Instant exp)
Sets the "exp" (expiration time) claim.void
setIssuedAt(Instant iat)
Sets the "iat" (issued at) claim.void
setIssuer(String issuer)
Sets the "iss" (issuer) claim.void
setNotBefore(Instant nbf)
Sets the "nbf" (not before) claim.void
setSubject(String subject)
Sets the "sub" (subject) claim.String
toString()
-
-
-
Field Detail
-
HCERT_CLAIM_KEY
public static final int HCERT_CLAIM_KEY
HCERT message tag. See https://www.iana.org/assignments/cwt/cwt.xhtml.- See Also:
- Constant Field Values
-
EU_DGC_V1_MESSAGE_TAG
public static final int EU_DGC_V1_MESSAGE_TAG
The message tag for eu_dgc_v1 that is added under the HCERT claim.- See Also:
- Constant Field Values
-
MESSAGE_TAG
public static final int MESSAGE_TAG
The CBOR CWT message tag.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Cwt
public Cwt()
Constructor creating an empty CWT.
-
Cwt
public Cwt(byte[] data) throws com.upokecenter.cbor.CBORException
Constructor creating a CWT from a supplied encoding.- Parameters:
data
- the encoding- Throws:
com.upokecenter.cbor.CBORException
- if the supplied encoding is not a valid CWT
-
-
Method Detail
-
builder
public static Cwt.CwtBuilder builder()
Creates aCwt.CwtBuilder
.- Returns:
- a CwtBuilder
-
decode
public static Cwt decode(byte[] data) throws com.upokecenter.cbor.CBORException
Decodes the supplied data into a Cwt object.- Parameters:
data
- the encoded data- Returns:
- a Cwt object
- Throws:
com.upokecenter.cbor.CBORException
- if the supplied encoding is not a valid CWT
-
encode
public byte[] encode()
Gets the binary representation of the CWT.- Returns:
- a byte array
-
setIssuer
public void setIssuer(String issuer)
Sets the "iss" (issuer) claim.- Parameters:
issuer
- the issuer value
-
getIssuer
public String getIssuer()
Gets the "iss" (issuer) claim.- Returns:
- the issuer value, or null
-
setSubject
public void setSubject(String subject)
Sets the "sub" (subject) claim.- Parameters:
subject
- the subject value
-
getSubject
public String getSubject()
Gets the "sub" (subject) claim.- Returns:
- the subject value, or null
-
setAudience
public void setAudience(String audience)
Sets a single value to the "aud" (audience) claim.- Parameters:
audience
- the audience value
-
setAudience
public void setAudience(List<String> audiences)
Sets multiple values to the "aud" (audience) claim.- Parameters:
audiences
- the values
-
getAudience
public List<String> getAudience()
Gets the values for the "aud" claim- Returns:
- the value, or null
-
setExpiration
public void setExpiration(Instant exp)
Sets the "exp" (expiration time) claim.- Parameters:
exp
- the expiration
-
getExpiration
public Instant getExpiration()
Gets the value of the "exp" (expiration time) claim.- Returns:
- the instant, or null
-
setNotBefore
public void setNotBefore(Instant nbf)
Sets the "nbf" (not before) claim.- Parameters:
exp
- the not before time
-
getNotBefore
public Instant getNotBefore()
Gets the value of the "nbf" (not before) claim.- Returns:
- the instant, or null
-
setIssuedAt
public void setIssuedAt(Instant iat)
Sets the "iat" (issued at) claim.- Parameters:
iat
- the issued at time
-
getIssuedAt
public Instant getIssuedAt()
Gets the value of the "iat" (issued at) claim.- Returns:
- the instant, or null
-
setCwtId
public void setCwtId(byte[] cti)
Sets the "cti" (CWT ID) claim.- Parameters:
cti
- the CWT ID
-
getCwtId
public byte[] getCwtId()
Gets the value of the "cti" (CWT ID) claim.- Returns:
- the ID, or null
-
setDgcV1
public void setDgcV1(byte[] dgcPayload)
Adds DGC v1 payload.- Parameters:
dgcPayload
- the CBOR encoding of DGC payload
-
getDgcV1
public byte[] getDgcV1()
Gets the CBOR encoding of a DGC v1 payload.- Returns:
- the CBOR encoding of a DGC v1 payload or null if no payload is stored
-
setClaim
public void setClaim(int claimKey, byte[] value)
Sets a claim identified byclaimKey
.- Parameters:
claimKey
- the claim keyvalue
- the claim value (in its CBOR encoding)
-
setClaim
public void setClaim(int claimKey, com.upokecenter.cbor.CBORObject value)
Sets a claim identified byclaimKey
.- Parameters:
claimKey
- the claim keyvalue
- the claim value
-
setClaim
public void setClaim(String claimKey, byte[] value)
Sets a claim identified byclaimKey
.- Parameters:
claimKey
- the claim keyvalue
- the claim value (in its CBOR encoding)
-
setClaim
public void setClaim(String claimKey, com.upokecenter.cbor.CBORObject value)
Sets a claim identified byclaimKey
.- Parameters:
claimKey
- the claim keyvalue
- the claim value
-
getClaim
public com.upokecenter.cbor.CBORObject getClaim(int claimKey)
Gets the claim identified byclaimKey
.- Parameters:
claimKey
- the claim key- Returns:
- the claim value as a CBORObject, or null
-
getClaim
public com.upokecenter.cbor.CBORObject getClaim(String claimKey)
Gets the claim identified byclaimKey
.- Parameters:
claimKey
- the claim key- Returns:
- the claim value as a CBORObject, or null
-
-