Esempio n. 1
0
        public void Deserialize(XElement input, AXMLSerializationSettings opt)
        {
            if (input.Name.LocalName != "config")
            {
                throw new Exception("LocalName != 'config'");
            }

            Name = XHelper.GetChildValue(input, "Name", "headless");
        }
Esempio n. 2
0
        private XElement SerializeRemoteStorageAccount(RemoteStorageAccount rsa, AXMLSerializationSettings opt)
        {
            var x = CreateXElem("Account", SettingObjectTypeEnum.RemoteStorageAccount, null, opt);

            x.Add(CreateXElem("ID", SettingObjectTypeEnum.Guid, rsa.ID.ToString("B"), opt));
            x.Add(CreateXElem("Plugin", SettingObjectTypeEnum.Guid, rsa.Plugin.GetUniqueID().ToString("B"), opt));
            x.Add(CreateXElem("Config", "Generic", rsa.Config.Serialize(opt), opt));
            return(x);
        }
Esempio n. 3
0
        private RemoteStorageAccount DeserializeRemoteStorageAccount(XElement e, AXMLSerializationSettings opt)
        {
            var rsa = new RemoteStorageAccount();

            rsa.ID     = XHelper.GetChildValue(e, "ID", Guid.Empty);
            rsa.Plugin = PluginManagerSingleton.Inst.GetPlugin(XHelper.GetChildValue(e, "Plugin", Guid.Empty));
            rsa.Config = rsa.Plugin.CreateEmptyRemoteStorageConfiguration();
            rsa.Config.Deserialize(XHelper.GetChildOrThrow(e, "Config").Elements().Single(), opt);
            return(rsa);
        }
Esempio n. 4
0
        private XElement CreateXElem(string name, object type, object content, AXMLSerializationSettings opt)
        {
            var r = content != null ? new XElement(name, content) : new XElement(name);

            if (type != null && (opt & AXMLSerializationSettings.IncludeTypeInfo) != 0)
            {
                r.Add(new XAttribute("type", type));
            }
            return(r);
        }
Esempio n. 5
0
        public void Deserialize(XElement input, AXMLSerializationSettings opt)
        {
            if (input.Name.LocalName != "config")
            {
                throw new Exception("LocalName != 'config'");
            }

            Email      = XHelper.GetChildValue(input, "Username", Email);
            Password   = Decrypt(XHelper.GetChildValue(input, "Password", string.Empty), opt);
            UseSandbox = XHelper.GetChildValue(input, "UseSandbox", UseSandbox);
        }
Esempio n. 6
0
        public void Deserialize(XElement input, AXMLSerializationSettings opt)
        {
            if (input.Name.LocalName != "config")
            {
                throw new Exception("LocalName != 'config'");
            }

            Folder      = XHelper.GetChildValue(input, "Folder", string.Empty);
            Extension   = XHelper.GetChildValue(input, "Extension", "txt");
            StrEncoding = XHelper.GetChildValue(input, "Encoding", "UTF-8");
            SearchDepth = XHelper.GetChildValue(input, "SearchDepth", 8);
        }
Esempio n. 7
0
        public void Deserialize(XElement input, AXMLSerializationSettings opt)
        {
            if (input.Name.LocalName != "config")
            {
                throw new Exception("LocalName != 'config'");
            }

            Username = XHelper.GetChildValue(input, "Username", Username);
            Password = Decrypt(XHelper.GetChildValue(input, "Password", string.Empty), opt);
            PermanentlyDeleteNotes = XHelper.GetChildValue(input, "PermanentlyDeleteNotes", PermanentlyDeleteNotes);
            BlankLineBelowTitle    = XHelper.GetChildValue(input, "BlankLineBelowTitle", BlankLineBelowTitle);
        }
Esempio n. 8
0
        public void Deserialize(XElement input, AXMLSerializationSettings opt)
        {
            if (input.Name.LocalName != "config")
            {
                throw new Exception("LocalName != 'config'");
            }

            Email        = XHelper.GetChildValue(input, "Email", Email);
            Password     = Decrypt(XHelper.GetChildValue(input, "Password", string.Empty), opt);
            Server       = XHelper.GetChildValue(input, "Server", Server);
            RemEmptyTags = XHelper.GetChildValue(input, "RemEmptyTags", RemEmptyTags);
        }
Esempio n. 9
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Name", Name),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", HeadlessPlugin.Name);
            r.SetAttributeValue("pluginversion", HeadlessPlugin.Version.ToString());
            return(r);
        }
 public void Serialize(XElement target, AXMLSerializationSettings opt)
 {
     foreach (var d in _data)
     {
         var x = new XElement("Value");
         x.Add(new XAttribute("Key", d.Key));
         if ((opt & AXMLSerializationSettings.IncludeTypeInfo) != 0)
         {
             x.Add(new XAttribute("type", d.Value.GetTypeStr()));
         }
         x.Value = d.Value.Serialize(opt);
         target.Add(x);
     }
 }
Esempio n. 11
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Username", Email),
                new XElement("Password", Encrypt(Password, opt)),
                new XElement("UseSandbox", UseSandbox),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", EvernotePlugin.Name);
            r.SetAttributeValue("pluginversion", EvernotePlugin.Version.ToString());
            return(r);
        }
Esempio n. 12
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Username", Username),
                new XElement("Password", Encrypt(Password, opt)),
                new XElement("PermanentlyDeleteNotes", PermanentlyDeleteNotes),
                new XElement("BlankLineBelowTitle", BlankLineBelowTitle),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", SimpleNotePlugin.Name);
            r.SetAttributeValue("pluginversion", SimpleNotePlugin.Version.ToString());
            return(r);
        }
Esempio n. 13
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Username", Username),
                new XElement("Password", Encrypt(Password, opt)),
                new XElement("Host", Host),
                new XElement("BlankLineBelowTitle", BlankLineBelowTitle),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", NextcloudPlugin.Name);
            r.SetAttributeValue("pluginversion", NextcloudPlugin.Version.ToString());
            return(r);
        }
Esempio n. 14
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Email", Email),
                new XElement("Password", Encrypt(Password, opt)),
                new XElement("Server", Server),
                new XElement("RemEmptyTags", RemEmptyTags),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", StandardNotePlugin.Name);
            r.SetAttributeValue("pluginversion", StandardNotePlugin.Version.ToString());
            return(r);
        }
Esempio n. 15
0
        public XElement Serialize(AXMLSerializationSettings opt)
        {
            var data = new object[]
            {
                new XElement("Folder", Folder),
                new XElement("Extension", Extension),
                new XElement("Encoding", StrEncoding),
                new XElement("SearchDepth", SearchDepth),
            };

            var r = new XElement("config", data);

            r.SetAttributeValue("plugin", FilesystemPlugin.Name);
            r.SetAttributeValue("pluginversion", FilesystemPlugin.Version.ToString());
            return(r);
        }
Esempio n. 16
0
        public object DeserializeNew(string source, AXMLSerializationSettings opt)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                return(new ShortcutDefinition(AlephShortcutScope.None, AlephModifierKeys.None, AlephKey.None));
            }

            var kk = AlephKey.None;
            var mm = AlephModifierKeys.None;
            var ss = AlephShortcutScope.Window;

            source = source.Trim();
            foreach (var v in Enum.GetValues(typeof(AlephShortcutScope)).Cast <AlephShortcutScope>())
            {
                var estr = $"[{v.ToString().ToLower()}]";
                if (source.ToLower().EndsWith(estr))
                {
                    ss     = v;
                    source = source.Substring(0, source.Length - estr.Length).Trim();
                    break;
                }
            }

            foreach (var elem in source.Split('+'))
            {
                if (Enum.TryParse <AlephModifierKeys>(elem.Trim(), true, out var mk))
                {
                    mm = mm | mk;
                    continue;
                }

                if (Enum.TryParse <AlephKey>(elem.Trim(), true, out var pk))
                {
                    kk = pk;
                    continue;
                }

                throw new Exception($"Unknown KeyCode: '{elem}'");
            }

            if (kk == AlephKey.None)
            {
                throw new Exception($"Keycode 'None' is no supported");
            }

            return(new ShortcutDefinition(ss, mm, kk));
        }
Esempio n. 17
0
        public void Deserialize(T obj, string xml, AXMLSerializationSettings opt)
        {
            var xd   = XDocument.Parse(xml);
            var root = xd.Root;

            if (root == null)
            {
                throw new Exception("XDocument needs root");
            }

            foreach (var prop in _fields)
            {
                prop.Deserialize(obj, root, opt);
            }

            obj.OnAfterDeserialize();
        }
Esempio n. 18
0
        public void Serialize(XElement target, AXMLSerializationSettings opt)
        {
            foreach (var d in Data)
            {
                var x = new XElement("Value");
                x.Add(new XAttribute("Key", d.Key));
                if ((opt & AXMLSerializationSettings.IncludeTypeInfo) != 0)
                {
                    x.Add(new XAttribute("type", "GenericValue"));
                }

                var s = new XElement("GenericValue");
                d.Value.Serialize(s, opt);
                x.Add(s);

                target.Add(x);
            }
        }
Esempio n. 19
0
        public string Serialize(T obj, AXMLSerializationSettings opt)
        {
            obj.OnBeforeSerialize();

            var root = new XElement(_rootNode);

            foreach (var prop in _fields)
            {
                var data = prop.PropInfo.GetValue(obj);

                root.Add(prop.Serialize(data, opt));
            }

            if ((opt & AXMLSerializationSettings.FormattedOutput) != 0)
            {
                return(XHelper.ConvertToStringFormatted(new XDocument(root)));
            }
            else
            {
                return(XHelper.ConvertToStringRaw(new XDocument(root)));
            }
        }
Esempio n. 20
0
        public static string SimpleEncryptWithPassword(string secretMessage, string password, AXMLSerializationSettings opt)
        {
            if ((opt & AXMLSerializationSettings.UseEncryption) == 0)
            {
                return(secretMessage);
            }
            if (string.IsNullOrWhiteSpace(secretMessage))
            {
                return(string.Empty);
            }

            var encbytes = EncodeBytes(Encoding.UTF32.GetBytes(secretMessage), password);

            return(":02:" + Convert.ToBase64String(encbytes));
        }
Esempio n. 21
0
 public static string SimpleEncryptWithPassword(string secretMessage, string password, AXMLSerializationSettings opt)
 {
     if ((opt & AXMLSerializationSettings.UseEncryption) == 0)
     {
         return(secretMessage);
     }
     return(AESThenHMAC.SimpleEncryptWithPassword(secretMessage, password));
 }
Esempio n. 22
0
        public object DeserializeNew(XElement source, AXMLSerializationSettings opt)
        {
            var d = source.Elements("Value").Select(p => Tuple.Create(p.Attribute("Key").Value, p.Value)).ToArray();

            return(new KeyValueStringList(d));
        }
        public object DeserializeNew(XElement source, AXMLSerializationSettings opt)
        {
            var d = source.Elements("Value").Select(p => Tuple.Create(p.Attribute("Key").Value, (TValue)DefaultDictValue.DeserializeNew(p.Value, opt))).ToArray();

            return(new KeyValueFlatCustomList <TValue>(d, DefaultDictValue));
        }
Esempio n. 24
0
        public static string SimpleDecryptWithPassword(string encryptedMessageStr, string password, AXMLSerializationSettings opt)
        {
            if ((opt & AXMLSerializationSettings.UseEncryption) == 0)
            {
                return(encryptedMessageStr);
            }
            if (string.IsNullOrWhiteSpace(encryptedMessageStr))
            {
                return(string.Empty);
            }

            if (!encryptedMessageStr.StartsWith(":"))
            {
                // VERSION 1
                var encryptedMessage = Convert.FromBase64String(encryptedMessageStr);

                var cryptSalt = new byte[SaltBitSize / 8];
                var authSalt  = new byte[SaltBitSize / 8];

                //Grab Salt from Non-Secret Payload
                Array.Copy(encryptedMessage, 0, cryptSalt, 0, cryptSalt.Length);
                Array.Copy(encryptedMessage, 0 + cryptSalt.Length, authSalt, 0, authSalt.Length);

                byte[] cryptKey;
                byte[] authKey;

                //Generate crypt key
                using (var generator = new Rfc2898DeriveBytes(password, cryptSalt, Iterations_v1))
                {
                    cryptKey = generator.GetBytes(KeyBitSize / 8);
                }
                //Generate auth key
                using (var generator = new Rfc2898DeriveBytes(password, authSalt, Iterations_v1))
                {
                    authKey = generator.GetBytes(KeyBitSize / 8);
                }

                return(Encoding.UTF32.GetString(SimpleDecrypt(encryptedMessage, cryptKey, authKey, cryptSalt.Length + authSalt.Length + 0)));
            }
            else if (encryptedMessageStr.StartsWith(":02:"))
            {
                // VERSION 2
                encryptedMessageStr = encryptedMessageStr.Substring(4);

                var encbytes = Convert.FromBase64String(encryptedMessageStr);
                var rawbytes = DecodeBytes(encbytes, password);

                return(Encoding.UTF32.GetString(rawbytes));
            }
            else
            {
                throw new ArgumentException("Unknown encryption version: " + encryptedMessageStr, nameof(encryptedMessageStr));
            }
        }
Esempio n. 25
0
 public static string SimpleDecryptWithPassword(string encryptedMessageStr, string password, AXMLSerializationSettings opt)
 {
     if ((opt & AXMLSerializationSettings.UseEncryption) == 0)
     {
         return(encryptedMessageStr);
     }
     return(AESThenHMAC.SimpleDecryptWithPassword(encryptedMessageStr, password));
 }
Esempio n. 26
0
 public object DeserializeNew(XElement source, AXMLSerializationSettings opt)
 {
     return(new SnippetDefinition(source.Attribute("display").Value, source.Attribute("value").Value));
 }
Esempio n. 27
0
 private string Decrypt(string data, AXMLSerializationSettings opt)
 {
     return(ANEncryptionHelper.SimpleDecryptWithPassword(data, ENCRYPTION_KEY, opt));
 }
Esempio n. 28
0
 private string Encrypt(string data, AXMLSerializationSettings opt)
 {
     return(AESThenHMAC.SimpleEncryptWithPassword(data, ENCRYPTION_KEY, opt));
 }
Esempio n. 29
0
 public string Serialize(AXMLSerializationSettings opt)
 {
     return(Serialize());
 }
Esempio n. 30
0
 public void Serialize(XElement target, AXMLSerializationSettings opt)
 {
     target.Add(new XAttribute("display", DisplayName));
     target.Add(new XAttribute("value", Value));
 }