Пример #1
0
        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"));
        }
Пример #2
0
        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"));
        }
Пример #3
0
        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"));
        }
Пример #4
0
        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"));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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");
            }
        }