예제 #1
0
        public static ItemData GetItemInfo(string keyring, int id)
        {
            if (keyring == null)
            {
                throw new ArgumentNullException("keyring");
            }

            RequestMessage req = new RequestMessage();

            req.CreateSimpleOperation(Operation.GetItemInfo, keyring, id);
            ResponseMessage resp   = SendRequest(req.Stream);
            ItemType        itype  = (ItemType)resp.GetInt32();
            ItemData        item   = ItemData.GetInstanceFromItemType(itype);
            string          name   = resp.GetString();
            string          secret = resp.GetString();
            DateTime        mtime  = resp.GetDateTime();
            DateTime        ctime  = resp.GetDateTime();

            item.Keyring = keyring;
            item.ItemID  = id;
            item.Secret  = secret;
            Hashtable tbl = new Hashtable();

            tbl ["name"]          = name;
            tbl ["keyring_ctime"] = ctime;
            tbl ["keyring_mtime"] = mtime;
            item.Attributes       = tbl;
            item.SetValuesFromAttributes();
            return(item);
        }
예제 #2
0
        public static ItemData GetItemInfo(string keyring, int id)
        {
            if (keyring == null)
            {
                throw new ArgumentNullException("keyring");
            }

            IntPtr itemInfo;

            ResultCode result = gnome_keyring_item_get_info_sync(keyring, (uint)id, out itemInfo);

            if (result != ResultCode.Ok)
            {
                throw new KeyringException(result);
            }

            ItemData item = ItemData.GetInstanceFromItemType(gnome_keyring_item_info_get_type(itemInfo));

            item.Attributes = new Hashtable();
            item.Attributes["keyring_ctime"] = GLib.Marshaller.time_tToDateTime(gnome_keyring_item_info_get_ctime(itemInfo));
            item.Attributes["keyring_mtime"] = GLib.Marshaller.time_tToDateTime(gnome_keyring_item_info_get_mtime(itemInfo));
            item.Attributes["name"]          = Marshal.PtrToStringAnsi(gnome_keyring_item_info_get_display_name(itemInfo));

            item.Keyring = keyring;
            item.ItemID  = id;
            item.Secret  = Marshal.PtrToStringAnsi(gnome_keyring_item_info_get_secret(itemInfo));

            item.SetValuesFromAttributes();

            gnome_keyring_item_info_free(itemInfo);

            return(item);
        }
예제 #3
0
        public static ItemData[] Find(ItemType type, Hashtable atts)
        {
            if (atts == null)
            {
                throw new ArgumentNullException("atts");
            }

            IntPtr passwordList;
            IntPtr attrList = gks_attribute_list_new();

            NativeListFromAttributes(attrList, atts);

            ResultCode result = gnome_keyring_find_items_sync(type, attrList, out passwordList);

            if (result == ResultCode.Denied || result == ResultCode.NoMatch)
            {
                return(empty_item_data);
            }

            if (result != ResultCode.Ok)
            {
                throw new KeyringException(result);
            }

            IntPtr[] passwordStructs           = (IntPtr[])GLib.Marshaller.ListPtrToArray(passwordList, typeof(GLib.List), false, false, typeof(IntPtr));
            List <GnomeKeyringFound> passwords = new List <GnomeKeyringFound> ();

            foreach (IntPtr ptr in passwordStructs)
            {
                passwords.Add((GnomeKeyringFound)Marshal.PtrToStructure(ptr, typeof(GnomeKeyringFound)));
            }

            ArrayList list = new ArrayList();

            foreach (var password in passwords)
            {
                ItemData found = ItemData.GetInstanceFromItemType(type);
                found.ItemID     = (int)password.item_id;
                found.Secret     = Marshal.PtrToStringAnsi(password.secret);
                found.Keyring    = Marshal.PtrToStringAnsi(password.keyring);
                found.Attributes = new Hashtable();
                AttributesFromNativeList(password.attrList, found.Attributes);
                found.SetValuesFromAttributes();
                list.Add(found);
            }

            gnome_keyring_found_list_free(passwordList);
            gnome_keyring_attribute_list_free(attrList);

            return((ItemData [])list.ToArray(typeof(ItemData)));
        }
예제 #4
0
        public static ItemData [] Find(ItemType type, Hashtable atts)
        {
            if (atts == null)
            {
                throw new ArgumentNullException("atts");
            }
            RequestMessage req = new RequestMessage();

            req.StartOperation(Operation.Find);
            req.Write((int)type);
            req.WriteAttributes(atts);
            req.EndOperation();

            ResponseMessage resp = null;

            try {
                resp = SendRequest(req.Stream);
            } catch (KeyringException ke) {
                if (ke.ResultCode == ResultCode.Denied ||
                    ke.ResultCode == ResultCode.NoMatch)
                {
                    return(empty_item_data);
                }
                throw;
            }

            ArrayList list = new ArrayList();

            while (resp.DataAvailable)
            {
                ItemData found = ItemData.GetInstanceFromItemType(type);
                found.Keyring    = resp.GetString();
                found.ItemID     = resp.GetInt32();
                found.Secret     = resp.GetString();
                found.Attributes = new Hashtable();
                resp.ReadAttributes(found.Attributes);
                found.SetValuesFromAttributes();
                list.Add(found);
            }

            return((ItemData [])list.ToArray(typeof(ItemData)));
        }