Esempio n. 1
0
 /// <summary>
 /// Empaqquete un DIscoInfo
 /// </summary>
 /// <param name="info">DicoInfo</param>
 /// <returns>Ampaquetage</returns>
 public static string DiscoInfoToVersion(DiscoInfo info)
 {
     StringBuilder builder = new StringBuilder(256);
     DiscoIdentity[] identities = info.GetIdentities();
     string[] ids = new string[identities.Length];
     for (int i = 0; i < identities.Length; i++)
     {
         ids[i] = string.Format("{0}/{1}", identities[i].Category, identities[i].Type);
     }
     Array.Sort(ids);
     foreach (string id in ids)
     {
         builder.AppendFormat("{0}<", id);
     }
     DiscoFeature[] features = info.GetFeatures();
     string[] feas = new string[features.Length];
     for (int i = 0; i < features.Length; i++)
     {
         feas[i] = features[i].Var;
     }
     Array.Sort(feas);
     foreach (string fea in feas)
     {
         builder.AppendFormat("{0}<", fea);
     }
     SHA1Managed sha1 = new SHA1Managed();
     byte[] hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(builder.ToString()));
     return Convert.ToBase64String(hash);
 }
Esempio n. 2
0
        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
        }