Modify identity selection logic / fix bugs
[moonshot-ui.git] / src / moonshot-id.vala
1 public class TrustAnchor : Object
2 {
3   public string ca_cert {get; set; default = "";}
4   public string subject {get; set; default = "";}
5   public string subject_alt  {get; set; default = "";}
6   public string server_cert  {get; set; default = "";}
7 }
8
9 public struct Rule
10 {
11   public string pattern;
12   public string always_confirm;
13 }
14
15 public class IdCard : Object
16 {
17   public const string NO_IDENTITY = "No Identity";
18
19   private string _nai;
20   
21   public string display_name { get; set; default = ""; }
22   
23   public string username { get; set; default = ""; }
24 #if GNOME_KEYRING
25   private unowned string _password;
26   public string password {
27     get {
28       return (_password!=null) ? _password : "";
29     }
30     set {
31       if (_password != null) {
32         GnomeKeyring.memory_free((void *)_password);
33         _password = null;
34       }
35       if (value != null)
36         _password = GnomeKeyring.memory_strdup(value); 
37     }
38   }
39 #else
40   public string password { get; set; default = null; }
41 #endif
42
43   public string issuer { get; set; default = ""; }
44   
45   public Rule[] rules {get; set; default = {};}
46   public string[] services { get; set; default = {}; }
47   public bool temporary {get; set; default = false; }
48
49   public TrustAnchor trust_anchor  { get; set; default = new TrustAnchor (); }
50   
51   public unowned string nai { get {  _nai = username + "@" + issuer; return _nai;}}
52
53   public bool store_password { get; set; default = false; }
54
55   public bool IsNoIdentity() 
56   {
57     return (display_name == NO_IDENTITY);
58   }
59
60   public static IdCard NewNoIdentity() 
61   { 
62     IdCard card = new IdCard();
63     card.display_name = NO_IDENTITY;
64     return card;
65   }
66
67   ~IdCard() {
68     password = null;
69   }
70 }