mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-30 11:48:26 -07:00
New: Implemented Torrent Download Clients: uTorrent, Transmission and Deluge. And several public and private Torrent Indexers.
This commit is contained in:
parent
ffa814f387
commit
67cd5703a1
134 changed files with 11018 additions and 99 deletions
41
src/MonoTorrent/HashAlgoFactory.cs
Normal file
41
src/MonoTorrent/HashAlgoFactory.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace MonoTorrent
|
||||
{
|
||||
public static class HashAlgoFactory
|
||||
{
|
||||
static Dictionary<Type, Type> algos = new Dictionary<Type, Type>();
|
||||
|
||||
static HashAlgoFactory()
|
||||
{
|
||||
Register<MD5, MD5CryptoServiceProvider>();
|
||||
Register<SHA1, SHA1CryptoServiceProvider>();
|
||||
}
|
||||
|
||||
public static void Register<T, U>()
|
||||
where T : HashAlgorithm
|
||||
where U : HashAlgorithm
|
||||
{
|
||||
Register(typeof(T), typeof(U));
|
||||
}
|
||||
|
||||
public static void Register(Type baseType, Type specificType)
|
||||
{
|
||||
Check.BaseType(baseType);
|
||||
Check.SpecificType(specificType);
|
||||
|
||||
lock (algos)
|
||||
algos[baseType] = specificType;
|
||||
}
|
||||
|
||||
public static T Create<T>()
|
||||
where T : HashAlgorithm
|
||||
{
|
||||
if (algos.ContainsKey(typeof(T)))
|
||||
return (T)Activator.CreateInstance(algos[typeof(T)]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue