Esempio n. 1
0
        public void TestKeyFileCreation()
        {
            var keyFile = new KeyFile("C:/Persistence", "Test");

            var objectIdA = new ObjectId();
            var objectIdB = new ObjectId();
            var objectIdC = new ObjectId();

            keyFile.Update(objectIdA, 100, 1000);
            keyFile.Update(objectIdB, 200, 2000);
            keyFile.Update(objectIdC, 300, 3000);

            int offset        = 0;
            int dataSizeBytes = 0;

            Assert.IsTrue(keyFile.Get(objectIdA, ref offset, ref dataSizeBytes));
            Assert.IsTrue(offset == 100);
            Assert.IsTrue(dataSizeBytes == 1000);

            Assert.IsTrue(keyFile.Get(objectIdB, ref offset, ref dataSizeBytes));
            Assert.IsTrue(offset == 200);
            Assert.IsTrue(dataSizeBytes == 2000);

            Assert.IsTrue(keyFile.Get(objectIdC, ref offset, ref dataSizeBytes));
            Assert.IsTrue(offset == 300);
            Assert.IsTrue(dataSizeBytes == 3000);

            keyFile.Save();
        }
Esempio n. 2
0
        public void KeyLocationExistsTest()
        {
            var target = new KeyFile();

            Assert.IsTrue(target.KeyLocationExists("Readme.txt"));
            Assert.IsFalse(target.KeyLocationExists("DontReadme.txt"));
        }
Esempio n. 3
0
        private void BMSChanged()
        {
            try
            {
                statusAssign = Status.GetNeutralPos;

                LargeTab.SelectedIndex = 0;

                // Read Theater List
                TheaterList.PopulateAndSave(appReg, Dropdown_TheaterList);

                // Read BMS-FULL.key
                string fname     = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName();
                string fnameauto = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getAutoKeyFileName();
                if (!File.Exists(fnameauto))
                {
                    File.Copy(fname, fnameauto);
                }
                keyFile = new KeyFile(fnameauto, appReg);

                // Write Data Grid
                WriteDataGrid();
            }
            catch (Exception ex)
            {
                Diagnostics.WriteLogFile(ex);
                Close();
            }
        }
Esempio n. 4
0
        private void LoadKeyFile(string keyFileName)
        {
            if (string.IsNullOrEmpty(keyFileName))
            {
                throw new ArgumentNullException("keyFileName");
            }
            var file = new FileInfo(keyFileName);

            if (!file.Exists)
            {
                throw new FileNotFoundException(keyFileName);
            }

            var oldViewerState = (ViewerState)_viewerState.Clone();

            try
            {
                _viewerState.Filename = keyFileName;
                _viewerState.KeyFile  = KeyFile.Load(keyFileName);
                ParseKeyFile();
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("An error occurred while loading the file.\n\n {0}", e.Message),
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                _viewerState = oldViewerState;
            }
        }
Esempio n. 5
0
        public static KeyFile GetCurrentKeyFile()
        {
            KeyFile toReturn          = null;
            string  falconKeyFilePath = null;

            using (var reader = new F4SharedMem.Reader())
            {
                falconKeyFilePath = reader.GetCurrentData()?.StringData?.data?.Where(x => x.strId == (uint)F4SharedMem.Headers.StringIdentifier.KeyFile).First().value;
            }
            if (string.IsNullOrEmpty(falconKeyFilePath))
            {
                return(null);
            }
            var keyFileInfo = new FileInfo(falconKeyFilePath);

            if (!keyFileInfo.Exists)
            {
                return(null);
            }
            try
            {
                toReturn = KeyFile.Load(falconKeyFilePath);
            }
            catch (IOException e)
            {
                Log.Error(e.Message, e);
            }
            return(toReturn);
        }
Esempio n. 6
0
        protected FlickrManager LoadToken()
        {
            var         mgr = new FlickrManager();
            AccessToken token;

            try
            {
                using (var stream = KeyFile.OpenRead())
                {
                    token = stream.Load <AccessToken>();
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Error loading token '{KeyFile.FullName}'. {ex.Message}");
            }
            try
            {
                mgr.ApplyToken(token);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Supplied token is invalid. {ex.Message}");
            }
            return(mgr);
        }
        /// <summary>
        /// Creates and saves stored keyfile in appdata based on current filename.
        /// </summary>
        /// <returns>New keyfile saved to disk.</returns>
        public static async Task <KeyFile> CreateStoredKeyFile(string saveLocation)
        {
            KeyFile key = new KeyFile(true);
            await FileManager.SaveFileAsync(saveLocation, FileManager.Serialize(key), true);

            return(key);
        }
Esempio n. 8
0
 private void LoadCurrentKeyFile()
 {
     if (!Settings.Default.RunAsClient)
     {
         _keyFile = KeyFileUtils.GetCurrentKeyFile();
     }
 }
Esempio n. 9
0
        void OkButtonClick(object sender, EventArgs e)
        {
            KeyFile = KeyFile.Trim();
            if (KeyFile.Length == 0)
            {
                MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.EnterKeyName}");
                return;
            }
            bool usePassword = Get <CheckBox>("usePassword").Checked;

            if (usePassword)
            {
                if (!CheckPassword(ControlDictionary["passwordTextBox"],
                                   ControlDictionary["confirmPasswordTextBox"]))
                {
                    return;
                }
                MessageService.ShowMessage("Creating a key file with a password is currently not supported.");
                return;
            }
            if (!KeyFile.EndsWith(".snk") && !KeyFile.EndsWith(".pfx"))
            {
                KeyFile += ".snk";
            }
            if (CreateKey(Path.Combine(baseDirectory, KeyFile)))
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
        private static void CreateKeyFile(string path, out string encrKey, out string signKey)
        {
            KeyProtection.CreateKeys(out encrKey, out signKey);

            var keys = new KeyFile { encryptKey = encrKey, signKey = signKey };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(keys);
            File.WriteAllText(path, json);
        }
Esempio n. 11
0
        public void PutKeyBlankLocationAsyncTest()
        {
            TestUtilities.AsyncTestWrapper(TestContext, () =>
            {
                var target = new KeyFile();

                target.PutKeyAsync(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, " \t").Wait();
            });
        }
Esempio n. 12
0
        public void GetKeyBlankLocationAsyncTest()
        {
            TestUtilities.AsyncTestWrapper(TestContext, () =>
            {
                var target = new KeyFile();

                target.GetKeyAsync(" \t").Wait();
            });
        }
Esempio n. 13
0
        private void OnFileDownloaded(MetaListItemInfo item,
                                      string path, byte[] bytes)
        {
            var dispatcher = Dispatcher;

            try
            {
                using (var buffer = new MemoryStream(bytes))
                {
                    if (string.IsNullOrEmpty(_folder))
                    {
                        if (!DatabaseVerifier.Verify(dispatcher, buffer))
                        {
                            return;
                        }

                        var name = item.Title.RemoveKdbx();

                        var storage = new DatabaseInfo();
                        storage.SetDatabase(buffer, new DatabaseDetails
                        {
                            Url      = path,
                            Name     = name,
                            Modified = item.Modified,
                            Type     = SourceTypes.Synchronizable,
                            Source   = DatabaseUpdater.ONEDRIVE_UPDATER,
                        });
                        dispatcher.BeginInvoke(
                            this.BackToDBs);
                    }
                    else
                    {
                        var hash = KeyFile.GetKey(buffer);
                        if (hash == null)
                        {
                            dispatcher.BeginInvoke(() => MessageBox.Show(
                                                       Properties.Resources.InvalidKeyFile,
                                                       Properties.Resources.KeyFileTitle,
                                                       MessageBoxButton.OK));
                            return;
                        }

                        new DatabaseInfo(_folder)
                        .SetKeyFile(hash);

                        dispatcher.BeginInvoke(
                            this.BackToDBPassword);
                    }
                }
            }
            finally
            {
                dispatcher.BeginInvoke(() =>
                                       progBusy.IsBusy = false);
            }
        }
Esempio n. 14
0
        private void GenerateKeyAndSend(String Name, String Organisation, String EmailAddress, bool SendMail)
        {
            //Opbouwen compleet bericht
            String MessageToEncrypt = "<xml><applicatie name=\"Copying Machine\" version=\"2.00\"/>";

            MessageToEncrypt += "<user name=\"";
            MessageToEncrypt += Name;
            MessageToEncrypt += "\" organisation=\"";
            MessageToEncrypt += Organisation;
            MessageToEncrypt += "\" id=\"";
            MessageToEncrypt += System.DateTime.Now.ToShortDateString() + System.DateTime.Now.ToShortTimeString();
            MessageToEncrypt += "\" emailaddress=\"";
            MessageToEncrypt += EmailAddress;
            MessageToEncrypt += "\"/></xml>";

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            Byte[] bytes         = encoding.GetBytes(MessageToEncrypt);
            byte[] dataToEncrypt = new byte[1 + bytes.Length];

            //Add the checksum to the xml
            int iChecksum = 0;

            for (int i = 0; i < MessageToEncrypt.Length; i++)
            {
                iChecksum            = iChecksum + bytes[i];
                dataToEncrypt[i + 1] = bytes[i];
            }

            iChecksum = (iChecksum & 0x07);
            iChecksum = (iChecksum << 5) & 0xFF;
            iChecksum = iChecksum | 0x20;

            dataToEncrypt[0] = Convert.ToByte(iChecksum);

            //Construct the name of the keyfile to be generated
            String KeyFile;

            KeyFile  = "Keys\\copymach_";
            KeyFile += Name.ToLower();
            KeyFile += ".cmk";
            KeyFile  = KeyFile.Replace(" ", "");

            if (!Directory.Exists("Keys"))
            {
                Directory.CreateDirectory("Keys");
            }

            //Create the key
            Key(KeyFile, dataToEncrypt, dataToEncrypt.Length);

            //Send e-mail
            if (SendMail)
            {
                MailKey(KeyFile, EmailAddress);
            }
        }
Esempio n. 15
0
        public void DeleteKeyLocationNonExistentTest()
        {
            var target = new KeyFile();

            Assert.IsFalse(File.Exists("foo.key"));

            target.DeleteKeyLocation("foo.key");

            Assert.IsFalse(File.Exists("foo.key"));
        }
Esempio n. 16
0
        public void PutKeyNullKeyAsyncTest()
        {
            TestUtilities.AsyncTestWrapper(TestContext, () =>
            {
                var target = new KeyFile();

                target.PutKeyAsync(null, "foo.key").Wait();
                Assert.IsFalse(File.Exists("foo.key"));
            });
        }
        private static void CreateKeyFile(string path, out string encrKey, out string signKey)
        {
            KeyProtection.CreateKeys(out encrKey, out signKey);

            var keys = new KeyFile {
                encryptKey = encrKey, signKey = signKey
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(keys);

            File.WriteAllText(path, json);
        }
Esempio n. 18
0
 private static IntPtr KeyFileClone(ref KeyFile keyFile)
 {
     if (Environment.Is64BitProcess)
     {
         return(KeyFileClone_64(ref keyFile));
     }
     else
     {
         return(KeyFileClone_32(ref keyFile));
     }
 }
Esempio n. 19
0
        private void OnFileDownloaded(byte[] file,
                                      string path, string title, string modified)
        {
            var dispatcher = Dispatcher;

            try
            {
                using (var buffer = new MemoryStream(file))
                {
                    if (string.IsNullOrEmpty(_folder))
                    {
                        if (!DatabaseVerifier.Verify(dispatcher, buffer))
                        {
                            return;
                        }

                        var storage = new DatabaseInfo();
                        storage.SetDatabase(buffer, new DatabaseDetails
                        {
                            Modified = modified,
                            Name     = title.RemoveKdbx(),
                            Url      = _client.GetUrl(path),
                            Type     = SourceTypes.Synchronizable,
                            Source   = DatabaseUpdater.WEBDAV_UPDATER,
                        });
                    }
                    else
                    {
                        var hash = KeyFile.GetKey(buffer);
                        if (hash == null)
                        {
                            dispatcher.BeginInvoke(() => MessageBox.Show(
                                                       Properties.Resources.InvalidKeyFile,
                                                       Properties.Resources.KeyFileTitle,
                                                       MessageBoxButton.OK));

                            return;
                        }

                        new DatabaseInfo(_folder)
                        .SetKeyFile(hash);
                    }
                }

                dispatcher.BeginInvoke(
                    this.BackToDBs);
            }
            finally
            {
                dispatcher.BeginInvoke(() =>
                                       progBusy.IsBusy = false);
            }
        }
Esempio n. 20
0
 public static KeyBinding FindKeyBinding(string callback)
 {
     if (_keyFile == null)
     {
         _keyFile = GetCurrentKeyFile();
     }
     if (_keyFile == null)
     {
         return(null);
     }
     return(_keyFile.GetBindingForCallback(callback) as KeyBinding);
 }
Esempio n. 21
0
        public void PutKeyTest()
        {
            File.Delete("foo.key");

            var target = new KeyFile();

            target.PutKey(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key");

            Assert.IsTrue(File.Exists("foo.key"));

            File.Delete("foo.key");
        }
        /// <summary>
        /// Load a stored keyfile from disk at given location.
        /// </summary>
        /// <param name="saveLocation">File location on disk.</param>
        /// <returns>Keyfile from disk, or if not found, null.</returns>
        public static async Task <KeyFile> LoadStoredKeyFile(string saveLocation)
        {
            byte[] data = await FileManager.OpenFile(saveLocation);

            KeyFile key = null;

            if (data != null)
            {
                key = FileManager.Deserialize <KeyFile>(data);
            }

            return(key);
        }
Esempio n. 23
0
        public void TestKeyLookup()
        {
            var keyFile = new KeyFile("C:/Persistence", "Test");

            var objectId           = new ObjectId();
            var deepCopiedObjectId = new ObjectId(objectId.AsInt());

            keyFile.Update(objectId, 100, 1000);

            int offset        = 0;
            int dataSizeBytes = 0;

            Assert.IsTrue(keyFile.Get(objectId, ref offset, ref dataSizeBytes), "Original");
            Assert.IsTrue(keyFile.Get(deepCopiedObjectId, ref offset, ref dataSizeBytes), "Deep copy");
        }
Esempio n. 24
0
        public KeyMappingWindow(MainWindow mainWindow, KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl)
        {
            InitializeComponent();

            this.mainWindow = mainWindow;

            CallbackName.Content = SelectedCallback.GetKeyDescription();

            Select_PinkyShift.IsChecked = true;
            Select_DX_Release.IsChecked = true;

            this.SelectedCallback = SelectedCallback;
            this.keyFile          = keyFile;

            Reset();
        }
Esempio n. 25
0
        public void GetKeyTest()
        {
            File.Delete("foo.key");

            var target = new KeyFile();

            target.PutKey(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key");

            Assert.IsTrue(File.Exists("foo.key"));

            var key = target.GetKey("foo.key");

            Assert.IsNotNull(key);
            Assert.IsTrue(key.SequenceEqual(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));

            File.Delete("foo.key");
        }
Esempio n. 26
0
            public GMpiFileInfo(string mediaPlayerId)
            {
                try {
                    mpi_file = new KeyFile();
                    mpi_file.SetListSeparator(Separator);
                    string full_path;
                    mpi_file.LoadFromDirs(String.Format("{0}.mpi", mediaPlayerId),
                                          new string [] { "/usr/share/media-player-info",
                                                          "/usr/local/share/media-player-info" },
                                          out full_path, KeyFileFlags.None);
                } catch (GLib.GException) {
                    Hyena.Log.WarningFormat("Failed to load media-player-info file for {0}",
                                            mediaPlayerId);
                }

                LoadProperties();
            }
Esempio n. 27
0
        public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
        {
            InitialLocalValues();
            if (args.Files != null &&
                args.Files.Count > 0)
            {
                var         action = (args.ContinuationData["Action"] as string);
                StorageFile file;
                switch (action)
                {
                case KdbxFormat:
                {
                    file = args.Files[0];

                    if (file.Name.EndsWith(KdbxFormat, StringComparison.OrdinalIgnoreCase))
                    {
                        var info = new DatabaseInfo();
                        var test = await file.OpenReadAsync();

                        info.SetDatabase(test.AsStream(), new DatabaseDetails
                            {
                                Source = "FileSystem",
                                Name   = file.Name.RemoveKdbx(),
                                Type   = SourceTypes.OneTime,
                            });
                        this.NavigateTo <MainPage>();
                    }
                }
                break;

                case KeyFormat:
                    file = args.Files[0];

                    if (file.Name.EndsWith(KeyFormat, StringComparison.OrdinalIgnoreCase))
                    {
                        var test = await file.OpenReadAsync();

                        (new DatabaseInfo(_folder)).SetKeyFile(KeyFile.GetKey(test.AsStream()));
                        NavigationService.GoBack();
                        //  this.NavigateTo<MainPage>();
                    }
                    break;
                }
            }
        }
Esempio n. 28
0
        public KeyMappingWindow(KeyAssgn SelectedCallback, KeyFile keyFile, DeviceControl deviceControl)
        {
            InitializeComponent();
            CallbackName.Content        = SelectedCallback.GetKeyDescription();
            Select_PinkyShift.IsChecked = true;
            Select_DX_Release.IsChecked = true;
            this.SelectedCallback       = SelectedCallback;
            this.keyFile       = keyFile;
            this.deviceControl = deviceControl;
            neutralButtons     = new NeutralButtons[deviceControl.devList.Count];

            tmpJoyStick = new JoyAssgn[deviceControl.devList.Count];
            for (int i = 0; i < deviceControl.devList.Count; i++)
            {
                tmpJoyStick[i] = deviceControl.joyAssign[i].Clone();
            }
            tmpCallback = this.SelectedCallback.Clone();
        }
Esempio n. 29
0
        /// <summary>
        /// Execute setting override.
        /// </summary>
        /// <param name="inGameAxis"></param>
        /// <param name="deviceControl"></param>
        /// <param name="keyFile"></param>
        /// <param name="visualAcuity"></param>
        public void Execute(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile)
        {
            if (!Directory.Exists(appReg.GetInstallDir() + "/User/Config/Backup/"))
            {
                Directory.CreateDirectory(appReg.GetInstallDir() + "/User/Config/Backup/");
            }

            MainWindow.deviceControl.SortDevice();

            SaveAxisMapping(inGameAxis, deviceControl);
            SaveJoystickCal(inGameAxis, deviceControl);
            SaveDeviceSorting(deviceControl);
            SaveConfigfile(inGameAxis, deviceControl);
            SaveKeyMapping(inGameAxis, deviceControl, keyFile);
            //SavePlcLbk();
            SavePop();
            SaveWindowConfig();
            SaveJoyAssignStatus(deviceControl);
        }
Esempio n. 30
0
        public bool InitTest()
        {
            string path = "C:\\Users\\dewints\\Downloads\\fdm.key";

            if (!KeyFile.TryLoadFromFile(path, "DEMO" /* TODO use your own passphase */, out k))
            {
                Debug.WriteLine("Unable to load the key file \"" + path + "\".");
                return(false);
            }

            c = FDMClient.CreateClient(k, Languages.English);
            if (c == null)
            {
                Debug.WriteLine("Unable to create the FDM client.");
                return(false);
            }

            return(true);
        }
Esempio n. 31
0
        public void GetKeyAsyncTest()
        {
            TestUtilities.AsyncTestWrapper(TestContext, () =>
            {
                File.Delete("foo.key");

                var target = new KeyFile();

                target.PutKeyAsync(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "foo.key").Wait();

                Assert.IsTrue(File.Exists("foo.key"));

                var key = target.GetKeyAsync("foo.key").Result;

                Assert.IsNotNull(key);
                Assert.IsTrue(key.SequenceEqual(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));

                File.Delete("foo.key");
            });
        }
Esempio n. 32
0
		public unsafe bool LoadFromDirs(string file, string search_dirs, string full_path, KeyFile.Flags flags) {
			IntPtr native_file = GLib.Marshaller.StringToPtrGStrdup (file);
			IntPtr native_search_dirs = GLib.Marshaller.StringToPtrGStrdup (search_dirs);
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_key_file_load_from_dirs(Handle, native_file, native_search_dirs, GLib.Marshaller.StringToPtrGStrdup(full_path), (int) flags, out error);
			bool ret = raw_ret;
			GLib.Marshaller.Free (native_file);
			GLib.Marshaller.Free (native_search_dirs);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}
Esempio n. 33
0
/*
 * GKeyFile.custom
 *
 * Author(s):
 *	Stephane Delcroix  ([email protected])
 *
 * Copyright (c) 2008 Novell, Inc.
 *
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

	public GKeyFile (string file, KeyFile.Flags flags) : this ()
	{
		LoadFromFile (file, flags);
	}
Esempio n. 34
0
 /// <summary>
 /// Use this to load a key file
 /// </summary>
 /// <param name="path">Path to key file</param>
 public bool LoadKey(string path)
 {
     //does file exist
     if(!File.Exists(path))
     {
         return false;
     }
     //maby the json in the file is broekn?
     try
     {
         _kf = JsonConvert.DeserializeObject<KeyFile>(File.ReadAllText(path));
     }
     catch { return false; }
     //well every thing worked out.
     return true;
 }
Esempio n. 35
0
 private static IntPtr KeyFileClone(ref KeyFile keyFile)
 {
     if (Environment.Is64BitProcess)
     {
         return KeyFileClone_64(ref keyFile);
     }
     else
     {
         return KeyFileClone_32(ref keyFile);
     }
 }
Esempio n. 36
0
 private static extern IntPtr KeyFileClone_64(ref KeyFile keyFile);
Esempio n. 37
0
		public unsafe bool LoadFromFile(string file, KeyFile.Flags flags) {
			IntPtr native_file = GLib.Marshaller.StringToPtrGStrdup (file);
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_key_file_load_from_file(Handle, native_file, (int) flags, out error);
			bool ret = raw_ret;
			GLib.Marshaller.Free (native_file);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}
Esempio n. 38
0
		public unsafe bool LoadFromData(string data, KeyFile.Flags flags) {
			IntPtr native_data = GLib.Marshaller.StringToPtrGStrdup (data);
			IntPtr error = IntPtr.Zero;
			bool raw_ret = g_key_file_load_from_data(Handle, native_data, new UIntPtr ((ulong) System.Text.Encoding.UTF8.GetByteCount (data)), (int) flags, out error);
			bool ret = raw_ret;
			GLib.Marshaller.Free (native_data);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}
Esempio n. 39
0
        public static bool KeyFilesApply(ref Password password, IEnumerable<string> keyfiles)
        {
            // prepare a list in native memory with all keyfiles
            KeyFile keyfileStruct = new KeyFile();
            IntPtr firstKeyfilePtr = IntPtr.Zero;
            foreach (string keyfile in keyfiles)
            {
                keyfileStruct.FileName = keyfile;
                IntPtr keyfilePtr = KeyFileClone(ref keyfileStruct);
                firstKeyfilePtr = KeyFileAdd(firstKeyfilePtr, keyfilePtr);
            }

            // apply the keyfiles to the password
            bool retval = KeyFilesApply(ref password, firstKeyfilePtr);

            // free the memory used by the keyfiles
            KeyFileRemoveAll(ref firstKeyfilePtr);

            return retval;
        }
Esempio n. 40
0
 public void SaveKey(string path, KeyFile f)
 {
     //save the file
     File.WriteAllText(path, JsonConvert.SerializeObject(f));
 }