/// <summary> /// Event arguments for legal identity responses /// </summary> /// <param name="e">IQ response event arguments.</param> /// <param name="Identity">Legal Identity.</param> public LegalIdentityEventArgs(IqResultEventArgs e, LegalIdentity Identity) : base(e) { this.identity = Identity; }
/// <summary> /// Parses an identity from its XML representation /// </summary> /// <param name="Xml">XML representation</param> /// <returns>Legal identity</returns> public static LegalIdentity Parse(XmlElement Xml) { List <Property> Properties = new List <Property>(); LegalIdentity Result = new LegalIdentity() { id = XML.Attribute(Xml, "id") }; foreach (XmlNode N in Xml.ChildNodes) { if (N is XmlElement E) { switch (E.LocalName) { case "clientPublicKey": foreach (XmlNode N2 in E.ChildNodes) { if (N2 is XmlElement E2) { IE2eEndpoint Key = EndpointSecurity.ParseE2eKey(E2); if (Key != null && Key.Namespace == EndpointSecurity.IoTHarmonizationE2E) { if (Key is RsaAes RsaAes) { Result.clientKeyName = "RSA" + RsaAes.KeySize.ToString(); Result.clientPubKey1 = RsaAes.Modulus; Result.clientPubKey2 = RsaAes.Exponent; } else if (Key is EcAes256 EcAes256) { Result.clientKeyName = Key.LocalName; Result.ClientPubKey1 = EcAes256.ToNetwork(EcAes256.PublicKey.X); Result.ClientPubKey2 = EcAes256.ToNetwork(EcAes256.PublicKey.Y); } } } } break; case "property": string Name = XML.Attribute(E, "name"); string Value = XML.Attribute(E, "value"); Properties.Add(new Property(Name, Value)); break; case "clientSignature": foreach (XmlAttribute Attr in E.Attributes) { switch (Attr.Name) { case "s1": Result.clientSignature1 = Convert.FromBase64String(Attr.Value); break; case "s2": Result.clientSignature2 = Convert.FromBase64String(Attr.Value); break; } } break; case "status": foreach (XmlAttribute Attr in E.Attributes) { switch (Attr.Name) { case "provider": Result.provider = Attr.Value; break; case "state": if (Enum.TryParse <IdentityState>(Attr.Value, out IdentityState IdentityState)) { Result.state = IdentityState; } break; case "created": if (XML.TryParse(Attr.Value, out DateTime TP)) { Result.created = TP; } break; case "updated": if (XML.TryParse(Attr.Value, out TP)) { Result.updated = TP; } break; case "from": if (XML.TryParse(Attr.Value, out TP)) { Result.from = TP; } break; case "to": if (XML.TryParse(Attr.Value, out TP)) { Result.to = TP; } break; } } break; case "serverSignature": foreach (XmlAttribute Attr in E.Attributes) { switch (Attr.Name) { case "s1": Result.serverSignature1 = Convert.FromBase64String(Attr.Value); break; case "s2": Result.serverSignature2 = Convert.FromBase64String(Attr.Value); break; } } break; } } } Result.properties = Properties.ToArray(); return(Result); }
/// <summary> /// Parses an identity from its XML representation /// </summary> /// <param name="Xml">XML representation</param> /// <returns>Legal identity</returns> public static LegalIdentity Parse(XmlElement Xml) { List <Property> Properties = new List <Property>(); List <Attachment> Attachments = new List <Attachment>(); LegalIdentity Result = new LegalIdentity() { id = XML.Attribute(Xml, "id") }; foreach (XmlNode N in Xml.ChildNodes) { if (N is XmlElement E) { switch (E.LocalName) { case "clientPublicKey": foreach (XmlNode N2 in E.ChildNodes) { if (N2 is XmlElement E2) { IE2eEndpoint Key = EndpointSecurity.ParseE2eKey(E2); if (Key != null && Key.Namespace == EndpointSecurity.IoTHarmonizationE2E) { Result.clientPubKey = Key.PublicKey; if (Key is RsaEndpoint RsaEndpoint) { Result.clientKeyName = "RSA" + RsaEndpoint.KeySize.ToString(); } else { Result.clientKeyName = Key.LocalName; } } } } break; case "property": string Name = XML.Attribute(E, "name"); string Value = XML.Attribute(E, "value"); Properties.Add(new Property(Name, Value)); break; case "clientSignature": Result.clientSignature = Convert.FromBase64String(E.InnerText); break; case "attachment": Attachments.Add(new Attachment() { Id = XML.Attribute(E, "id"), LegalId = Result.id, ContentType = XML.Attribute(E, "contentType"), FileName = XML.Attribute(E, "fileName"), Signature = Convert.FromBase64String(XML.Attribute(E, "s")), Timestamp = XML.Attribute(E, "timestamp", DateTime.MinValue) }); break; case "status": foreach (XmlAttribute Attr in E.Attributes) { switch (Attr.Name) { case "provider": Result.provider = Attr.Value; break; case "state": if (Enum.TryParse <IdentityState>(Attr.Value, out IdentityState IdentityState)) { Result.state = IdentityState; } break; case "created": if (XML.TryParse(Attr.Value, out DateTime TP)) { Result.created = TP; } break; case "updated": if (XML.TryParse(Attr.Value, out TP)) { Result.updated = TP; } break; case "from": if (XML.TryParse(Attr.Value, out TP)) { Result.from = TP; } break; case "to": if (XML.TryParse(Attr.Value, out TP)) { Result.to = TP; } break; } } break; case "serverSignature": Result.serverSignature = Convert.FromBase64String(E.InnerText); break; case "attachmentRef": string AttachmentId = XML.Attribute(E, "attachmentId"); string Url = XML.Attribute(E, "url"); foreach (Attachment Attachment in Attachments) { if (Attachment.Id == AttachmentId) { Attachment.Url = Url; break; } } break; } } } Result.properties = Properties.ToArray(); Result.attachments = Attachments.ToArray(); return(Result); }