예제 #1
0
        public void Constructor_Empty()
        {
            CipherData cipherData = new CipherData();

            Assert.Null(cipherData.CipherReference);
            Assert.Null(cipherData.CipherValue);
            Assert.Throws <CryptographicException>(() => cipherData.GetXml());
        }
예제 #2
0
        public void Constructor_CipherValue(byte[] cipherValue)
        {
            CipherData cipherData = new CipherData(cipherValue);

            Assert.Equal(cipherValue, cipherData.CipherValue);
            Assert.Null(cipherData.CipherReference);

            XmlElement xmlElement = cipherData.GetXml();

            Assert.NotNull(xmlElement);
            Assert.Equal(
                $"<CipherData xmlns=\"http://www.w3.org/2001/04/xmlenc#\"><CipherValue>{Convert.ToBase64String(cipherValue)}</CipherValue></CipherData>",
                xmlElement.OuterXml);
        }
예제 #3
0
        public void LoadXml_CipherReference(XmlElement xmlElement, string uri)
        {
            CipherData cipherData = new CipherData();

            cipherData.LoadXml(xmlElement);

            Assert.Equal(uri, cipherData.CipherReference.Uri);
            Assert.Null(cipherData.CipherValue);

            XmlElement gotXmlElement = cipherData.GetXml();

            Assert.NotNull(gotXmlElement);
            Assert.Equal(xmlElement.OuterXml, gotXmlElement.OuterXml);
        }
예제 #4
0
        public void Constructor_CipherReference(CipherReference cipherReference)
        {
            CipherData cipherData = new CipherData(cipherReference);

            Assert.Null(cipherData.CipherValue);
            Assert.Equal(cipherReference, cipherData.CipherReference);

            XmlElement xmlElement = cipherData.GetXml();

            Assert.NotNull(xmlElement);
            if (cipherReference.Uri != string.Empty)
            {
                Assert.Equal(
                    $"<CipherData xmlns=\"http://www.w3.org/2001/04/xmlenc#\"><CipherReference URI=\"{cipherReference.Uri}\" /></CipherData>",
                    xmlElement.OuterXml);
            }
            else
            {
                Assert.Equal(
                    "<CipherData xmlns=\"http://www.w3.org/2001/04/xmlenc#\"><CipherReference /></CipherData>",
                    xmlElement.OuterXml);
            }
        }