Package COSE

Class Sign1Message


  • public class Sign1Message
    extends SignCommon
    The Sign1Message class implements the COSE_Sign1 object. This provides for a single signature where the signer is normally implicitly known. SignMessage need to be used in those cases where more than one signature is needed on a content. There is no way to convert a signed message between the two formats.

    Create a Sign1Message object for a new message, when processing an existing message use Message.DecodeFromBytes to create the Sign1Message object.

    There are examples of using this class:
    Simple Example

    Author:
    jimsch
    • Constructor Detail

      • Sign1Message

        public Sign1Message()
        Create a signed message object for which there will be a leading tag and the content will be included.
      • Sign1Message

        public Sign1Message​(boolean emitTag)
        Create a signed message object. Emission of the leading tag is controlled by the parameter.
        Parameters:
        emitTag - emit leading tag when message is serialized
      • Sign1Message

        public Sign1Message​(boolean emitTag,
                            boolean emitContent)
        Create a signed message object for which the emission of the leading tag and content is controlled by the parameters.
        Parameters:
        emitTag - emit leading tag when message is serialized
        emitContent - emit the content as part of the message
        Since:
        COSE 0.9.1
    • Method Detail

      • sign

        public void sign​(OneKey key)
                  throws CoseException
        Create a signature for the message if one does not exist.
        Parameters:
        key - key to use to sign the message
        Throws:
        CoseException - Errors generated by the COSE module
      • validate

        public boolean validate​(OneKey cnKey)
                         throws CoseException
        Validate the signature on the message using the passed in key.
        Parameters:
        cnKey - key to use for validation
        Returns:
        true if the signature validates
        Throws:
        CoseException - Errors generated by the COSE module
      • DecodeFromCBORObject

        protected void DecodeFromCBORObject​(com.upokecenter.cbor.CBORObject messageObject)
                                     throws CoseException
        Internal function used in creating a Sign1Message object from a byte string.
        Specified by:
        DecodeFromCBORObject in class Message
        Parameters:
        messageObject - COSE_Sign1 encoded object.
        Throws:
        CoseException - Errors generated by the COSE module
      • EncodeCBORObject

        protected com.upokecenter.cbor.CBORObject EncodeCBORObject()
                                                            throws CoseException
        Internal function used to create a serialization of a COSE_Sign1 message
        Specified by:
        EncodeCBORObject in class Message
        Returns:
        CBOR object which can be encoded.
        Throws:
        CoseException - Errors generated by the COSE module