mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
added loggly integration
This commit is contained in:
parent
0e7ca07e02
commit
3010ed6073
7 changed files with 211 additions and 1 deletions
89
NzbDrone.Common/HashUtil.cs
Normal file
89
NzbDrone.Common/HashUtil.cs
Normal file
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public static class HashUtil
|
||||
{
|
||||
//This should never be changed. very bad things will happen!
|
||||
private static readonly DateTime Epoch = new DateTime(2010, 1, 1);
|
||||
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
public static string CalculateCrc(string input)
|
||||
{
|
||||
uint mCrc = 0xffffffff;
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(input);
|
||||
foreach (byte myByte in bytes)
|
||||
{
|
||||
mCrc ^= ((uint)(myByte) << 24);
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if ((Convert.ToUInt32(mCrc) & 0x80000000) == 0x80000000)
|
||||
{
|
||||
mCrc = (mCrc << 1) ^ 0x04C11DB7;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCrc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.Format("{0:x8}", mCrc);
|
||||
}
|
||||
|
||||
public static string GenerateUserId()
|
||||
{
|
||||
return GenerateId("u");
|
||||
}
|
||||
|
||||
public static string GenerateAppId()
|
||||
{
|
||||
return GenerateId("a");
|
||||
}
|
||||
|
||||
public static string GenerateApiToken()
|
||||
{
|
||||
return Guid.NewGuid().ToString().Replace("-", "");
|
||||
}
|
||||
|
||||
public static string GenerateSecurityToken(int length)
|
||||
{
|
||||
var byteSize = (length / 4) * 3;
|
||||
|
||||
var linkBytes = new byte[byteSize];
|
||||
var rngCrypto = new System.Security.Cryptography.RNGCryptoServiceProvider();
|
||||
rngCrypto.GetBytes(linkBytes);
|
||||
var base64String = Convert.ToBase64String(linkBytes);
|
||||
|
||||
return base64String;
|
||||
}
|
||||
|
||||
private static string GenerateId(string prefix)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
var tick = (DateTime.Now - Epoch).Ticks;
|
||||
return prefix + "." + ToBase(tick);
|
||||
}
|
||||
}
|
||||
|
||||
private static string ToBase(long input)
|
||||
{
|
||||
const string BASE_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
int targetBase = BASE_CHARS.Length;
|
||||
|
||||
var result = new StringBuilder();
|
||||
do
|
||||
{
|
||||
result.Append(BASE_CHARS[(int)(input % targetBase)]);
|
||||
input /= targetBase;
|
||||
} while (input > 0);
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue