Package COSE

Class Message

  • Direct Known Subclasses:
    EncryptCommon, MacCommon, Recipient, SignCommon, SignMessage

    public abstract class Message
    extends Attribute
    The Message class provides a common class that all of the COSE message classes inherit from. It provides the function used for decoding all of the known messages.
    Author:
    jimsch
    • Field Detail

      • emitTag

        protected boolean emitTag
        Is the tag identifying the message emitted?
      • emitContent

        protected boolean emitContent
        Is the content emitted as part of the message?
      • messageTag

        protected MessageTag messageTag
        What message tag identifies this message?
      • rgbContent

        protected byte[] rgbContent
        What is the plain text content of the message.
    • Constructor Detail

      • Message

        public Message()
    • Method Detail

      • DecodeFromBytes

        public static Message DecodeFromBytes​(byte[] rgbData)
                                       throws CoseException
        Decode a COSE message object. This function assumes that the message has a leading CBOR tag to identify the message type. If this is not true then use {#link DecodeFromBytes(byte[], MessageTag)}.
        Parameters:
        rgbData - byte stream to be decoded
        Returns:
        the decoded message object
        Throws:
        CoseException - on a decode failure
      • DecodeFromBytes

        public static Message DecodeFromBytes​(byte[] rgbData,
                                              MessageTag defaultTag)
                                       throws CoseException
        Decode a COSE message object. Use a value of MessageTag.Unknown to decode a generic structure with tagging. Use a specific value if the tagging is absent or if a known structure is passed in.
        Parameters:
        rgbData - byte stream to be decoded
        defaultTag - assumed message type to be decoded
        Returns:
        the decoded message object
        Throws:
        CoseException - on a decode failure.
      • EncodeToBytes

        public byte[] EncodeToBytes()
                             throws CoseException
        Encode the message to a byte array. This function will force cryptographic operations to be executed as needed.
        Returns:
        byte encoded object
        Throws:
        CoseException - Internal COSE Exception
      • DecodeFromCBORObject

        protected abstract void DecodeFromCBORObject​(com.upokecenter.cbor.CBORObject messageObject)
                                              throws CoseException
        Given a CBOR tree, parse the message. This is an abstract function that is implemented for each different supported COSE message.
        Parameters:
        messageObject - CBORObject to be converted to a message.
        Throws:
        CoseException - Internal COSE Exception
      • EncodeCBORObject

        protected abstract com.upokecenter.cbor.CBORObject EncodeCBORObject()
                                                                     throws CoseException
        Encode the COSE message object to a CBORObject tree. This function call will force cryptographic operations to be executed as needed. This is an internal function, as such it does not add the tag on the front and is implemented on a per message object.
        Returns:
        CBORObject representing the message.
        Throws:
        CoseException - Internal COSE Exception
      • EncodeToCBORObject

        public com.upokecenter.cbor.CBORObject EncodeToCBORObject()
                                                           throws CoseException
        Encode the COSE message object to a CBORObject tree. This function call will force cryptographic operations to be executed as needed.
        Returns:
        CBORObject representing the message.
        Throws:
        CoseException - Internal COSE Exception
      • GetContent

        public byte[] GetContent()
        Return the content bytes of the message
        Returns:
        bytes of the content
      • HasContent

        public boolean HasContent()
        Does the message current have content?
        Returns:
        true if it has content
      • SetContent

        public void SetContent​(byte[] rgbData)
        Set the content bytes of the message. If the message was transmitted with detached content, this must be called before doing cryptographic processing on the message.
        Parameters:
        rgbData - bytes to set as the content
      • SetContent

        public void SetContent​(String strData)
        Set the content bytes as a text string. The string will be encoded using UTF8 into a byte string.
        Parameters:
        strData - string to set as the content
      • addCountersignature

        public void addCountersignature​(CounterSign countersignature)
      • setCountersign1

        public void setCountersign1​(CounterSign1 value)