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 classCwt.CwtBuilderA builder for creatingCwtobjects.
-
Field Summary
Fields Modifier and Type Field Description static intEU_DGC_V1_MESSAGE_TAGThe message tag for eu_dgc_v1 that is added under the HCERT claim.static intHCERT_CLAIM_KEYHCERT message tag.static intMESSAGE_TAGThe CBOR CWT message tag.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Cwt.CwtBuilderbuilder()Creates aCwt.CwtBuilder.static Cwtdecode(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.CBORObjectgetClaim(int claimKey)Gets the claim identified byclaimKey.com.upokecenter.cbor.CBORObjectgetClaim(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.InstantgetExpiration()Gets the value of the "exp" (expiration time) claim.InstantgetIssuedAt()Gets the value of the "iat" (issued at) claim.StringgetIssuer()Gets the "iss" (issuer) claim.InstantgetNotBefore()Gets the value of the "nbf" (not before) claim.StringgetSubject()Gets the "sub" (subject) claim.voidsetAudience(String audience)Sets a single value to the "aud" (audience) claim.voidsetAudience(List<String> audiences)Sets multiple values to the "aud" (audience) claim.voidsetClaim(int claimKey, byte[] value)Sets a claim identified byclaimKey.voidsetClaim(int claimKey, com.upokecenter.cbor.CBORObject value)Sets a claim identified byclaimKey.voidsetClaim(String claimKey, byte[] value)Sets a claim identified byclaimKey.voidsetClaim(String claimKey, com.upokecenter.cbor.CBORObject value)Sets a claim identified byclaimKey.voidsetCwtId(byte[] cti)Sets the "cti" (CWT ID) claim.voidsetDgcV1(byte[] dgcPayload)Adds DGC v1 payload.voidsetExpiration(Instant exp)Sets the "exp" (expiration time) claim.voidsetIssuedAt(Instant iat)Sets the "iat" (issued at) claim.voidsetIssuer(String issuer)Sets the "iss" (issuer) claim.voidsetNotBefore(Instant nbf)Sets the "nbf" (not before) claim.voidsetSubject(String subject)Sets the "sub" (subject) claim.StringtoString()
-
-
-
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.CBORExceptionConstructor 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
-
-