Class Cwt


  • public class Cwt
    extends Object
    A representation of a CWT according to RFC 8392.
    Author:
    Martin Lindström (martin@idsec.se), Henrik Bengtsson (extern.henrik.bengtsson@digg.se), Henric Norlander (extern.henric.norlander@digg.se)
    • 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

      • 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 by claimKey.
        Parameters:
        claimKey - the claim key
        value - the claim value (in its CBOR encoding)
      • setClaim

        public void setClaim​(int claimKey,
                             com.upokecenter.cbor.CBORObject value)
        Sets a claim identified by claimKey.
        Parameters:
        claimKey - the claim key
        value - the claim value
      • setClaim

        public void setClaim​(String claimKey,
                             byte[] value)
        Sets a claim identified by claimKey.
        Parameters:
        claimKey - the claim key
        value - the claim value (in its CBOR encoding)
      • setClaim

        public void setClaim​(String claimKey,
                             com.upokecenter.cbor.CBORObject value)
        Sets a claim identified by claimKey.
        Parameters:
        claimKey - the claim key
        value - the claim value
      • getClaim

        public com.upokecenter.cbor.CBORObject getClaim​(int claimKey)
        Gets the claim identified by claimKey.
        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 by claimKey.
        Parameters:
        claimKey - the claim key
        Returns:
        the claim value as a CBORObject, or null