Reworked encryption to use less heap allocated buffers for secrets.
Also some work on plugin system.
This commit is contained in:
parent
8782ef39c6
commit
054754f553
42 changed files with 1452 additions and 242 deletions
59
IdentityShroud.Core/Plugins/PluginLoader.cs
Normal file
59
IdentityShroud.Core/Plugins/PluginLoader.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using IdentityShroud.PluginSupport;
|
||||
|
||||
namespace IdentityShroud.Core.Plugins;
|
||||
|
||||
public static class PluginLoader
|
||||
{
|
||||
public static IEnumerable<IPlugin> LoadPlugins(string pluginsFolder)
|
||||
{
|
||||
if (!Directory.Exists(pluginsFolder))
|
||||
yield break;
|
||||
|
||||
foreach (var dll in Directory.EnumerateFiles(pluginsFolder, "*.dll"))
|
||||
{
|
||||
foreach (var plugin in LoadPluginDll(dll)) yield return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<IPlugin> LoadPluginDll(string dll)
|
||||
{
|
||||
Assembly asm;
|
||||
try
|
||||
{
|
||||
asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(dll));
|
||||
}
|
||||
catch
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
IEnumerable<Type> pluginTypes;
|
||||
try
|
||||
{
|
||||
pluginTypes = asm.GetTypes()
|
||||
.Where(t => typeof(IPlugin).IsAssignableFrom(t) && t is { IsInterface: false, IsAbstract: false });
|
||||
}
|
||||
catch
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var t in pluginTypes)
|
||||
{
|
||||
IPlugin? instance = null;
|
||||
try
|
||||
{
|
||||
instance = (IPlugin?)Activator.CreateInstance(t);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore bad plugin types
|
||||
}
|
||||
|
||||
if (instance != null)
|
||||
yield return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue