Exemplo n.º 1
0
        /// <summary>
        /// When overridden in a descendant class, deserializes the object from an XML according to Aadhaar API specification.
        /// </summary>
        /// <param name="element">An instance of <see cref="XElement"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="element"/> is null.</exception>
        protected virtual void DeserializeXml(XElement element)
        {
            ValidateNull(element, nameof(element));

            AadhaarNumber = element.Attribute("uid").Value;
            Terminal      = element.Attribute("tid").Value;
            Timestamp     = DateTimeOffset.ParseExact(element.Attribute("ts").Value, AadhaarHelper.TimestampFormat, CultureInfo.InvariantCulture);
            DeviceInfo    = new Metadata(element.Element("Meta"));
            KeyInfo       = new SessionKeyInfo(element.Element("Skey"));
            Data          = new EncryptedData(element.Element("Data"));
            Hmac          = element.Element("Hmac").Value;
        }
Exemplo n.º 2
0
        /// <summary>
        /// When overridden in a descendant class, deserializes the object from an XML according to Aadhaar API specification.
        /// </summary>
        /// <param name="element">An instance of <see cref="XElement"/>.</param>
        protected override void DeserializeXml(XElement element)
        {
            base.DeserializeXml(element);

            AadhaarNumber = element.Attribute("uid").Value;
            KeyInfo       = new SessionKeyInfo(element.Element("Skey"));
            Data          = new EncryptedData(element.Element("Data"));
            Hmac          = element.Element("Hmac").Value;

            var meta = element.Element("Meta");

            meta.Add(new XAttribute("idc", Metadata.DeviceNotApplicable));
            DeviceInfo = new Metadata(meta);
        }
Exemplo n.º 3
0
        /// <summary>
        /// When overridden in a descendant class, deserializes the object from an XML according to Aadhaar API specification.
        /// </summary>
        /// <param name="element">An instance of <see cref="XElement"/>.</param>
        protected override void DeserializeXml(XElement element)
        {
            base.DeserializeXml(element);

            AadhaarNumber = element.Attribute("uid").Value;
            Uses          = new AuthUsage(element.Element("Uses"));
            DeviceInfo    = new Metadata(element.Element("Meta"));
            KeyInfo       = new SessionKeyInfo(element.Element("Skey"));
            Data          = new EncryptedData(element.Element("Data"));
            Hmac          = element.Element("Hmac").Value;

            var tkn = element.Element("Tkn");

            Token = tkn != null ? new Token(tkn) : null;
        }
        public void FromXmlTest()
        {
            /*
             * Assume:     ToXml(string) is correct.
             */
            var sessionKey = new SessionKeyInfo();
            var xml        = XElement.Parse(File.ReadAllText(Data.SessionKeyInfoXml)).Elements().ToArray();

            // Validate null argument.
            Assert.Throws <ArgumentNullException>("element", () => sessionKey.FromXml(null));

            // XML must be same after loading and deserializing it.
            foreach (var element in xml)
            {
                sessionKey.FromXml(element);
                Assert.True(XNode.DeepEquals(element, sessionKey.ToXml("Skey")));
            }
        }