#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Paddings
{
/// A padder that adds Null byte padding to a block.
public class ZeroBytePadding : IBlockCipherPadding
{
/// Return the name of the algorithm the cipher implements.
///
///
/// the name of the algorithm the cipher implements.
///
public string PaddingName
{
get { return "ZeroBytePadding"; }
}
/// Initialise the padder.
///
///
/// - a SecureRandom if available.
///
public void Init(SecureRandom random)
{
// nothing to do.
}
public int AddPadding(byte[] input, int inOff)
{
int added = input.Length - inOff;
while (inOff < input.Length)
{
input[inOff++] = 0x00;
}
return added;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
public int AddPadding(Span block, int position)
{
int count = block.Length - position;
block[position..].Fill(0x00);
return count;
}
#endif
public int PadCount(byte[] input)
{
int count = 0, still00Mask = -1;
int i = input.Length;
while (--i >= 0)
{
int next = input[i];
int match00Mask = ((next ^ 0x00) - 1) >> 31;
still00Mask &= match00Mask;
count -= still00Mask;
}
return count;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
public int PadCount(ReadOnlySpan block)
{
int count = 0, still00Mask = -1;
int i = block.Length;
while (--i >= 0)
{
int next = block[i];
int match00Mask = ((next ^ 0x00) - 1) >> 31;
still00Mask &= match00Mask;
count -= still00Mask;
}
return count;
}
#endif
}
}
#pragma warning restore
#endif