public class Signer extends Object
Create a Signer object for adding a new signature to a message, existing signers will have a Signer object created for them when a SignMessage object is created by Message.DecodeFromBytes.
Examples of using this class can be found in
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.
| Modifier and Type | Field and Description |
|---|---|
protected String |
contextString |
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_SEND
|
protected byte[] |
externalData
Holder for the external data object that is authenticated as part of the
message
|
protected 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 attributes
|
protected com.upokecenter.cbor.CBORObject |
objUnprotected
Internal map of unprotected attributes
|
static 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.PROTECT
|
protected byte[] |
rgbProtected
The encoded byte string for the protected attributes.
|
protected byte[] |
rgbSignature |
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 and Description |
|---|
Signer()
Create a new signer object to add to a SignMessage
|
Signer(OneKey key)
Create a new signer object for a SignMessage and set the key to be used.
|
| Modifier and Type | Method and 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);
|
void |
clearKey()
Remove the key object from the signer
|
protected void |
DecodeFromCBORObject(com.upokecenter.cbor.CBORObject obj)
Internal function used in creating a Sign1Message object from a byte string.
|
protected com.upokecenter.cbor.CBORObject |
EncodeToCBORObject()
Internal function used to create a serialization of a COSE_Sign1 message
|
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 attributes
|
byte[] |
getExternal()
Get the optional external data field to be authenticated
* @return external authenticated data
|
com.upokecenter.cbor.CBORObject |
getProtectedAttributes()
Return the entire map of protected attributes
|
com.upokecenter.cbor.CBORObject |
getUnprotectedAttributes()
Return the entire map of unprotected attributes
|
void |
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
|
void |
setKey(com.upokecenter.cbor.CBORObject keyIn)
Deprecated.
As of COSE 0.9.1, use setKey(OneKey)
|
void |
setKey(OneKey keyIn)
Set a key object on a signer
|
void |
sign(byte[] rgbBodyProtected,
byte[] rgbContent) |
boolean |
validate(byte[] rgbBodyProtected,
byte[] rgbContent) |
protected byte[] rgbSignature
protected String contextString
protected com.upokecenter.cbor.CBORObject objProtected
protected com.upokecenter.cbor.CBORObject objUnprotected
protected com.upokecenter.cbor.CBORObject objDontSend
protected byte[] rgbProtected
protected byte[] externalData
@Deprecated public static final int ProtectedAttributes
@Deprecated public static final int UnprotectedAttributes
@Deprecated public static final int DontSendAttributes
public static final int PROTECTED
public static final int UNPROTECTED
public static final int DO_NOT_SEND
public Signer()
public Signer(OneKey key)
key - key to use for signing.public void clearKey()
@Deprecated public void setKey(com.upokecenter.cbor.CBORObject keyIn) throws CoseException
keyIn - key to be used for signing or verificationCoseException - Errors generated by the COSE modulepublic void setKey(OneKey keyIn) throws CoseException
keyIn - key to be used for signing or verificationCoseExceptionprotected void DecodeFromCBORObject(com.upokecenter.cbor.CBORObject obj)
throws CoseException
obj - COSE_Sign1 encoded object.CoseException - Errors generated by the COSE moduleprotected com.upokecenter.cbor.CBORObject EncodeToCBORObject()
throws CoseException
CoseException - Errors generated by the COSE modulepublic void sign(byte[] rgbBodyProtected,
byte[] rgbContent)
throws CoseException
CoseExceptionpublic boolean validate(byte[] rgbBodyProtected,
byte[] rgbContent)
throws CoseException
CoseExceptionpublic void addAttribute(com.upokecenter.cbor.CBORObject label,
com.upokecenter.cbor.CBORObject value,
int where)
throws CoseException
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 transmittedCoseException - COSE Package exceptionpublic void addAttribute(HeaderKeys label, com.upokecenter.cbor.CBORObject value, int where) throws CoseException
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 transmittedCoseException - COSE Package exceptionpublic void addAttribute(HeaderKeys label, byte[] value, int where) throws CoseException
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 transmittedCoseException - COSE Package exception@Deprecated public void AddProtected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value) throws CoseException
label - CBOR object which identifies the attribute in the mapvalue - CBOR object which contains the value of the attributeCoseException - COSE Package exception@Deprecated public void AddProtected(HeaderKeys label, com.upokecenter.cbor.CBORObject value) throws CoseException
label - HeaderKeys label which identifies the attribute in the mapvalue - CBOR object which contains the value of the attributeCoseException - COSE Package exception@Deprecated public void AddProtected(HeaderKeys label, byte[] value) throws CoseException
label - CBOR object which identifies the attribute in the mapvalue - byte array of valueCoseException - COSE Package exception@Deprecated public void AddUnprotected(com.upokecenter.cbor.CBORObject label, com.upokecenter.cbor.CBORObject value) throws CoseException
label - value identifies the attribute in the mapvalue - value to be associated with the labelCoseException - COSE Package exception@Deprecated public void AddUnprotected(HeaderKeys label, com.upokecenter.cbor.CBORObject value) throws CoseException
label - identifies the attribute in the mapvalue - value to be associated with the labelCoseException - COSE Package exception@Deprecated public void AddUnprotected(HeaderKeys label, byte[] value) throws CoseException
label - identifies the attribute in the mapvalue - value to be associated with the labelCoseException - COSE Package exceptionpublic com.upokecenter.cbor.CBORObject findAttribute(com.upokecenter.cbor.CBORObject label)
label - - Label of the value to be searched forpublic com.upokecenter.cbor.CBORObject findAttribute(com.upokecenter.cbor.CBORObject label,
int where)
label - - HeaderKey enumeration value to search forwhere - which maps to search for the labelpublic com.upokecenter.cbor.CBORObject findAttribute(HeaderKeys label)
label - - HeaderKey enumeration value to search forpublic com.upokecenter.cbor.CBORObject findAttribute(HeaderKeys label, int where)
label - - HeaderKey enumeration value to search forwhere - which maps to search for the labelpublic com.upokecenter.cbor.CBORObject getProtectedAttributes()
public com.upokecenter.cbor.CBORObject getUnprotectedAttributes()
public com.upokecenter.cbor.CBORObject getDoNotSendAttributes()
public void removeAttribute(com.upokecenter.cbor.CBORObject label)
throws CoseException
label - attribute to be removedCoseException - if integrity protection would be modified.public void removeAttribute(HeaderKeys label) throws CoseException
label - attribute to be removedCoseExceptionpublic byte[] getExternal()
public void setExternal(byte[] rgbData)
rgbData - - data to be authenticatedCOSE for Java documentation, generatedin 2016.