+#endif
+
+ public string issuer { get; set; default = ""; }
+
+ private Rule[] _rules = new Rule[0];
+ public Rule[] rules {
+ get {return _rules;}
+ internal set {_rules = value ?? new Rule[0] ;}
+ }
+
+ private ArrayList<string> _services = new ArrayList<string>();
+
+ internal ArrayList<string> services {
+ get {return _services;}
+ }
+
+ // Returns the list of services as a string, using the given separator.
+ internal string get_services_string(string sep) {
+ if (_services.is_empty) {
+ return "";
+ }
+
+ // ArrayList.to_array() seems to be unreliable -- it causes segfaults
+ // semi-randomly. (Possibly because it returns an unowned ref?)
+ // return string.joinv(sep, _services.to_array());
+ //
+ // This problem may be related to the one noted elsewhere as the
+ // "Centos vala array property bug".
+
+ string[] svcs = new string[_services.size];
+ for (int i = 0; i < _services.size; i++) {
+ svcs[i] = _services[i];
+ }
+
+ return string.joinv(sep, svcs);
+ }
+
+ internal void update_services(string[] services) {
+ _services.clear();
+
+ // Doesn't exist in older versions of libgee:
+ // _services.add_all_array(services);
+
+ if (services != null) {
+ foreach (string s in services) {
+ _services.add(s);
+ }
+ }
+ }
+
+ internal void update_services_from_list(ArrayList<string> services) {
+ if (services == this._services) {
+ // Don't try to update from self.
+ return;
+ }
+
+ _services.clear();
+
+ if (services != null) {
+ _services.add_all(services);
+ }
+ }
+
+
+ public bool temporary {get; set; default = false; }
+
+ public TrustAnchor trust_anchor { get; set; default = new TrustAnchor (); }
+
+ public unowned string nai { get { _nai = username + "@" + issuer; return _nai;}}
+
+ public bool store_password { get; set; default = false; }
+
+ public bool is_no_identity()
+ {
+ return (display_name == NO_IDENTITY);
+ }
+
+ public enum DiffFlags {
+ DISPLAY_NAME,
+ USERNAME,
+ PASSWORD,
+ ISSUER,
+ RULES,
+ SERVICES,
+ TRUST_ANCHOR;
+ }
+
+ public int Compare(IdCard other)
+ {
+ int diff = 0;
+ if (this.display_name != other.display_name)
+ diff |= 1 << DiffFlags.DISPLAY_NAME;
+
+ if (this.username != other.username)
+ diff |= 1 << DiffFlags.USERNAME;
+
+ if (this.password != other.password)
+ diff |= 1 << DiffFlags.PASSWORD;
+
+ if (this.issuer != other.issuer)
+ diff |= 1 << DiffFlags.ISSUER;
+
+ if (CompareRules(this.rules, other.rules)!=0)
+ diff |= 1 << DiffFlags.RULES;
+
+ if (CompareStringArrayList(this._services, other._services)!=0)
+ diff |= 1 << DiffFlags.SERVICES;
+
+ if (this.trust_anchor.Compare(other.trust_anchor)!=0)
+ diff |= 1 << DiffFlags.TRUST_ANCHOR;
+
+ // stdout.printf("Diff Flags: %x\n", diff);
+ return diff;
+ }
+
+ public static IdCard NewNoIdentity()
+ {
+ IdCard card = new IdCard();
+ card.display_name = NO_IDENTITY;
+ return card;
+ }
+
+ ~IdCard() {
+ password = null;
+ }
+
+ internal void add_rule(Rule rule) {
+ _rules += rule;
+ }
+}
+
+public int CompareRules(Rule[] a, Rule[] b)
+{
+ if (a.length != b.length) {
+ return 1;
+ }
+
+ for (int i = 0; i < a.length; i++) {
+ if (a[i].Compare(b[i]) != 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+public int CompareStringArrayList(ArrayList<string> a, ArrayList<string> b)
+{
+ if (a.size != b.size) {
+ return 1;
+ }