Package COSE

Class SignMessage


  • public class SignMessage
    extends Message
    The SignMessage class is used to implement the COSE_Sign object. This provides for a signed object with content and one or more signatures attached. The signatures can be either from a single signer or from multiple different signers. In the case where only one signature is required and the signer can be implicitly known, Sign1Message can be used instead. There is no way to convert a signed message between the two formats.

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

    Examples can be found at
    Single Signer Example an example of signing and verify a message with a single signature.
    Multiple Signer Example an example of signing and verifying a message which has multiple signatures.

    Author:
    jimsch
    • Field Detail

    • Constructor Detail

      • SignMessage

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

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

      • DecodeFromCBORObject

        protected void DecodeFromCBORObject​(com.upokecenter.cbor.CBORObject obj)
                                     throws CoseException
        Internal function used in creating a SignMessage object from a byte string.
        Specified by:
        DecodeFromCBORObject in class Message
        Parameters:
        obj - COSE_Sign 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_Sign message
        Specified by:
        EncodeCBORObject in class Message
        Returns:
        CBOR object which can be encoded.
        Throws:
        CoseException - Errors generated by the COSE module
      • AddSigner

        public void AddSigner​(Signer signedBy)
        Add a new signer to the message. The details of the signer are provided by the Signer object being added.
        Parameters:
        signedBy - provides a Signer object containing details for the signer
      • getSigner

        public Signer getSigner​(int iSigner)
        Return the i-th signer of the message.
        Parameters:
        iSigner - - which signer to be returned
        Returns:
        Signer object
      • getSignerCount

        public int getSignerCount()
        Return the number of signers on the message
        Returns:
        number of elements in the signer list
      • getSignerList

        public List<Signer> getSignerList()
        Return the list of signers on the message
        Returns:
        a list of all of the Signer objects.
      • sign

        public void sign()
                  throws CoseException
        Causes a signature to be created for every signer that does not already have one.
        Throws:
        CoseException - Errors generated by the COSE module
      • validate

        public boolean validate​(Signer signerToUse)
                         throws CoseException
        Validate the signature on a message for a specific signer. The signer is required to be one of the Signer objects attached to the message. The key must be attached to the signer before making this call.
        Parameters:
        signerToUse - which signer to validate with
        Returns:
        true if the message validates with the signer
        Throws:
        CoseException - Errors generated by the COSE module