aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Cryptography/Constants.cs18
-rw-r--r--MediaBrowser.Common/Cryptography/CryptoExtensions.cs35
-rw-r--r--MediaBrowser.Common/Cryptography/PasswordHash.cs219
-rw-r--r--MediaBrowser.Common/FfmpegException.cs39
-rw-r--r--MediaBrowser.Common/IApplicationHost.cs11
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj12
-rw-r--r--MediaBrowser.Common/Net/IPNetAddress.cs2
-rw-r--r--MediaBrowser.Common/Net/IPObject.cs2
8 files changed, 52 insertions, 286 deletions
diff --git a/MediaBrowser.Common/Cryptography/Constants.cs b/MediaBrowser.Common/Cryptography/Constants.cs
deleted file mode 100644
index 354114232..000000000
--- a/MediaBrowser.Common/Cryptography/Constants.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace MediaBrowser.Common.Cryptography
-{
- /// <summary>
- /// Class containing global constants for Jellyfin Cryptography.
- /// </summary>
- public static class Constants
- {
- /// <summary>
- /// The default length for new salts.
- /// </summary>
- public const int DefaultSaltLength = 64;
-
- /// <summary>
- /// The default amount of iterations for hashing passwords.
- /// </summary>
- public const int DefaultIterations = 1000;
- }
-}
diff --git a/MediaBrowser.Common/Cryptography/CryptoExtensions.cs b/MediaBrowser.Common/Cryptography/CryptoExtensions.cs
deleted file mode 100644
index 157b0ed10..000000000
--- a/MediaBrowser.Common/Cryptography/CryptoExtensions.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System.Collections.Generic;
-using System.Globalization;
-using System.Text;
-using MediaBrowser.Model.Cryptography;
-using static MediaBrowser.Common.Cryptography.Constants;
-
-namespace MediaBrowser.Common.Cryptography
-{
- /// <summary>
- /// Class containing extension methods for working with Jellyfin cryptography objects.
- /// </summary>
- public static class CryptoExtensions
- {
- /// <summary>
- /// Creates a new <see cref="PasswordHash" /> instance.
- /// </summary>
- /// <param name="cryptoProvider">The <see cref="ICryptoProvider" /> instance used.</param>
- /// <param name="password">The password that will be hashed.</param>
- /// <returns>A <see cref="PasswordHash" /> instance with the hash method, hash, salt and number of iterations.</returns>
- public static PasswordHash CreatePasswordHash(this ICryptoProvider cryptoProvider, string password)
- {
- byte[] salt = cryptoProvider.GenerateSalt();
- return new PasswordHash(
- cryptoProvider.DefaultHashMethod,
- cryptoProvider.ComputeHashWithDefaultMethod(
- Encoding.UTF8.GetBytes(password),
- salt),
- salt,
- new Dictionary<string, string>
- {
- { "iterations", DefaultIterations.ToString(CultureInfo.InvariantCulture) }
- });
- }
- }
-}
diff --git a/MediaBrowser.Common/Cryptography/PasswordHash.cs b/MediaBrowser.Common/Cryptography/PasswordHash.cs
deleted file mode 100644
index 0e2065302..000000000
--- a/MediaBrowser.Common/Cryptography/PasswordHash.cs
+++ /dev/null
@@ -1,219 +0,0 @@
-#pragma warning disable CS1591
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace MediaBrowser.Common.Cryptography
-{
- // Defined from this hash storage spec
- // https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md
- // $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
- // with one slight amendment to ease the transition, we're writing out the bytes in hex
- // rather than making them a BASE64 string with stripped padding
- public class PasswordHash
- {
- private readonly Dictionary<string, string> _parameters;
- private readonly byte[] _salt;
- private readonly byte[] _hash;
-
- public PasswordHash(string id, byte[] hash)
- : this(id, hash, Array.Empty<byte>())
- {
- }
-
- public PasswordHash(string id, byte[] hash, byte[] salt)
- : this(id, hash, salt, new Dictionary<string, string>())
- {
- }
-
- public PasswordHash(string id, byte[] hash, byte[] salt, Dictionary<string, string> parameters)
- {
- if (id == null)
- {
- throw new ArgumentNullException(nameof(id));
- }
-
- if (id.Length == 0)
- {
- throw new ArgumentException("String can't be empty", nameof(id));
- }
-
- Id = id;
- _hash = hash;
- _salt = salt;
- _parameters = parameters;
- }
-
- /// <summary>
- /// Gets the symbolic name for the function used.
- /// </summary>
- /// <value>Returns the symbolic name for the function used.</value>
- public string Id { get; }
-
- /// <summary>
- /// Gets the additional parameters used by the hash function.
- /// </summary>
- public IReadOnlyDictionary<string, string> Parameters => _parameters;
-
- /// <summary>
- /// Gets the salt used for hashing the password.
- /// </summary>
- /// <value>Returns the salt used for hashing the password.</value>
- public ReadOnlySpan<byte> Salt => _salt;
-
- /// <summary>
- /// Gets the hashed password.
- /// </summary>
- /// <value>Return the hashed password.</value>
- public ReadOnlySpan<byte> Hash => _hash;
-
- public static PasswordHash Parse(ReadOnlySpan<char> hashString)
- {
- if (hashString.IsEmpty)
- {
- throw new ArgumentException("String can't be empty", nameof(hashString));
- }
-
- if (hashString[0] != '$')
- {
- throw new FormatException("Hash string must start with a $");
- }
-
- // Ignore first $
- hashString = hashString[1..];
-
- int nextSegment = hashString.IndexOf('$');
- if (hashString.IsEmpty || nextSegment == 0)
- {
- throw new FormatException("Hash string must contain a valid id");
- }
- else if (nextSegment == -1)
- {
- return new PasswordHash(hashString.ToString(), Array.Empty<byte>());
- }
-
- ReadOnlySpan<char> id = hashString[..nextSegment];
- hashString = hashString[(nextSegment + 1)..];
- Dictionary<string, string>? parameters = null;
-
- nextSegment = hashString.IndexOf('$');
-
- // Optional parameters
- ReadOnlySpan<char> parametersSpan = nextSegment == -1 ? hashString : hashString[..nextSegment];
- if (parametersSpan.Contains('='))
- {
- while (!parametersSpan.IsEmpty)
- {
- ReadOnlySpan<char> parameter;
- int index = parametersSpan.IndexOf(',');
- if (index == -1)
- {
- parameter = parametersSpan;
- parametersSpan = ReadOnlySpan<char>.Empty;
- }
- else
- {
- parameter = parametersSpan[..index];
- parametersSpan = parametersSpan[(index + 1)..];
- }
-
- int splitIndex = parameter.IndexOf('=');
- if (splitIndex == -1 || splitIndex == 0 || splitIndex == parameter.Length - 1)
- {
- throw new FormatException("Malformed parameter in password hash string");
- }
-
- (parameters ??= new Dictionary<string, string>()).Add(
- parameter[..splitIndex].ToString(),
- parameter[(splitIndex + 1)..].ToString());
- }
-
- if (nextSegment == -1)
- {
- // parameters can't be null here
- return new PasswordHash(id.ToString(), Array.Empty<byte>(), Array.Empty<byte>(), parameters!);
- }
-
- hashString = hashString[(nextSegment + 1)..];
- nextSegment = hashString.IndexOf('$');
- }
-
- if (nextSegment == 0)
- {
- throw new FormatException("Hash string contains an empty segment");
- }
-
- byte[] hash;
- byte[] salt;
-
- if (nextSegment == -1)
- {
- salt = Array.Empty<byte>();
- hash = Convert.FromHexString(hashString);
- }
- else
- {
- salt = Convert.FromHexString(hashString[..nextSegment]);
- hashString = hashString[(nextSegment + 1)..];
- nextSegment = hashString.IndexOf('$');
- if (nextSegment != -1)
- {
- throw new FormatException("Hash string contains too many segments");
- }
-
- if (hashString.IsEmpty)
- {
- throw new FormatException("Hash segment is empty");
- }
-
- hash = Convert.FromHexString(hashString);
- }
-
- return new PasswordHash(id.ToString(), hash, salt, parameters ?? new Dictionary<string, string>());
- }
-
- private void SerializeParameters(StringBuilder stringBuilder)
- {
- if (_parameters.Count == 0)
- {
- return;
- }
-
- stringBuilder.Append('$');
- foreach (var pair in _parameters)
- {
- stringBuilder.Append(pair.Key)
- .Append('=')
- .Append(pair.Value)
- .Append(',');
- }
-
- // Remove last ','
- stringBuilder.Length -= 1;
- }
-
- /// <inheritdoc />
- public override string ToString()
- {
- var str = new StringBuilder()
- .Append('$')
- .Append(Id);
- SerializeParameters(str);
-
- if (_salt.Length != 0)
- {
- str.Append('$')
- .Append(Convert.ToHexString(_salt));
- }
-
- if (_hash.Length != 0)
- {
- str.Append('$')
- .Append(Convert.ToHexString(_hash));
- }
-
- return str.ToString();
- }
- }
-}
diff --git a/MediaBrowser.Common/FfmpegException.cs b/MediaBrowser.Common/FfmpegException.cs
new file mode 100644
index 000000000..be420196d
--- /dev/null
+++ b/MediaBrowser.Common/FfmpegException.cs
@@ -0,0 +1,39 @@
+using System;
+
+namespace MediaBrowser.Common
+{
+ /// <summary>
+ /// Represents errors that occur during interaction with FFmpeg.
+ /// </summary>
+ public class FfmpegException : Exception
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FfmpegException"/> class.
+ /// </summary>
+ public FfmpegException()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FfmpegException"/> class with a specified error message.
+ /// </summary>
+ /// <param name="message">The message that describes the error.</param>
+ public FfmpegException(string message) : base(message)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FfmpegException"/> class with a specified error message and a
+ /// reference to the inner exception that is the cause of this exception.
+ /// </summary>
+ /// <param name="message">The error message that explains the reason for the exception.</param>
+ /// <param name="innerException">
+ /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if
+ /// no inner exception is specified.
+ /// </param>
+ public FfmpegException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs
index 192a77611..53683cdbd 100644
--- a/MediaBrowser.Common/IApplicationHost.cs
+++ b/MediaBrowser.Common/IApplicationHost.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common
{
@@ -137,13 +138,7 @@ namespace MediaBrowser.Common
/// <summary>
/// Initializes this instance.
/// </summary>
- void Init();
-
- /// <summary>
- /// Creates the instance.
- /// </summary>
- /// <param name="type">The type.</param>
- /// <returns>System.Object.</returns>
- object CreateInstance(Type type);
+ /// <param name="serviceCollection">Instance of the <see cref="IServiceCollection"/> interface.</param>
+ void Init(IServiceCollection serviceCollection);
}
}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 6358c0000..2a2fffce0 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -19,9 +19,9 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
- <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
- <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
+ <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
@@ -38,6 +38,10 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+ </PropertyGroup>
+
<PropertyGroup Condition=" '$(Stability)'=='Unstable'">
<!-- Include all symbols in the main nupkg until Azure Artifact Feed starts supporting ingesting NuGet symbol packages. -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
@@ -46,7 +50,7 @@
<!-- Code analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
- <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>
diff --git a/MediaBrowser.Common/Net/IPNetAddress.cs b/MediaBrowser.Common/Net/IPNetAddress.cs
index f6e3971bf..f1428d4be 100644
--- a/MediaBrowser.Common/Net/IPNetAddress.cs
+++ b/MediaBrowser.Common/Net/IPNetAddress.cs
@@ -195,7 +195,7 @@ namespace MediaBrowser.Common.Net
return NetworkAddress.PrefixLength <= netaddrObj.PrefixLength;
}
- var altAddress = NetworkAddressOf(netaddrObj.Address, PrefixLength).address;
+ var altAddress = NetworkAddressOf(netaddrObj.Address, PrefixLength).Address;
return NetworkAddress.Address.Equals(altAddress);
}
diff --git a/MediaBrowser.Common/Net/IPObject.cs b/MediaBrowser.Common/Net/IPObject.cs
index 2612268fd..bd5368882 100644
--- a/MediaBrowser.Common/Net/IPObject.cs
+++ b/MediaBrowser.Common/Net/IPObject.cs
@@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Net
/// <param name="address">IP Address to convert.</param>
/// <param name="prefixLength">Subnet prefix.</param>
/// <returns>IPAddress.</returns>
- public static (IPAddress address, byte prefixLength) NetworkAddressOf(IPAddress address, byte prefixLength)
+ public static (IPAddress Address, byte PrefixLength) NetworkAddressOf(IPAddress address, byte prefixLength)
{
if (address == null)
{