diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 5a5046e..366a38f 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -409,19 +409,25 @@ namespace OpenSim.Framework | |||
409 | /// </summary> | 409 | /// </summary> |
410 | /// <param name="data"></param> | 410 | /// <param name="data"></param> |
411 | /// <returns></returns> | 411 | /// <returns></returns> |
412 | |||
412 | public static string Md5Hash(string data) | 413 | public static string Md5Hash(string data) |
413 | { | 414 | { |
414 | byte[] dataMd5 = ComputeMD5Hash(data); | 415 | return Md5Hash(data, Encoding.Default); |
416 | } | ||
417 | |||
418 | public static string Md5Hash(string data, Encoding encoding) | ||
419 | { | ||
420 | byte[] dataMd5 = ComputeMD5Hash(data, encoding); | ||
415 | StringBuilder sb = new StringBuilder(); | 421 | StringBuilder sb = new StringBuilder(); |
416 | for (int i = 0; i < dataMd5.Length; i++) | 422 | for (int i = 0; i < dataMd5.Length; i++) |
417 | sb.AppendFormat("{0:x2}", dataMd5[i]); | 423 | sb.AppendFormat("{0:x2}", dataMd5[i]); |
418 | return sb.ToString(); | 424 | return sb.ToString(); |
419 | } | 425 | } |
420 | 426 | ||
421 | private static byte[] ComputeMD5Hash(string data) | 427 | private static byte[] ComputeMD5Hash(string data, Encoding encoding) |
422 | { | 428 | { |
423 | MD5 md5 = MD5.Create(); | 429 | MD5 md5 = MD5.Create(); |
424 | return md5.ComputeHash(Encoding.Default.GetBytes(data)); | 430 | return md5.ComputeHash(encoding.GetBytes(data)); |
425 | } | 431 | } |
426 | 432 | ||
427 | /// <summary> | 433 | /// <summary> |
@@ -429,16 +435,22 @@ namespace OpenSim.Framework | |||
429 | /// </summary> | 435 | /// </summary> |
430 | /// <param name="data"></param> | 436 | /// <param name="data"></param> |
431 | /// <returns></returns> | 437 | /// <returns></returns> |
438 | |||
432 | public static string SHA1Hash(string data) | 439 | public static string SHA1Hash(string data) |
433 | { | 440 | { |
434 | byte[] hash = ComputeSHA1Hash(data); | 441 | return SHA1Hash(data, Encoding.Default); |
442 | } | ||
443 | |||
444 | public static string SHA1Hash(string data, Encoding encoding) | ||
445 | { | ||
446 | byte[] hash = ComputeSHA1Hash(data, encoding); | ||
435 | return BitConverter.ToString(hash).Replace("-", String.Empty); | 447 | return BitConverter.ToString(hash).Replace("-", String.Empty); |
436 | } | 448 | } |
437 | 449 | ||
438 | private static byte[] ComputeSHA1Hash(string src) | 450 | private static byte[] ComputeSHA1Hash(string src, Encoding encoding) |
439 | { | 451 | { |
440 | SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); | 452 | SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); |
441 | return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); | 453 | return SHA1.ComputeHash(encoding.GetBytes(src)); |
442 | } | 454 | } |
443 | 455 | ||
444 | public static int fast_distance2d(int x, int y) | 456 | public static int fast_distance2d(int x, int y) |
@@ -1023,19 +1035,19 @@ namespace OpenSim.Framework | |||
1023 | { | 1035 | { |
1024 | string os = String.Empty; | 1036 | string os = String.Empty; |
1025 | 1037 | ||
1026 | if (Environment.OSVersion.Platform != PlatformID.Unix) | 1038 | // if (Environment.OSVersion.Platform != PlatformID.Unix) |
1027 | { | 1039 | // { |
1028 | os = Environment.OSVersion.ToString(); | 1040 | // os = Environment.OSVersion.ToString(); |
1029 | } | 1041 | // } |
1030 | else | 1042 | // else |
1031 | { | 1043 | // { |
1032 | os = ReadEtcIssue(); | 1044 | // os = ReadEtcIssue(); |
1033 | } | 1045 | // } |
1034 | 1046 | // | |
1035 | if (os.Length > 45) | 1047 | // if (os.Length > 45) |
1036 | { | 1048 | // { |
1037 | os = os.Substring(0, 45); | 1049 | // os = os.Substring(0, 45); |
1038 | } | 1050 | // } |
1039 | 1051 | ||
1040 | return os; | 1052 | return os; |
1041 | } | 1053 | } |
@@ -1168,7 +1180,7 @@ namespace OpenSim.Framework | |||
1168 | 1180 | ||
1169 | public static Guid GetHashGuid(string data, string salt) | 1181 | public static Guid GetHashGuid(string data, string salt) |
1170 | { | 1182 | { |
1171 | byte[] hash = ComputeMD5Hash(data + salt); | 1183 | byte[] hash = ComputeMD5Hash(data + salt, Encoding.Default); |
1172 | 1184 | ||
1173 | //string s = BitConverter.ToString(hash); | 1185 | //string s = BitConverter.ToString(hash); |
1174 | 1186 | ||
@@ -1537,6 +1549,23 @@ namespace OpenSim.Framework | |||
1537 | return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1); | 1549 | return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1); |
1538 | } | 1550 | } |
1539 | 1551 | ||
1552 | // Returns value of Tick Count A - TickCount B accounting for wrapping of TickCount | ||
1553 | // Assumes both tcA and tcB came from previous calls to Util.EnvironmentTickCount(). | ||
1554 | // A positive return value indicates A occured later than B | ||
1555 | public static Int32 EnvironmentTickCountCompare(Int32 tcA, Int32 tcB) | ||
1556 | { | ||
1557 | // A, B and TC are all between 0 and 0x3fffffff | ||
1558 | int tc = EnvironmentTickCount(); | ||
1559 | |||
1560 | if (tc - tcA >= 0) | ||
1561 | tcA += EnvironmentTickCountMask + 1; | ||
1562 | |||
1563 | if (tc - tcB >= 0) | ||
1564 | tcB += EnvironmentTickCountMask + 1; | ||
1565 | |||
1566 | return tcA - tcB; | ||
1567 | } | ||
1568 | |||
1540 | /// <summary> | 1569 | /// <summary> |
1541 | /// Prints the call stack at any given point. Useful for debugging. | 1570 | /// Prints the call stack at any given point. Useful for debugging. |
1542 | /// </summary> | 1571 | /// </summary> |