First pass at supporting trust anchors in IdCard dialog
[moonshot-ui.git] / src / moonshot-id.vala
index ec0866c..0895d1e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2014, JANET(UK)
+ * Copyright (c) 2011-2016, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,61 @@ using Gee;
 
 public class TrustAnchor : Object
 {
-    public string ca_cert {get; set; default = "";}
-    public string subject {get; set; default = "";}
-    public string subject_alt  {get; set; default = "";}
-    public string server_cert  {get; set; default = "";}
+    public enum TrustAnchorType {
+        CA_CERT,
+        SERVER_CERT
+    }
+    private string _ca_cert = "";
+    private string _subject = "";
+    private string _subject_alt = "";
+    private string _server_cert = "";
+
+    public string ca_cert {
+        get {
+            return _ca_cert;
+        }
+        set {
+            _ca_cert = (value ?? "");
+        }
+    }
+
+    public string subject {
+        get {
+            return _subject;
+        }
+        set {
+            _subject = (value ?? "");
+        }
+    }
+
+    public string subject_alt  {
+        get {
+            return _subject_alt;
+        }
+        set {
+            _subject_alt = (value ?? "");
+        }
+    }
+
+
+    public string server_cert {
+        get {
+            return _server_cert;
+        }
+        set {
+            _server_cert = (value ?? "");
+        }
+    }
+
+    public bool is_empty() {
+        return ca_cert == "" && subject == "" && subject_alt == "" && server_cert == "";
+    }
+
+    public TrustAnchorType get_anchor_type() {
+        return server_cert == "" ? TrustAnchorType.CA_CERT : TrustAnchorType.SERVER_CERT;
+    }
+
     public int Compare(TrustAnchor other)
     {
         if (this.ca_cert != other.ca_cert)
@@ -50,6 +101,16 @@ public class TrustAnchor : Object
             return 1;
         return 0;
     }
+
+    public string? get_expiration_date()
+    {
+        if (this.ca_cert == "") {
+            return null;
+        }
+
+        //!!TODO read expiration date
+        return "";
+    }
 }
 
 public struct Rule