protected override XElement getContent(XNamespace ns)
        {
            XNamespace ns1        = Consts.XML_XEP_0384_NAMESPACE;
            XElement   bundleNode = new XElement(ns1 + "bundle");

            XElement sigPreKeyNode = new XElement(ns1 + "signedPreKeyPublic");

            sigPreKeyNode.Add(new XAttribute("signedPreKeyId", SIGNED_PRE_KEY_ID));
            sigPreKeyNode.Value = Convert.ToBase64String(PUBLIC_SIGNED_PRE_KEY.serialize());
            bundleNode.Add(sigPreKeyNode);

            XElement sigPreKeySigNode = new XElement(ns1 + "signedPreKeySignature")
            {
                Value = Convert.ToBase64String(SIGNED_PRE_KEY_SIGNATURE)
            };

            bundleNode.Add(sigPreKeySigNode);

            XElement identKeyNode = new XElement(ns1 + "identityKey")
            {
                Value = Convert.ToBase64String(PUBLIC_IDENTITY_KEY.serialize())
            };

            bundleNode.Add(identKeyNode);

            if (PUBLIC_PRE_KEYS.Count < 20)
            {
                throw new InvalidOperationException("Failed to convert " + nameof(OmemoBundleInformation) + " to an " + nameof(XElement) + "! Less then 20 PreKeys given.");
            }

            XElement preKeysNode = new XElement(ns1 + "prekeys");
            XElement preKeyNode;

            foreach (Tuple <uint, ECPublicKey> key in PUBLIC_PRE_KEYS)
            {
                preKeyNode = new XElement(ns1 + "preKeyPublic")
                {
                    Value = Convert.ToBase64String(key.Item2.serialize())
                };
                preKeyNode.Add(new XAttribute("preKeyId", key.Item1));
                preKeysNode.Add(preKeyNode);
            }
            bundleNode.Add(preKeysNode);
            return(bundleNode);
        }
Beispiel #2
0
        protected override XElement getContent(XNamespace ns)
        {
            XNamespace ns1        = Consts.XML_XEP_0384_NAMESPACE;
            XElement   bundleNode = new XElement(ns1 + "bundle");

            XElement sigPreKeyNode = new XElement(ns1 + "signedPreKeyPublic");

            sigPreKeyNode.Add(new XAttribute("signedPreKeyId", SIGNED_PRE_KEY_ID));
            sigPreKeyNode.Value = Convert.ToBase64String(PUBLIC_SIGNED_PRE_KEY.serialize());
            bundleNode.Add(sigPreKeyNode);

            XElement sigPreKeySigNode = new XElement(ns1 + "signedPreKeySignature")
            {
                Value = Convert.ToBase64String(SIGNED_PRE_KEY_SIGNATURE)
            };

            bundleNode.Add(sigPreKeySigNode);

            XElement identKeyNode = new XElement(ns1 + "identityKey")
            {
                Value = Convert.ToBase64String(PUBLIC_IDENTITY_KEY.serialize())
            };

            bundleNode.Add(identKeyNode);

            XElement preKeysNode = new XElement(ns1 + "prekeys");
            XElement preKeyNode;

            foreach (Tuple <uint, ECPublicKey> key in PUBLIC_PRE_KEYS)
            {
                preKeyNode = new XElement(ns1 + "preKeyPublic")
                {
                    Value = Convert.ToBase64String(key.Item2.serialize())
                };
                preKeyNode.Add(new XAttribute("preKeyId", key.Item1));
                preKeysNode.Add(preKeyNode);
            }
            bundleNode.Add(preKeysNode);
            return(bundleNode);
        }