Ejemplo n.º 1
0
        public void Constructor_Empty()
        {
            CipherData cipherData = new CipherData();

            Assert.Null(cipherData.CipherReference);
            Assert.Null(cipherData.CipherValue);
            Assert.Throws <CryptographicException>(() => cipherData.GetXml());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }