| | using System; |
| | using System.Text; |
| | using System.Security.Cryptography; |
| | using UnityEngine; |
| |
|
| | namespace Unity.MLAgents.Analytics |
| | { |
| | internal static class AnalyticsUtils |
| | { |
| | |
| | |
| | |
| | |
| | |
| | private static string ToHexString(byte[] array) |
| | { |
| | StringBuilder hex = new StringBuilder(array.Length * 2); |
| | foreach (byte b in array) |
| | { |
| | hex.AppendFormat("{0:x2}", b); |
| | } |
| | return hex.ToString(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static string Hash(string key, string value) |
| | { |
| | string hash; |
| | UTF8Encoding encoder = new UTF8Encoding(); |
| | using (HMACSHA256 hmac = new HMACSHA256(encoder.GetBytes(key))) |
| | { |
| | Byte[] hmBytes = hmac.ComputeHash(encoder.GetBytes(value)); |
| | hash = ToHexString(hmBytes); |
| | } |
| | return hash; |
| | } |
| |
|
| | internal static bool s_SendEditorAnalytics = true; |
| |
|
| | |
| | |
| | |
| | internal class DisableAnalyticsSending : IDisposable |
| | { |
| | private bool m_PreviousSendEditorAnalytics; |
| |
|
| | public DisableAnalyticsSending() |
| | { |
| | m_PreviousSendEditorAnalytics = s_SendEditorAnalytics; |
| | s_SendEditorAnalytics = false; |
| | } |
| |
|
| | public void Dispose() |
| | { |
| | s_SendEditorAnalytics = m_PreviousSendEditorAnalytics; |
| | } |
| | } |
| | } |
| | } |
| |
|