+ private static const string CERT_HEADER = "-----BEGIN CERTIFICATE-----";
+ private static const string CERT_FOOTER = "-----END CERTIFICATE-----";
+
+ public enum TrustAnchorType {
+ CA_CERT,
+ SERVER_CERT
+ }
+
+ private string _ca_cert = "";
+ private string _subject = "";
+ private string _subject_alt = "";
+ private string _server_cert = "";
+ private string _datetime_added = "";
+ public bool user_verified = false;
+
+ private static string fixup (string s) {
+ return (s == null ? "" : s.strip());
+ }
+
+ public TrustAnchor(string ca_cert, string server_cert, string subject, string subject_alt, bool user_verified) {
+ _ca_cert = fixup(ca_cert);
+ _server_cert = fixup(server_cert);
+ _subject = fixup(subject);
+ _subject_alt = fixup(subject_alt);
+ this.user_verified = user_verified;
+
+ // If we're reading from store, this will be overridden (see set_datetime_added)
+ _datetime_added = "";
+ }
+
+ public TrustAnchor.empty() {
+ }
+
+
+ public string ca_cert {
+ get {
+ return _ca_cert;
+ }
+ }
+
+ public string subject {
+ get {
+ return _subject;
+ }
+ }
+
+ public string subject_alt {
+ get {
+ return _subject_alt;
+ }
+ }
+
+
+ public string server_cert {
+ get {
+ return _server_cert;
+ }
+ }
+
+ public string datetime_added {
+ get {
+ return _datetime_added;
+ }
+ }
+
+ 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;
+ }
+
+ internal void set_datetime_added(string datetime) {
+ _datetime_added = fixup(datetime);
+ }
+
+ internal static string format_datetime_now() {
+ DateTime now = new DateTime.now_utc();
+ string dt = now.format("%b %d %T %Y %Z");
+ return dt;
+ }
+