~and471/+junk/do-with-docky

« back to all changes in this revision

Viewing changes to Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GnomeKeyringSecurePreferencesService.cs

  • Committer: rugby471 at gmail
  • Date: 2010-10-15 16:08:38 UTC
  • Revision ID: rugby471@gmail.com-20101015160838-z9m3utbf7bxzb5ty
reverted to before docky removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
using System;
22
22
using System.Collections;
23
 
using System.Threading;
24
23
using System.ComponentModel;
25
24
 
26
25
using Mono.Unix;
62
61
                public bool Set (string key, string val)
63
62
                {
64
63
                        Hashtable keyData;
65
 
 
 
64
                        
66
65
                        if (!Ring.Available) {
67
66
                                Log.Error (KeyringUnavailableMessage);
68
67
                                return false;
69
68
                        }
70
69
 
71
70
                        keyData = new Hashtable ();
72
 
                        keyData[AbsolutePathForKey (key)] = key;
73
 
 
74
 
                        bool success = false;
75
 
                        AutoResetEvent completed = new AutoResetEvent (false);
76
 
 
77
 
                        Services.Application.RunOnMainThread (delegate {
78
 
                                try {
79
 
                                        Ring.CreateItem (Ring.GetDefaultKeyring (), ItemType.GenericSecret, AbsolutePathForKey (key), keyData, val.ToString (), true);
80
 
                                        success = true;
81
 
                                } catch (KeyringException e) {
82
 
                                        Log.Error (ErrorSavingMessage, key, e.Message);
83
 
                                        Log.Debug (e.StackTrace);
84
 
                                        success = false;
85
 
                                }
86
 
                                completed.Set ();
87
 
                        });
88
 
                        if (!completed.WaitOne (200)) {
 
71
                        keyData [AbsolutePathForKey (key)] = key;
 
72
                        
 
73
                        try {
 
74
                                Ring.CreateItem (Ring.GetDefaultKeyring (), ItemType.GenericSecret, AbsolutePathForKey (key), keyData, val.ToString (), true);
 
75
                        } catch (KeyringException e) {
 
76
                                Log.Error (ErrorSavingMessage, key, e.Message);
 
77
                                Log.Debug (e.StackTrace);
89
78
                                return false;
90
79
                        }
91
 
                        return success;
 
80
 
 
81
                        return true;
92
82
                }
93
83
 
94
84
                public bool TryGet (string key, out string val)
95
85
                {
96
86
                        Hashtable keyData;
97
 
 
98
 
                        string secret = "";
99
 
 
 
87
                        
 
88
                        val = "";
 
89
                        
100
90
                        if (!Ring.Available) {
101
91
                                Log.Error (KeyringUnavailableMessage);
102
 
                                val = "";
103
92
                                return false;
104
93
                        }
105
94
 
106
95
                        keyData = new Hashtable ();
107
 
                        keyData[AbsolutePathForKey (key)] = key;
 
96
                        keyData [AbsolutePathForKey (key)] = key;
108
97
                        
109
 
                        bool success = false;
110
 
                        AutoResetEvent completed = new AutoResetEvent (false);
111
 
 
112
 
                        Services.Application.RunOnMainThread (delegate {
113
 
                                try {
114
 
                                        foreach (ItemData item in Ring.Find (ItemType.GenericSecret, keyData)) {
115
 
                                                if (!item.Attributes.ContainsKey (AbsolutePathForKey (key)))
116
 
                                                        continue;
117
 
 
118
 
                                                secret = item.Secret;
119
 
                                                success = true;
120
 
                                                break;
121
 
                                        }
122
 
                                } catch (KeyringException) {
123
 
                                        Log.Debug (KeyNotFoundMessage, AbsolutePathForKey (key));
124
 
                                        success = false;
125
 
                                } finally {
126
 
                                        completed.Set ();
 
98
                        try {
 
99
                                foreach (ItemData item in Ring.Find (ItemType.GenericSecret, keyData)) {
 
100
                                        if (!item.Attributes.ContainsKey (AbsolutePathForKey (key))) continue;
 
101
 
 
102
                                        val = item.Secret;
 
103
                                        return true;
127
104
                                }
128
 
                        });
129
 
                        if (!completed.WaitOne (200)) {
130
 
                                success = false;
 
105
                        } catch (KeyringException) {
 
106
                                Log.Debug (KeyNotFoundMessage, AbsolutePathForKey (key));
131
107
                        }
132
 
                        val = secret;
133
 
                        return success;
 
108
 
 
109
                        return false;
134
110
                }
135
111
                
136
112
                #endregion