private string BuildCapsVersion(DiscoInfo di) { /* 1. Initialize an empty string S. 2. Sort the service discovery identities by category and then by type (if it exists), formatted as 'category' '/' 'type'. 3. For each identity, append the 'category/type' to S, followed by the '<' character. 4. Sort the supported features. 5. For each feature, append the feature to S, followed by the '<' character. 6. Compute ver by hashing S using the SHA-1 algorithm as specified in RFC 3174 [17] (with binary output) and encoding the hash using Base64 as specified in Section 4 of RFC 4648 [18] (note: the Base64 output MUST NOT include whitespace and MUST set padding bits to zero). [19] */ ArrayList features = new ArrayList(); ArrayList identities = new ArrayList(); foreach (DiscoIdentity did in di.GetIdentities()) identities.Add(did.Type == null ? did.Category : did.Category + "/" + did.Type); foreach (DiscoFeature df in di.GetFeatures()) features.Add(df.Var); identities.Sort(); features.Sort(); StringBuilder S = new StringBuilder(); foreach (string s in identities) S.Append(s + "<"); foreach (string s in features) S.Append(s + "<"); byte[] sha1 = util.Hash.Sha1HashBytes(S.ToString()); #if CF return Convert.ToBase64String(sha1, 0, sha1.Length); #else return Convert.ToBase64String(sha1); #endif }
/// <summary> /// Builds and sets the caps ver attribute from a DiscoInfo object /// </summary> /// <param name="di"></param> public void SetVersion(DiscoInfo di) { Version = BuildCapsVersion(di); }