Package COSE
Class Message
- java.lang.Object
-
- COSE.Attribute
-
- COSE.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 Summary
Fields Modifier and Type Field Description protected booleanemitContentIs the content emitted as part of the message?protected booleanemitTagIs the tag identifying the message emitted?protected MessageTagmessageTagWhat message tag identifies this message?protected byte[]rgbContentWhat is the plain text content of the message.-
Fields inherited from class COSE.Attribute
DO_NOT_SEND, DontSendAttributes, externalData, objDontSend, objProtected, objUnprotected, PROTECTED, ProtectedAttributes, rgbProtected, UNPROTECTED, UnprotectedAttributes
-
-
Constructor Summary
Constructors Constructor Description Message()
-
Method Summary
Modifier and Type Method Description voidaddCountersignature(CounterSign countersignature)static MessageDecodeFromBytes(byte[] rgbData)Decode a COSE message object.static MessageDecodeFromBytes(byte[] rgbData, MessageTag defaultTag)Decode a COSE message object.protected abstract voidDecodeFromCBORObject(com.upokecenter.cbor.CBORObject messageObject)Given a CBOR tree, parse the message.protected abstract com.upokecenter.cbor.CBORObjectEncodeCBORObject()Encode the COSE message object to a CBORObject tree.byte[]EncodeToBytes()Encode the message to a byte array.com.upokecenter.cbor.CBORObjectEncodeToCBORObject()Encode the COSE message object to a CBORObject tree.byte[]GetContent()Return the content bytes of the messageCounterSign1getCountersign1()List<CounterSign>getCountersignerList()booleanHasContent()Does the message current have content?protected voidProcessCounterSignatures()voidSetContent(byte[] rgbData)Set the content bytes of the message.voidSetContent(String strData)Set the content bytes as a text string.voidsetCountersign1(CounterSign1 value)booleanvalidate(CounterSign countersignature)booleanvalidate(CounterSign1 countersignature)-
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
-
-
-
-
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.
-
-
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 ofMessageTag.Unknownto 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 decodeddefaultTag- assumed message type to be decoded- Returns:
- the decoded message object
- Throws:
CoseException- on a decode failure.
-
EncodeToBytes
public byte[] EncodeToBytes() throws CoseExceptionEncode 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 CoseExceptionGiven 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 CoseExceptionEncode 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 CoseExceptionEncode 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)
-
getCountersignerList
public List<CounterSign> getCountersignerList()
-
getCountersign1
public CounterSign1 getCountersign1()
-
setCountersign1
public void setCountersign1(CounterSign1 value)
-
ProcessCounterSignatures
protected void ProcessCounterSignatures() throws CoseException- Throws:
CoseException
-
validate
public boolean validate(CounterSign1 countersignature) throws CoseException
- Throws:
CoseException
-
validate
public boolean validate(CounterSign countersignature) throws CoseException
- Throws:
CoseException
-
-