public void macNoContent() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("No Content Specified")); }
public void macNoAlgorithm() { MAC0Message msg = new MAC0Message(); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("No Algorithm Specified")); }
public void macUnsupportedAlgorithm() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_CCM_16_64_256, Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("MAC algorithm not recognized 11")); }
public void macUnknownAlgorithm() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, CBORObject.FromObject("Unknown"), Attributes.PROTECTED); msg.SetContent(rgbContent); CoseException e = Assert.ThrowsException <CoseException>(() => msg.Compute(rgbKey256)); Assert.AreEqual(e.Message, ("Unknown Algorithm Specified")); }
public void testRoundTrip() { MAC0Message msg = new MAC0Message(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.SetContent(rgbContent); msg.Compute(rgbKey256); byte[] rgbMsg = msg.EncodeToBytes(); msg = (MAC0Message)Message.DecodeFromBytes(rgbMsg, Tags.MAC0); Boolean contentNew = msg.Validate(rgbKey256); Assert.AreEqual(contentNew, (true)); }
public void testAddAttribute_3() { byte[] rgbKey = new byte[256 / 8]; MAC0Message msg = new MAC0Message(); msg.SetContent("ABCDE"); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.HMAC_SHA_256, Attributes.PROTECTED); msg.Compute(rgbKey); try { msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); } catch (CoseException e) { Assert.AreEqual(e.Message, "Operation would modify integrity protected attributes"); } }