Package COSE
Class SignMessage
- java.lang.Object
-
- COSE.Attribute
-
- COSE.Message
-
- COSE.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,Sign1Messagecan 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 Summary
Fields Modifier and Type Field Description protected List<Signer>signerList-
Fields inherited from class COSE.Message
emitContent, emitTag, messageTag, rgbContent
-
Fields inherited from class COSE.Attribute
DO_NOT_SEND, DontSendAttributes, externalData, objDontSend, objProtected, objUnprotected, PROTECTED, ProtectedAttributes, rgbProtected, UNPROTECTED, UnprotectedAttributes
-
-
Constructor Summary
Constructors Constructor Description SignMessage()Create a signed message object for which the leading tag and the content will be included.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.
-
Method Summary
Modifier and Type Method Description voidAddSigner(Signer signedBy)Add a new signer to the message.protected voidDecodeFromCBORObject(com.upokecenter.cbor.CBORObject obj)Internal function used in creating a SignMessage object from a byte string.protected com.upokecenter.cbor.CBORObjectEncodeCBORObject()Internal function used to create a serialization of a COSE_Sign messageSignergetSigner(int iSigner)Return the i-th signer of the message.intgetSignerCount()Return the number of signers on the messageList<Signer>getSignerList()Return the list of signers on the messagevoidsign()Causes a signature to be created for every signer that does not already have one.booleanvalidate(Signer signerToUse)Validate the signature on a message for a specific signer.-
Methods inherited from class COSE.Message
addCountersignature, DecodeFromBytes, DecodeFromBytes, EncodeToBytes, EncodeToCBORObject, GetContent, getCountersign1, getCountersignerList, HasContent, ProcessCounterSignatures, SetContent, SetContent, setCountersign1, validate, validate
-
Methods inherited from class COSE.Attribute
addAttribute, addAttribute, addAttribute, AddProtected, AddProtected, AddProtected, AddUnprotected, AddUnprotected, AddUnprotected, findAttribute, findAttribute, findAttribute, findAttribute, getDoNotSendAttributes, getExternal, getProtectedAttributes, getUnprotectedAttributes, removeAttribute, removeAttribute, setExternal
-
-
-
-
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 serializedemitContentIn- emit the content as part of the message
-
-
Method Detail
-
DecodeFromCBORObject
protected void DecodeFromCBORObject(com.upokecenter.cbor.CBORObject obj) throws CoseExceptionInternal function used in creating a SignMessage object from a byte string.- Specified by:
DecodeFromCBORObjectin classMessage- Parameters:
obj- COSE_Sign encoded object.- Throws:
CoseException- Errors generated by the COSE module
-
EncodeCBORObject
protected com.upokecenter.cbor.CBORObject EncodeCBORObject() throws CoseExceptionInternal function used to create a serialization of a COSE_Sign message- Specified by:
EncodeCBORObjectin classMessage- 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 CoseExceptionCauses 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
-
-