Add Sign0 corners
diff --git a/src/Encrypt.c b/src/Encrypt.c
index 57a25b4..dd253c7 100644
--- a/src/Encrypt.c
+++ b/src/Encrypt.c
@@ -101,6 +101,11 @@
 
 	if (!IsValidEnvelopedHandle(h)) return false;
 
+	if (p->m_message.m_refCount > 1) {
+		p->m_message.m_refCount--;
+		return true;
+	}
+
 #ifdef USE_CBOR_CONTEXT
 	context = ((COSE_Enveloped *)h)->m_message.m_allocContext;
 #endif
diff --git a/test/mac_test.c b/test/mac_test.c
index f14879a..630698e 100644
--- a/test/mac_test.c
+++ b/test/mac_test.c
@@ -383,6 +383,7 @@
 	if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) CFails++;
 	if (COSE_Mac_AddRecipient((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) CFails++;
 	if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, NULL)) CFails++;
+	if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, NULL)) CFails++;
 	if (COSE_Mac_Free((HCOSE_MAC)hEncrypt)) CFails++;
 
     hEncrypt = COSE_Encrypt_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
@@ -394,6 +395,7 @@
 	if (COSE_Mac_validate((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) CFails++;
 	if (COSE_Mac_AddRecipient((HCOSE_MAC)hEncrypt, (HCOSE_RECIPIENT)hMAC, NULL)) CFails++;
 	if (COSE_Mac_GetRecipient((HCOSE_MAC)hEncrypt, 0, NULL)) CFails++;
+	if (COSE_Mac_SetExternal((HCOSE_MAC)hEncrypt, rgb, 0, NULL)) CFails++;
 	if (COSE_Mac_Free((HCOSE_MAC)hEncrypt)) CFails++;
 
     //
@@ -433,6 +435,7 @@
 	if (COSE_Mac0_map_put_int((HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) CFails++;
 	if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) CFails++;
 	if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) CFails++;
+	if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, NULL)) CFails++;
 	if (COSE_Mac0_Free((HCOSE_MAC0)hEncrypt)) CFails++;
 
 	hEncrypt = COSE_Encrypt_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
@@ -442,6 +445,7 @@
 	if (COSE_Mac0_map_put_int((HCOSE_MAC0)hEncrypt, 1, cn, COSE_PROTECT_ONLY, NULL)) CFails++;
 	if (COSE_Mac0_encrypt((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) CFails++;
 	if (COSE_Mac0_validate((HCOSE_MAC0)hEncrypt, rgb, 10, NULL)) CFails++;
+	if (COSE_Mac0_SetExternal((HCOSE_MAC0)hEncrypt, rgb, 0, NULL)) CFails++;
 
 	if (COSE_Mac0_Free((HCOSE_MAC0)hEncrypt)) CFails++;
 
diff --git a/test/sign.c b/test/sign.c
index 9c4838d..0cd4183 100644
--- a/test/sign.c
+++ b/test/sign.c
@@ -415,3 +415,51 @@
 
 	return;
 }
+
+void Sign0_Corners()
+{
+	HCOSE_SIGN0 hSign = NULL;
+	HCOSE_SIGN0 hSign2;
+	byte rgb[10];
+	cn_cbor * cn = cn_cbor_int_create(5, CBOR_CONTEXT_PARAM_COMMA NULL);
+
+	hSign2 = COSE_Sign0_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
+	//  Missing case - addref then release on item
+
+	//  Incorrect algorithm
+
+	//  Null handle checks
+
+	if (COSE_Sign0_SetContent(hSign, rgb, 10, NULL)) CFails++;
+	if (COSE_Sign0_map_get_int(hSign, 1, COSE_BOTH, NULL)) CFails++;
+	if (COSE_Sign0_map_put_int(hSign, 1, cn, COSE_PROTECT_ONLY, NULL)) CFails++;
+	if (COSE_Sign0_Sign(hSign, cn, NULL)) CFails++;
+	if (COSE_Sign0_Sign(hSign2, NULL, NULL)) CFails++;
+	if (COSE_Sign0_validate(hSign, cn, NULL)) CFails++;
+	if (COSE_Sign0_validate(hSign2, NULL, NULL)) CFails++;
+	if (COSE_Sign0_SetExternal(hSign, rgb, sizeof(rgb), NULL)) CFails++;
+
+	hSign = (HCOSE_SIGN0)COSE_Encrypt_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
+
+	if (COSE_Sign0_SetContent(hSign, rgb, 10, NULL)) CFails++;
+	if (COSE_Sign0_map_get_int(hSign, 1, COSE_BOTH, NULL)) CFails++;
+	if (COSE_Sign0_map_put_int(hSign, 1, cn, COSE_PROTECT_ONLY, NULL)) CFails++;
+	if (COSE_Sign0_Sign(hSign, cn, NULL)) CFails++;
+	if (COSE_Sign0_validate(hSign, cn, NULL)) CFails++;
+	if (COSE_Sign0_SetExternal(hSign, rgb, sizeof(rgb), NULL)) CFails++;
+
+	//
+	//  Unsupported algorithm
+
+	hSign = COSE_Sign0_Init(CBOR_CONTEXT_PARAM_COMMA NULL);
+	if (hSign == NULL) CFails++;
+
+	if (!COSE_Sign0_SetContent(hSign, (byte *) "Message", 7, NULL)) CFails++;
+	if (!COSE_Sign0_map_put_int(hSign, COSE_Header_Algorithm, cn_cbor_int_create(-99, CBOR_CONTEXT_PARAM_COMMA NULL), COSE_PROTECT_ONLY, NULL)) CFails++;
+	if (COSE_Sign0_Sign(hSign, cn, NULL)) CFails++;
+
+	if (!COSE_Sign0_map_put_int(hSign, COSE_Header_Algorithm, cn_cbor_string_create("hmac", CBOR_CONTEXT_PARAM_COMMA NULL), COSE_PROTECT_ONLY, NULL)) CFails++;
+	if (COSE_Sign0_Sign(hSign, cn, NULL)) CFails++;
+
+	return;
+}
diff --git a/test/test.c b/test/test.c
index baf54a8..60f6014 100644
--- a/test/test.c
+++ b/test/test.c
@@ -466,12 +466,13 @@
 
 void RunCorners()
 {
-    	Test_cn_cbor_array_replace();
-        MAC_Corners();
-		MAC0_Corners();
-		Encrypt_Corners();
-		Enveloped_Corners();
-		Sign_Corners();
+	Test_cn_cbor_array_replace();
+	MAC_Corners();
+	MAC0_Corners();
+	Encrypt_Corners();
+	Enveloped_Corners();
+	Sign_Corners();
+	Sign0_Corners();
 }
 
 void RunMemoryTest(const char * szFileName)
diff --git a/test/test.h b/test/test.h
index 2837ab2..967bd48 100644
--- a/test/test.h
+++ b/test/test.h
@@ -30,6 +30,7 @@
 int ValidateSign0(const cn_cbor * pControl);
 int BuildSign0Message(const cn_cbor * pControl);
 void Sign_Corners();
+void Sign0_Corners();
 
 
 // mac_testc