Package COSE
Class Attribute
- java.lang.Object
-
- COSE.Attribute
-
public class Attribute extends Object
Internal class which supports the protected and unprotected attribute maps that are common to the core COSE objects.In addition an attribute map is provided for attributes which will not be sent as part of the message, but which are needed for the code to function correctly. As an example of how this works, there are some situations where the algorithm identifier is not sent as part of an encrypted message, however it is needed in order to encrypt or decrypt the content so the application would set it in the unsent package at send time - for encryption - or at receive time - for decryption.
- Author:
- jimsch
-
-
Field Summary
Fields Modifier and Type Field Description static int
DO_NOT_SEND
Used to place an attribute in the do not send attribute map Attributes in this map are available for lookup and use but will not be transmitted as part of the message.static int
DontSendAttributes
Deprecated.As of COSE 0.9.1, use Attribute.DO_NOT_SENDprotected byte[]
externalData
Holder for the external data object that is authenticated as part of the messageprotected com.upokecenter.cbor.CBORObject
objDontSend
Internal map of attributes which are not a part of the encoded message.protected com.upokecenter.cbor.CBORObject
objProtected
Internal map of protected attributesprotected com.upokecenter.cbor.CBORObject
objUnprotected
Internal map of unprotected attributesstatic int
PROTECTED
Used to place an attribute in the protected attribute map Attributes placed in this map are part of the integrity check if the cryptographic algorithm supports authenticated data.static int
ProtectedAttributes
Deprecated.As of COSE 0.9.1, use Attribute.PROTECTprotected byte[]
rgbProtected
The encoded byte string for the protected attributes.static int
UNPROTECTED
Used to place an attribute in the unprotected attribute map Attributes placed in this map are not integrity protected.static int
UnprotectedAttributes
Deprecated.As of COSE 0.9.1, use Attribute.UNPROTECT
-
Constructor Summary
Constructors Constructor Description Attribute()
-
Method Summary
Modifier and Type Method Description void
addAttribute(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value, int where)
Set an attribute in the COSE object.void
addAttribute(HeaderKeys label, byte[] value, int where)
Set an attribute in the COSE object.void
addAttribute(HeaderKeys label, com.upokecenter.cbor.CBORObject value, int where)
Set an attribute in the COSE object.void
AddProtected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value)
Deprecated.As of COSE 0.9.0, use addAttribute(CBORObject, CBORObject, Attribute.PROTECTED);void
AddProtected(HeaderKeys label, byte[] value)
Deprecated.As of COSE 0.9.0, use addAttribute(HeaderKeys, byte[], Attribute.PROTECTED);void
AddProtected(HeaderKeys label, com.upokecenter.cbor.CBORObject value)
Deprecated.As of COSE 0.9.0, use addAttribute(HeaderKeys, CBORObject, Attribute.PROTECTED);void
AddUnprotected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value)
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);void
AddUnprotected(HeaderKeys label, byte[] value)
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);void
AddUnprotected(HeaderKeys label, com.upokecenter.cbor.CBORObject value)
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);com.upokecenter.cbor.CBORObject
findAttribute(com.upokecenter.cbor.CBORObject label)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.com.upokecenter.cbor.CBORObject
findAttribute(com.upokecenter.cbor.CBORObject label, int where)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.com.upokecenter.cbor.CBORObject
findAttribute(HeaderKeys label)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.com.upokecenter.cbor.CBORObject
findAttribute(HeaderKeys label, int where)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.com.upokecenter.cbor.CBORObject
getDoNotSendAttributes()
Return the entire map of do not send attributesbyte[]
getExternal()
Get the optional external data field to be authenticatedcom.upokecenter.cbor.CBORObject
getProtectedAttributes()
Return the entire map of protected attributescom.upokecenter.cbor.CBORObject
getUnprotectedAttributes()
Return the entire map of unprotected attributesvoid
removeAttribute(com.upokecenter.cbor.CBORObject label)
Remove an attribute from the set of all attribute maps.void
removeAttribute(HeaderKeys label)
Remove an attribute from the set of all attribute maps.void
setExternal(byte[] rgbData)
Set the optional external data field to be authenticated
-
-
-
Field Detail
-
objProtected
protected com.upokecenter.cbor.CBORObject objProtected
Internal map of protected attributes
-
objUnprotected
protected com.upokecenter.cbor.CBORObject objUnprotected
Internal map of unprotected attributes
-
objDontSend
protected com.upokecenter.cbor.CBORObject objDontSend
Internal map of attributes which are not a part of the encoded message.
-
rgbProtected
protected byte[] rgbProtected
The encoded byte string for the protected attributes. If this variable is set then the message was either decoded or as been cryptographically signed/encrypted/maced. If it is set, then do not allow objProtected to be modified.
-
externalData
protected byte[] externalData
Holder for the external data object that is authenticated as part of the message
-
ProtectedAttributes
@Deprecated public static final int ProtectedAttributes
Deprecated.As of COSE 0.9.1, use Attribute.PROTECTUsed to place an attribute in the protected attribute map Attributes placed in this map are part of the integrity check if the cryptographic algorithm supports authenticated data.- See Also:
- Constant Field Values
-
UnprotectedAttributes
@Deprecated public static final int UnprotectedAttributes
Deprecated.As of COSE 0.9.1, use Attribute.UNPROTECTUsed to place an attribute in the unprotected attribute map Attributes placed in this map are not integrity protected.- See Also:
- Constant Field Values
-
DontSendAttributes
@Deprecated public static final int DontSendAttributes
Deprecated.As of COSE 0.9.1, use Attribute.DO_NOT_SENDUsed to place an attribute in the do not send attribute map Attributes in this map are available for lookup and use but will not be transmitted as part of the message.- See Also:
- Constant Field Values
-
PROTECTED
public static final int PROTECTED
Used to place an attribute in the protected attribute map Attributes placed in this map are part of the integrity check if the cryptographic algorithm supports authenticated data.- See Also:
- Constant Field Values
-
UNPROTECTED
public static final int UNPROTECTED
Used to place an attribute in the unprotected attribute map Attributes placed in this map are not integrity protected.- See Also:
- Constant Field Values
-
DO_NOT_SEND
public static final int DO_NOT_SEND
Used to place an attribute in the do not send attribute map Attributes in this map are available for lookup and use but will not be transmitted as part of the message.- See Also:
- Constant Field Values
-
-
Method Detail
-
addAttribute
public void addAttribute(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value, int where) throws CoseException
Set an attribute in the COSE object. Setting an attribute in one map will remove it from all other maps as a side effect.- Parameters:
label
- CBOR object which identifies the attribute in the mapvalue
- CBOR object which contains the value of the attributewhere
- Identifies which of the buckets to place the attribute in. ProtectedAttributes - attributes cryptographically protected UnprotectedAttributes - attributes not cryptographically protected DontSendAttributes - attributes used locally and not transmitted- Throws:
CoseException
- COSE Package exception
-
addAttribute
public void addAttribute(HeaderKeys label, com.upokecenter.cbor.CBORObject value, int where) throws CoseException
Set an attribute in the COSE object. Setting an attribute in one map will remove it from all other maps as a side effect.- Parameters:
label
- HeaderKeys label which identifies the attribute in the mapvalue
- CBOR object which contains the value of the attributewhere
- Identifies which of the buckets to place the attribute in. ProtectedAttributes - attributes cryptographically protected UnprotectedAttributes - attributes not cryptographically protected DontSendAttributes - attributes used locally and not transmitted- Throws:
CoseException
- COSE Package exception
-
addAttribute
public void addAttribute(HeaderKeys label, byte[] value, int where) throws CoseException
Set an attribute in the COSE object. Setting an attribute in one map will remove it from all other maps as a side effect.- Parameters:
label
- HeaderKeys label which identifies the attribute in the mapvalue
- CBOR object which contains the value of the attributewhere
- Identifies which of the buckets to place the attribute in. ProtectedAttributes - attributes cryptographically protected UnprotectedAttributes - attributes not cryptographically protected DontSendAttributes - attributes used locally and not transmitted- Throws:
CoseException
- COSE Package exception
-
AddProtected
@Deprecated public void AddProtected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value) throws CoseException
Deprecated.As of COSE 0.9.0, use addAttribute(CBORObject, CBORObject, Attribute.PROTECTED);Set an attribute in the protect bucket of the COSE object- Parameters:
label
- CBOR object which identifies the attribute in the mapvalue
- CBOR object which contains the value of the attribute- Throws:
CoseException
- COSE Package exception
-
AddProtected
@Deprecated public void AddProtected(HeaderKeys label, com.upokecenter.cbor.CBORObject value) throws CoseException
Deprecated.As of COSE 0.9.0, use addAttribute(HeaderKeys, CBORObject, Attribute.PROTECTED);Set an attribute in the protect bucket of the COSE object- Parameters:
label
- HeaderKeys label which identifies the attribute in the mapvalue
- CBOR object which contains the value of the attribute- Throws:
CoseException
- COSE Package exception
-
AddProtected
@Deprecated public void AddProtected(HeaderKeys label, byte[] value) throws CoseException
Deprecated.As of COSE 0.9.0, use addAttribute(HeaderKeys, byte[], Attribute.PROTECTED);Set an attribute in the protect bucket of the COSE object- Parameters:
label
- CBOR object which identifies the attribute in the mapvalue
- byte array of value- Throws:
CoseException
- COSE Package exception
-
AddUnprotected
@Deprecated public void AddUnprotected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value) throws CoseException
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);Set an attribute in the unprotected bucket of the COSE object- Parameters:
label
- value identifies the attribute in the mapvalue
- value to be associated with the label- Throws:
CoseException
- COSE Package exception
-
AddUnprotected
@Deprecated public void AddUnprotected(HeaderKeys label, com.upokecenter.cbor.CBORObject value) throws CoseException
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);Set an attribute in the unprotected bucket of the COSE object- Parameters:
label
- identifies the attribute in the mapvalue
- value to be associated with the label- Throws:
CoseException
- COSE Package exception
-
AddUnprotected
@Deprecated public void AddUnprotected(HeaderKeys label, byte[] value) throws CoseException
Deprecated.As of COSE 0.9.1, use addAttribute(HeaderKeys, byte[], Attribute.UNPROTECTED);Set an attribute in the unprotected bucket of the COSE object- Parameters:
label
- identifies the attribute in the mapvalue
- value to be associated with the label- Throws:
CoseException
- COSE Package exception
-
findAttribute
public com.upokecenter.cbor.CBORObject findAttribute(com.upokecenter.cbor.CBORObject label)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.- Parameters:
label
- - Label of the value to be searched for- Returns:
- - CBORObject with the value if found; otherwise null
-
findAttribute
public com.upokecenter.cbor.CBORObject findAttribute(com.upokecenter.cbor.CBORObject label, int where)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.- Parameters:
label
- - HeaderKey enumeration value to search forwhere
- which maps to search for the label- Returns:
- - CBORObject with the value if found; otherwise null
-
findAttribute
public com.upokecenter.cbor.CBORObject findAttribute(HeaderKeys label)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.- Parameters:
label
- - HeaderKey enumeration value to search for- Returns:
- - CBORObject with the value if found; otherwise null
-
findAttribute
public com.upokecenter.cbor.CBORObject findAttribute(HeaderKeys label, int where)
Locate an attribute in one of the attribute buckets The buckets are searched in the order protected, unprotected, unsent.- Parameters:
label
- - HeaderKey enumeration value to search forwhere
- which maps to search for the label- Returns:
- - CBORObject with the value if found; otherwise null
-
getProtectedAttributes
public com.upokecenter.cbor.CBORObject getProtectedAttributes()
Return the entire map of protected attributes- Returns:
- the protected attribute map
-
getUnprotectedAttributes
public com.upokecenter.cbor.CBORObject getUnprotectedAttributes()
Return the entire map of unprotected attributes- Returns:
- the unprotected attribute map
-
getDoNotSendAttributes
public com.upokecenter.cbor.CBORObject getDoNotSendAttributes()
Return the entire map of do not send attributes- Returns:
- the do not send attribute map
-
removeAttribute
public void removeAttribute(com.upokecenter.cbor.CBORObject label) throws CoseException
Remove an attribute from the set of all attribute maps.- Parameters:
label
- attribute to be removed- Throws:
CoseException
- if integrity protection would be modified.
-
removeAttribute
public void removeAttribute(HeaderKeys label) throws CoseException
Remove an attribute from the set of all attribute maps.- Parameters:
label
- attribute to be removed- Throws:
CoseException
- - Label not present
-
getExternal
public byte[] getExternal()
Get the optional external data field to be authenticated- Returns:
- external authenticated data
-
setExternal
public void setExternal(byte[] rgbData)
Set the optional external data field to be authenticated- Parameters:
rgbData
- - data to be authenticated
-
-