3198353cdb1882fe83be905f9c1d4a7ee35cc2cb
[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
48   public TrustAnchor trust_anchor  { get; set; default = new TrustAnchor (); }
49   
50   public unowned string nai { get {  _nai = username + "@" + issuer; return _nai;}}
51
52   public bool store_password { get; set; default = false; }
53
54   public bool IsNoIdentity() 
55   {
56     return (display_name == NO_IDENTITY);
57   }
58
59   public static IdCard NewNoIdentity() 
60   { 
61     IdCard card = new IdCard();
62     card.display_name = NO_IDENTITY;
63     return card;
64   }
65
66   ~IdCard() {
67     password = null;
68   }
69 }