diff --git a/Assets/Settings/Editor/User/URSEditorUserSettings.asset b/Assets/Settings/Editor/User/URSEditorUserSettings.asset
deleted file mode 100644
index 973fd3f..0000000
--- a/Assets/Settings/Editor/User/URSEditorUserSettings.asset
+++ /dev/null
@@ -1,20 +0,0 @@
-%YAML 1.1
-%TAG !u! tag:unity3d.com,2011:
---- !u!114 &11400000
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 0}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 0}
- m_Name: URSEditorUserSettings
- m_EditorClassIdentifier: Assembly-CSharp-Editor::URSEditorUserSettings
- BuildVersionCode: 1.0.0
- CopyToStreamTargetVersion: 1.0.0
- BuildChannel: default_channel
- AppId: AppId
- AppToChannelRouter:
- Items: []
diff --git a/Assets/URS/Animation/Editor/AnimationClipUtil.cs b/Assets/URS/Animation/Editor/AnimationClipUtil.cs
index 069acdd..58c3f04 100644
--- a/Assets/URS/Animation/Editor/AnimationClipUtil.cs
+++ b/Assets/URS/Animation/Editor/AnimationClipUtil.cs
@@ -26,7 +26,7 @@ Hope this helps and please comment with any questions. Thanks!
using UnityEditor;
using System.IO;
using System.Collections.Generic;
-using static DG.DemiEditor.DeGUIKey;
+//using static DG.DemiEditor.DeGUIKey;
public class SpiteAnimationClip : ScriptableWizard
{
diff --git a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/AssetSearchTableItem.cs b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/AssetSearchTableItem.cs
index 7c80ab9..fac6eed 100644
--- a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/AssetSearchTableItem.cs
+++ b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/AssetSearchTableItem.cs
@@ -101,7 +101,7 @@ public void UpdateProfileState()
}
enabledProcessorCount++;
- if (!userData.HasProcessor(processor))
+ if (!processor.IsConfigOK(userData.GetAssetImporter()) ||!userData.HasProcessor(processor))
{
missingProcessors.Add($"Processor: {processor.GetName()}\nFilter: {filter.file.pattern}");
}
diff --git a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableItem.cs b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableItem.cs
index 0c6a2f7..949e1a9 100644
--- a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableItem.cs
+++ b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableItem.cs
@@ -72,7 +72,7 @@ public void UpdateProfileState()
}
enabledProcessorCount++;
- if (!userData.HasProcessor(processor))
+ if (!processor.IsConfigOK(userData.GetAssetImporter()) ||!userData.HasProcessor(processor))
{
missingProcessors.Add($"Processor: {processor.GetName()}\nFilter: {filter.file.pattern}");
}
diff --git a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableView.cs b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableView.cs
index edb6156..bb0d4fe 100644
--- a/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableView.cs
+++ b/Assets/URS/AssetPipeline/Editor/Interface/TreeViews/ImportProfileAssetTableView.cs
@@ -155,6 +155,7 @@ protected override void CellGUI(Rect cellRect, int columnIndex, AssetTableItem a
{
var tooltip = string.Empty;
GUIContent icon = null;
+ // Debug.LogError(" asset path "+ item.assetPath+ " item.profileState "+ item.profileState);
switch (item.profileState)
{
case AssetProfileState.NoMatchingFilters:
diff --git a/Assets/URS/AssetPipeline/Editor/PathConvention/Anchor.cs b/Assets/URS/AssetPipeline/Editor/PathConvention/Anchor.cs
index 8198341..9a0ae0a 100644
--- a/Assets/URS/AssetPipeline/Editor/PathConvention/Anchor.cs
+++ b/Assets/URS/AssetPipeline/Editor/PathConvention/Anchor.cs
@@ -7,5 +7,6 @@ public enum Anchor
End = 2,
Exact = 3,
AllPaths = 4,
+ Regex= 5,
}
}
\ No newline at end of file
diff --git a/Assets/URS/AssetPipeline/Editor/PathConvention/Template.cs b/Assets/URS/AssetPipeline/Editor/PathConvention/Template.cs
index f1c120c..367115b 100644
--- a/Assets/URS/AssetPipeline/Editor/PathConvention/Template.cs
+++ b/Assets/URS/AssetPipeline/Editor/PathConvention/Template.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Debug = UnityEngine.Debug;
using System.Text.RegularExpressions;
namespace Daihenka.AssetPipeline.NamingConvention
@@ -406,6 +407,10 @@ Regex ConstructRegularExpression(string rePattern)
{
expression += "$";
}
+ if (Anchor == Anchor.Regex)
+ {
+ expression = rePattern;
+ }
Regex compiled;
try
diff --git a/Assets/URS/AssetPipeline/Editor/Postprocessors/AssetImportPostprocessor.cs b/Assets/URS/AssetPipeline/Editor/Postprocessors/AssetImportPostprocessor.cs
index 5fa6f8d..d46e228 100644
--- a/Assets/URS/AssetPipeline/Editor/Postprocessors/AssetImportPostprocessor.cs
+++ b/Assets/URS/AssetPipeline/Editor/Postprocessors/AssetImportPostprocessor.cs
@@ -35,7 +35,7 @@ static List GetProcessors(string assetPath, string[] methodNames
var result = new List(s_CachedProcessors[assetPath].Count);
foreach (var processor in s_CachedProcessors[assetPath])
{
- if (AssetProcessor.IsForceApply(assetPath) || ((isOnDeletedAsset || !ImportProfileUserData.HasProcessor(assetPath, processor)) && processor.HasOverriddenMethods(methodNames)))
+ if (processor.FireOnEveryImport()|| AssetProcessor.IsForceApply(assetPath) || ((isOnDeletedAsset || !ImportProfileUserData.HasProcessor(assetPath, processor)) && processor.HasOverriddenMethods(methodNames)))
{
result.Add(processor);
}
@@ -188,6 +188,7 @@ void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
void OnPostprocessTexture(Texture2D texture)
{
+ CustomAssetImportPostprocessor.OnPostprocessTexture(assetPath, assetImporter);
foreach (var processor in GetProcessors(assetPath, MethodBase.GetCurrentMethod().Name))
{
processor.OnPostprocessTexture(assetPath, assetImporter as TextureImporter, texture);
@@ -259,9 +260,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
AssetProcessor.SetForceApply(assetPath, false);
}
- foreach (var assetPath in deletedAssets) {
- foreach (var processor in GetProcessors(assetPath, "OnDeletedAsset")) {
- processor.OnDeletedAsset(assetPath);
+ foreach (var assetPath in deletedAssets)
+ {
+ if (!string.IsNullOrEmpty(assetPath))
+ {
+ foreach (var processor in GetProcessors(assetPath, "OnDeletedAsset"))
+ {
+ processor.OnDeletedAsset(assetPath);
+ }
}
}
diff --git a/Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs b/Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs
new file mode 100644
index 0000000..405f1a1
--- /dev/null
+++ b/Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs
@@ -0,0 +1,193 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Daihenka.AssetPipeline.Import;
+using NinjaBeats;
+using UnityEditor;
+using UnityEditor.AssetImporters;
+using UnityEngine;
+
+public class CustomAssetImportPostprocessor
+{
+ public const string VFXDirectoryPath = "Assets/GameResources/VFX/Texture";
+ public const string VFXDirectoryPath2 = "Assets/GameResources/VFX/Scene/Texture";
+
+
+ private static string[] Platforms = new string[] { "Android", "iOS" };
+
+ public static void OnPostprocessTexture(string assetPath, AssetImporter assetImporter)
+ {
+ if (assetPath == null) return;
+ if ((!assetPath.Contains(VFXDirectoryPath)) && (!assetPath.Contains(VFXDirectoryPath2))) return;
+
+ var ti = assetImporter as TextureImporter;
+ if (ti == null) return;
+
+ bool showWarning = false;
+ string message = "";
+ foreach (var platform in Platforms)
+ {
+ var currentSetting = ti.GetPlatformTextureSettings(platform);
+ // Debug.LogError("platform.name " + platform + " tPath ? " + (tPath));
+ if (currentSetting == null)
+ {
+ message += $" 没有安装{platform}的扩展 ";
+ showWarning = true;
+ }
+
+ if (!currentSetting.overridden)
+ {
+ message += $" {platform}没有点击overrider ";
+ showWarning = true;
+ }
+
+ if (currentSetting.overridden && currentSetting.maxTextureSize > 1024)
+ {
+ message += $" {platform}maxTextureSize 不能高于1024 ";
+ showWarning = true;
+ }
+
+ if (currentSetting.overridden && currentSetting.format != TextureImporterFormat.ASTC_4x4
+ && currentSetting.format != TextureImporterFormat.ASTC_5x5
+ && currentSetting.format != TextureImporterFormat.ASTC_6x6
+ && currentSetting.format != TextureImporterFormat.ASTC_8x8
+ && currentSetting.format != TextureImporterFormat.ASTC_10x10
+ && currentSetting.format != TextureImporterFormat.ASTC_12x12
+ )
+ {
+ message += $"{platform}format 不是astc,当前的格式是 {currentSetting.format}";
+ showWarning = true;
+ }
+ }
+
+ if (showWarning)
+ {
+ if (EditorApplication.isUpdating && EditorUtility.DisplayDialog("警告", $"特效贴图没有设置,路径{assetPath},原因 {message}", "确定"))
+ {
+ }
+ }
+ else
+ {
+ Debug.Log($"特效贴图设置OK,路径{assetPath}");
+ }
+ }
+
+ public delegate void CheckVFXTextureDelegate(string assetPath, string message);
+
+ public static void CheckVFXTexture(string assetPath, CheckVFXTextureDelegate func, int preferMaxTextureSize = 1024)
+ {
+ var assetImporter = AssetImporter.GetAtPath(assetPath);
+
+ var ti = assetImporter as TextureImporter;
+
+ //Debug.LogError("platform.name " + tPath + " is null? " + (ti==null));
+ if (ti == null)
+ return;
+
+ string message = "";
+
+ var texture = AssetDatabase.LoadAssetAtPath(assetPath);
+ if (texture != null)
+ {
+ if ((texture.width & texture.width - 1) != 0 || (texture.height & texture.height - 1) != 0)
+ {
+ message += " 不是2的幂次方";
+ }
+ }
+
+ if (ti.isReadable)
+ {
+ message += " 不能开启Read/Write Enabled";
+ }
+
+ // if (ti.mipmapEnabled)
+ // {
+ // message += $" 不能开启mipmap";
+ // }
+ //
+ // if (ti.streamingMipmaps)
+ // {
+ // message += " 不能开启mipmap串流";
+ // }
+
+ int maxTextureSize = 0;
+ TextureImporterFormat format = TextureImporterFormat.Automatic;
+ bool isFirst = true;
+ foreach (var platform in Platforms)
+ {
+ var currentSetting = ti.GetPlatformTextureSettings(platform);
+ // Debug.LogError("platform.name " + platform + " tPath ? " + (tPath));
+ if (currentSetting == null)
+ {
+ message += $" 没有安装\'{platform}\'的扩展";
+ }
+
+ if (!currentSetting.overridden)
+ {
+ message += $" \'{platform}\'没有点击override";
+ }
+
+ if (currentSetting.overridden && currentSetting.maxTextureSize > preferMaxTextureSize)
+ {
+ message += $" \'{platform}\'maxTextureSize 不能高于{preferMaxTextureSize}";
+ }
+
+ if (currentSetting.overridden && currentSetting.format != TextureImporterFormat.ASTC_4x4
+ && currentSetting.format != TextureImporterFormat.ASTC_5x5
+ && currentSetting.format != TextureImporterFormat.ASTC_6x6
+ && currentSetting.format != TextureImporterFormat.ASTC_8x8
+ && currentSetting.format != TextureImporterFormat.ASTC_10x10
+ && currentSetting.format != TextureImporterFormat.ASTC_12x12
+ )
+ {
+ message += $" \'{platform}\'format 不是astc ,当前的格式是 {currentSetting.format}";
+ }
+
+ if (isFirst)
+ {
+ isFirst = false;
+ maxTextureSize = currentSetting.maxTextureSize;
+ format = currentSetting.format;
+ }
+ else
+ {
+ if (maxTextureSize != currentSetting.maxTextureSize)
+ {
+ message += $" \'Android\'与\'iOS\'maxTextureSize 不一致";
+ }
+
+ if (format != currentSetting.format)
+ {
+ message += $" \'Android\'与\'iOS\'format 不一致";
+ }
+ }
+ }
+
+ func(assetPath, message);
+ }
+
+ public static void CheckVFXTexture(CheckVFXTextureDelegate func)
+ {
+ var textures = AssetDatabase.FindAssets("t:Texture", new string[] { VFXDirectoryPath });
+ if (textures == null) return;
+ //Debug.LogError("platform.name " + textures.Length);
+ foreach (var guid in textures)
+ {
+ var tPath = AssetDatabase.GUIDToAssetPath(guid);
+ CheckVFXTexture(tPath, func);
+ }
+ }
+
+ [MenuItem("Tools/检查特效贴图设置")]
+ public static void CheckVFXTexture()
+ {
+ CheckVFXTexture((assetPath, message) =>
+ {
+ if (!string.IsNullOrWhiteSpace(message))
+ Debug.LogError($"特效贴图没有设置,路径{assetPath},原因:{message}");
+ else
+ Debug.Log($"特效贴图设置OK,路径{assetPath}");
+ });
+ }
+}
\ No newline at end of file
diff --git a/Assets/URS/Setting/Editor/Settings/ScriptableObjectSettingsProvider.cs.meta b/Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs.meta
similarity index 83%
rename from Assets/URS/Setting/Editor/Settings/ScriptableObjectSettingsProvider.cs.meta
rename to Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs.meta
index 28136c9..7976897 100644
--- a/Assets/URS/Setting/Editor/Settings/ScriptableObjectSettingsProvider.cs.meta
+++ b/Assets/URS/AssetPipeline/Editor/Postprocessors/TexturePostprocess.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: c9f3529e51db83c41a2464f56cd2f310
+guid: b3a03a52035dd694a98cf194dad859f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/URS/AssetPipeline/Editor/Processors/AnimCompression.cs b/Assets/URS/AssetPipeline/Editor/Processors/AnimCompression.cs
index bf1540d..ee9f1be 100644
--- a/Assets/URS/AssetPipeline/Editor/Processors/AnimCompression.cs
+++ b/Assets/URS/AssetPipeline/Editor/Processors/AnimCompression.cs
@@ -8,20 +8,51 @@ namespace Daihenka.AssetPipeline.Processors
[AssetProcessorDescription("FilterByLabel@2x", ImportAssetTypeFlag.Models)]
public class AnimCompression : AssetProcessor
{
- [SerializeField] private ModelImporterAnimationCompression animationCompression;
+ [SerializeField] private ModelImporterAnimationCompression animationCompression;
[SerializeField] private float animationRotationError;
[SerializeField] private float animationPositionError;
[SerializeField] private float animationScaleError;
-
+ [SerializeField] private bool resampleCurve=false;
+ public override bool IsConfigOK (AssetImporter importer)
+ {
+ if (importer == null) return false;
+ var mi= importer as ModelImporter;
+ if (mi == null) return false;
+ if (!mi.importAnimation) return true;
+ if (mi.animationCompression != animationCompression)
+ {
+ return false;
+ }
+ if (mi.animationRotationError != animationRotationError)
+ {
+ return false;
+ }
+ if (mi.animationPositionError != animationPositionError)
+ {
+ return false;
+ }
+ if (mi.animationScaleError != animationScaleError)
+ {
+ return false;
+ }
+ if (mi.resampleCurves != resampleCurve)
+ {
+ return false;
+ }
+ return true;
+ }
public override void OnPostprocessModel(string assetPath, ModelImporter importer, GameObject go)
{
- importer.animationCompression = animationCompression;
- importer.animationRotationError = animationRotationError;
- importer.animationPositionError = animationPositionError;
- importer.animationScaleError = animationScaleError;
-
- ImportProfileUserData.AddOrUpdateProcessor(assetPath, this);
- Debug.Log($"[{GetName()}] Preset applied for {assetPath}");
+ if (importer.importAnimation&& !IsConfigOK(importer))
+ {
+ importer.animationCompression = animationCompression;
+ importer.animationRotationError = animationRotationError;
+ importer.animationPositionError = animationPositionError;
+ importer.animationScaleError = animationScaleError;
+ importer.resampleCurves = resampleCurve;
+ ImportProfileUserData.AddOrUpdateProcessor(assetPath, this);
+ Debug.Log($"[{GetName()}] Preset applied for {assetPath}");
+ }
}
}
diff --git a/Assets/URS/AssetPipeline/Editor/Processors/ApplyPreset.cs b/Assets/URS/AssetPipeline/Editor/Processors/ApplyPreset.cs
index b14ccd9..8bb716a 100644
--- a/Assets/URS/AssetPipeline/Editor/Processors/ApplyPreset.cs
+++ b/Assets/URS/AssetPipeline/Editor/Processors/ApplyPreset.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using Daihenka.AssetPipeline.Import;
using UnityEditor;
using UnityEditor.Presets;
@@ -26,12 +27,49 @@ public override void OnPostprocess(Object asset, string assetPath)
{
ApplyPresetToSpriteAtlas(asset, assetPath);
}
+
+ public override void OnPostprocessTexture(string assetPath, TextureImporter importer, Texture2D tex)
+ {
+ OnPostprocessTexture(assetPath, importer);
+ }
+
+ public override void OnPostprocessCubemap(string assetPath, TextureImporter importer, Cubemap texture)
+ {
+ OnPostprocessTexture(assetPath, importer);
+ }
public override bool ShouldImport(string assetPath)
{
return IsForceApply(assetPath) || !ImportProfileUserData.HasProcessor(assetPath, this);
}
+ public override bool IsConfigOK(AssetImporter importer)
+ {
+ if (importer == null || preset == null) return false;
+ bool isEqual= DataEquals(preset, importer);
+ if (isEqual)
+ {
+ return true;
+ }
+ else
+ {
+ if (importer is TextureImporter textureImporter)
+ {
+ string androidPlatform = "Android";
+ string iPhonePlatform = "iPhone";
+ bool isAndroidPresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(androidPlatform, preset, textureImporter, out var orignAndroidSetting, out var orignAndroidMaxSize,out var presetAndroidMaxSize);
+ bool isIPhonePresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(iPhonePlatform, preset, textureImporter, out var orignIPhoneSetting, out var orignIPhoneMaxSize, out var presetIPhoneMaxSize);
+ bool androidOk = (!isAndroidPresetOverrider) || (orignAndroidMaxSize <= presetAndroidMaxSize);
+ bool isIPhoneOk = (!isIPhonePresetOverrider) || (orignIPhoneMaxSize <= presetIPhoneMaxSize);
+ return androidOk & isIPhoneOk;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
public override void OnPreprocessAsset(string assetPath, AssetImporter importer)
{
if (preset == null || !preset.CanBeAppliedTo(importer) || !ShouldImport(importer))
@@ -59,8 +97,24 @@ public override void OnPreprocessAsset(string assetPath, AssetImporter importer)
var prevW = widthProp.intValue;
var prevH = heightProp.intValue;
+
+ string androidPlatform = "Android";
+ string iPhonePlatform = "iPhone";
+ bool isAndroidPresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(androidPlatform, preset, textureImporter, out var orignAndroidSetting, out var orignAndroidMaxSize, out var presetAndroidMaxSize);
+ bool isIPhonePresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(iPhonePlatform, preset, textureImporter, out var orignIPhoneSetting, out var orignIPhoneMaxSize, out var presetIPhoneMaxSize);
preset.ApplyTo(importer);
-
+ if (isAndroidPresetOverrider && (orignAndroidMaxSize < presetAndroidMaxSize))
+ {
+ var currentSetting = textureImporter.GetPlatformTextureSettings(androidPlatform);
+ currentSetting.maxTextureSize = orignAndroidMaxSize;
+ textureImporter.SetPlatformTextureSettings(currentSetting);
+ }
+ if (isIPhonePresetOverrider && (orignIPhoneMaxSize < presetIPhoneMaxSize))
+ {
+ var currentSetting = textureImporter.GetPlatformTextureSettings(iPhonePlatform);
+ currentSetting.maxTextureSize = orignIPhoneMaxSize;
+ textureImporter.SetPlatformTextureSettings(currentSetting);
+ }
importerSo.Update();
widthProp.intValue = prevW;
heightProp.intValue = prevH;
@@ -113,11 +167,11 @@ void ApplyPresetToSpriteAtlas(Object asset, string assetPath)
return;
}
- var atlas = (SpriteAtlas) asset;
+ var atlas = (SpriteAtlas)asset;
var isVariant = atlas.isVariant;
var so = new SerializedObject(atlas);
var includeInBuild = so.FindProperty("m_EditorData.bindAsDefault").boolValue;
- var masterAtlas = (SpriteAtlas) so.FindProperty("m_MasterAtlas").objectReferenceValue;
+ var masterAtlas = (SpriteAtlas)so.FindProperty("m_MasterAtlas").objectReferenceValue;
var variantScale = so.FindProperty("m_EditorData.variantMultiplier").floatValue;
var packables = atlas.GetPackables();
preset.ApplyTo(atlas);
@@ -135,5 +189,118 @@ void ApplyPresetToSpriteAtlas(Object asset, string assetPath)
Debug.Log($"[{GetName()}] Preset applied for {assetPath}");
ImportProfileUserData.AddOrUpdateProcessor(assetPath, this);
}
+
+ static bool DataEquals(Preset preset, UnityEngine.Object obj)
+ {
+ if (preset == null || obj == null)
+ return false;
+ var properties = preset.PropertyModifications;
+ var so = new SerializedObject(obj);
+ foreach (var prop in properties)
+ {
+ if (prop.propertyPath == "m_UserData" || prop.propertyPath == "m_PSDShowRemoveMatteOption")
+ continue;
+ var value = so.FindProperty(prop.propertyPath);
+ if (value.GetPropertyValueAsString() != prop.value)
+ return false;
+ }
+
+ return true;
+ }
+ public bool IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(
+ string platform,
+ Preset preset,
+ TextureImporter importer,
+ out TextureImporterPlatformSettings orignSetting,
+ out int orginTextureSize,
+ out int presetTetureSize)
+ {
+ var so = new SerializedObject(importer);
+ SerializedProperty property = so.FindProperty("m_PlatformSettings");
+ string targetPresetPropertyPath = null;
+ bool orignHasOverride = false;
+ int orignMaxTextureSize = 0;
+ for (int i = 0; i < property.arraySize; i++)
+ {
+ SerializedProperty element = property.GetArrayElementAtIndex(i);
+ var buildTarget = element.FindPropertyRelative("m_BuildTarget").stringValue;
+
+ if (buildTarget == platform)
+ {
+ targetPresetPropertyPath = element.propertyPath;
+ orignHasOverride = element.FindPropertyRelative("m_Overridden").boolValue;
+ orignMaxTextureSize = element.FindPropertyRelative("m_MaxTextureSize").intValue;
+ break;
+ }
+
+ }
+ bool presetOverrider = false;
+ int presetMaxTextureSize = 0;
+ if (!string.IsNullOrEmpty(targetPresetPropertyPath))
+ {
+ var modify = preset.PropertyModifications;
+ var presetOverriderPath = $"{targetPresetPropertyPath}.m_Overridden";
+ var presetMaxSizePath = $"{targetPresetPropertyPath}.m_MaxTextureSize";
+ foreach (var proper in modify)
+ {
+ if (proper.propertyPath == presetOverriderPath)
+ {
+ presetOverrider = (proper.value == "1");
+ }
+ else if (proper.propertyPath == presetMaxSizePath)
+ {
+ presetMaxTextureSize = int.Parse(proper.value);
+ }
+ }
+ }
+ //Debug.LogError($"targetPresetPropertyPath {targetPresetPropertyPath} orignHasOverride {orignHasOverride} orignMaxTextureSize {orignMaxTextureSize} presetOverrider {presetOverrider} presetMaxTextureSize {presetMaxTextureSize}");
+
+ orginTextureSize = orignMaxTextureSize;
+ presetTetureSize = presetMaxTextureSize;
+ orignSetting = importer.GetPlatformTextureSettings(platform);
+
+ return presetOverrider;
+ }
+
+ void OnPostprocessTexture(string assetPath, TextureImporter importer)
+ {
+ if (DataEquals(preset, importer))
+ return;
+ string androidPlatform = "Android";
+ string iPhonePlatform = "iPhone";
+ bool isAndroidPresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(
+ androidPlatform,
+ preset,
+ importer ,
+ out var orignAndroidSetting,
+ out var orignAndroidMaxSize,
+ out var presetAndroidMaxSize);
+ bool isIPhonePresetOverrider = IsPresetPlatformTextureMaxSizeIsBiggerThanOrign(
+ iPhonePlatform,
+ preset,
+ importer,
+ out var orignIPhoneSetting,
+ out var orignIPhoneMaxSize,
+ out var presetIPhoneMaxSize);
+
+ if (!preset.ApplyTo(importer))
+ return;
+ if (isAndroidPresetOverrider&& (orignAndroidMaxSize{assetPath}");
+ ImportProfileUserData.AddOrUpdateProcessor(assetPath, this);
+ }
}
}
\ No newline at end of file
diff --git a/Assets/URS/AssetPipeline/Editor/Processors/AssetProcessor.cs b/Assets/URS/AssetPipeline/Editor/Processors/AssetProcessor.cs
index 79ec35d..1b18abf 100644
--- a/Assets/URS/AssetPipeline/Editor/Processors/AssetProcessor.cs
+++ b/Assets/URS/AssetPipeline/Editor/Processors/AssetProcessor.cs
@@ -235,6 +235,24 @@ public virtual void OnPreprocessMaterialDescription(string assetPath, AssetImpor
{
}
+ public virtual bool IsConfigOK(AssetImporter importer)
+ {
+ return true;
+ }
+
+ public virtual bool FireOnEveryImport() {
+
+ return false;
+ }
+
+ public virtual void BeforeImport(string assetpath)
+ {
+
+ }
+ public virtual void AfterImport(string assetpath)
+ {
+
+ }
protected string ReplaceVariables(string input, string assetPath)
{
if (string.IsNullOrEmpty(input))
diff --git a/Assets/URS/AssetPipeline/Editor/Processors/Inspectors/SetTextureFormatInspector.cs b/Assets/URS/AssetPipeline/Editor/Processors/Inspectors/SetTextureFormatInspector.cs
index 8c65ae8..906e5bd 100644
--- a/Assets/URS/AssetPipeline/Editor/Processors/Inspectors/SetTextureFormatInspector.cs
+++ b/Assets/URS/AssetPipeline/Editor/Processors/Inspectors/SetTextureFormatInspector.cs
@@ -8,14 +8,17 @@
using UnityEditorInternal;
using UnityEngine;
using Object = UnityEngine.Object;
+using NinjaBeats;
+using IList = System.Collections.IList;
+using NinjaBeats.ReflectionHelper;
namespace Daihenka.AssetPipeline.Processors
{
[CustomEditor(typeof(SetTextureFormat))]
internal class SetTextureFormatInspector : AssetProcessorInspector
{
- private static dynamic m_DummyEditor;
- private dynamic m_PlatformSettings;
+ private static UnityEditor_TextureImporterInspector s_DummyEditor;
+ private static IList s_PlatformSettings;
private SetTextureFormat m_Target;
private readonly GUIContent GUIContent_defaultPlatform = EditorGUIUtility.TrTextContent("Default");
@@ -29,21 +32,10 @@ protected override void OnEnable()
m_Target.DataToDummy();
- m_DummyEditor ??= Editor.CreateEditor(SetTextureFormat.DummyImporter, UnityEditorDynamic.Type_TextureImporterInspector);
- m_PlatformSettings = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(new[] { UnityEditorDynamic.Type_BaseTextureImportPlatformSettings }));
- var v = Activator.CreateInstance(UnityEditorDynamic.Type_TextureImportPlatformSettings,
- UnityEditorDynamic.TextureImporterInspector.s_DefaultPlatformName, BuildTarget.StandaloneWindows, m_DummyEditor);
- ((IList)m_PlatformSettings).Add((object)v);
- foreach (var buildPlatform in UnityEditorDynamic.Build_BuildPlatforms.instance.GetValidPlatforms())
- {
- var name = (string)UnityEditorDynamic.Reflection_BuildPlatform_name.GetValue((object)buildPlatform);
- var defaultTarget = (BuildTarget)UnityEditorDynamic.Reflection_BuildPlatform_defaultTarget.GetValue((object)buildPlatform);
- var vv = Activator.CreateInstance(UnityEditorDynamic.Type_TextureImportPlatformSettings, name, defaultTarget, m_DummyEditor);
- ((IList)m_PlatformSettings).Add((object)vv);
- }
-
- if (m_DummyEditor != null)
- UnityEditorDynamic.Reflection_TextureImporterInspector_OnEnable.Invoke((object)m_DummyEditor, Array.Empty
- *
- * Note: In some cases, due to the local date processing, this
- * may lead to unexpected results. If you want to stick the normal
- * convention of 1950 to 2049 use the GetAdjustedTime() method.
- */
- public string TimeString
+ public DerUtcTime(DateTime dateTime, int twoDigitYearMax)
+ : base(dateTime, twoDigitYearMax)
{
- get
- {
- //
- // standardise the format.
- //
- if (time.IndexOf('-') < 0 && time.IndexOf('+') < 0)
- {
- if (time.Length == 11)
- {
- return time.Substring(0, 10) + "00GMT+00:00";
- }
- else
- {
- return time.Substring(0, 12) + "GMT+00:00";
- }
- }
- else
- {
- int index = time.IndexOf('-');
- if (index < 0)
- {
- index = time.IndexOf('+');
- }
- string d = time;
-
- if (index == time.Length - 3)
- {
- d += "00";
- }
-
- if (index == 10)
- {
- return d.Substring(0, 10) + "00GMT" + d.Substring(10, 3) + ":" + d.Substring(13, 2);
- }
- else
- {
- return d.Substring(0, 12) + "GMT" + d.Substring(12, 3) + ":" + d.Substring(15, 2);
- }
- }
- }
}
-
- public string AdjustedTime
- {
- get { return AdjustedTimeString; }
- }
-
- ///
- /// Return a time string as an adjusted date with a 4 digit year.
- /// This goes in the range of 1950 - 2049.
- ///
- public string AdjustedTimeString
- {
- get
- {
- string d = TimeString;
- string c = d[0] < '5' ? "20" : "19";
-
- return c + d;
- }
- }
-
- private byte[] GetOctets()
+ internal DerUtcTime(byte[] contents)
+ : base(contents)
{
- return Strings.ToAsciiByteArray(time);
}
- internal override int EncodedLength(bool withID)
+ internal override IAsn1Encoding GetEncoding(int encoding)
{
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, time.Length);
+ return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.UtcTime,
+ GetContents(Asn1OutputStream.EncodingDer));
}
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
{
- asn1Out.WriteEncodingDL(withID, Asn1Tags.UtcTime, GetOctets());
- }
-
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
- {
- DerUtcTime other = asn1Object as DerUtcTime;
-
- if (other == null)
- return false;
-
- return this.time.Equals(other.time);
- }
-
- protected override int Asn1GetHashCode()
- {
- return time.GetHashCode();
+ return new PrimitiveEncoding(tagClass, tagNo, GetContents(Asn1OutputStream.EncodingDer));
}
-
- public override string ToString()
- {
- return time;
- }
- }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUTF8String.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUTF8String.cs
index 6e9a9f6..55da1bd 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUTF8String.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUTF8String.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Text;
+using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -13,92 +13,114 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
public class DerUtf8String
: DerStringBase
{
- private readonly string str;
+ internal class Meta : Asn1UniversalType
+ {
+ internal static readonly Asn1UniversalType Instance = new Meta();
+
+ private Meta() : base(typeof(DerUtf8String), Asn1Tags.Utf8String) {}
+
+ internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString)
+ {
+ return CreatePrimitive(octetString.GetOctets());
+ }
+ }
/**
* return an UTF8 string from the passed in object.
*
* @exception ArgumentException if the object cannot be converted.
*/
- public static DerUtf8String GetInstance(
- object obj)
+ public static DerUtf8String GetInstance(object obj)
{
- if (obj == null || obj is DerUtf8String)
+ if (obj == null)
+ return null;
+
+ if (obj is DerUtf8String derUtf8String)
+ return derUtf8String;
+
+ if (obj is IAsn1Convertible asn1Convertible)
+ {
+ Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+ if (asn1Object is DerUtf8String converted)
+ return converted;
+ }
+ else if (obj is byte[] bytes)
{
- return (DerUtf8String)obj;
+ try
+ {
+ return (DerUtf8String)Meta.Instance.FromByteArray(bytes);
+ }
+ catch (IOException e)
+ {
+ throw new ArgumentException("failed to construct UTF8 string from byte[]: " + e.Message);
+ }
}
- throw new ArgumentException("illegal object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("illegal object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
/**
- * return an UTF8 string from a tagged object.
+ * return a UTF8 string from a tagged object.
*
- * @param obj the tagged object holding the object we want
- * @param explicitly true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception ArgumentException if the tagged object cannot
- * be converted.
+ * @param taggedObject the tagged object holding the object we want
+ * @param declaredExplicit true if the object is meant to be explicitly tagged false otherwise.
+ * @exception ArgumentException if the tagged object cannot be converted.
*/
- public static DerUtf8String GetInstance(
- Asn1TaggedObject obj,
- bool isExplicit)
+ public static DerUtf8String GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- Asn1Object o = obj.GetObject();
+ return (DerUtf8String)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
+ }
- if (isExplicit || o is DerUtf8String)
- {
- return GetInstance(o);
- }
+ private readonly byte[] m_contents;
- return new DerUtf8String(Asn1OctetString.GetInstance(o).GetOctets());
+ public DerUtf8String(string str)
+ : this(Strings.ToUtf8ByteArray(str), false)
+ {
}
- /**
- * basic constructor - byte encoded string.
- */
- public DerUtf8String(
- byte[] str)
- : this(Encoding.UTF8.GetString(str, 0, str.Length))
+ public DerUtf8String(byte[] contents)
+ : this(contents, true)
{
}
- /**
- * basic constructor
- */
- public DerUtf8String(
- string str)
+ internal DerUtf8String(byte[] contents, bool clone)
{
- if (str == null)
- throw new ArgumentNullException("str");
+ if (null == contents)
+ throw new ArgumentNullException("contents");
- this.str = str;
+ m_contents = clone ? Arrays.Clone(contents) : contents;
}
- public override string GetString()
+ public override string GetString()
{
- return str;
+ return Strings.FromUtf8ByteArray(m_contents);
}
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
+ protected override bool Asn1Equals(Asn1Object asn1Object)
{
- DerUtf8String other = asn1Object as DerUtf8String;
+ DerUtf8String that = asn1Object as DerUtf8String;
+ return null != that
+ && Arrays.AreEqual(this.m_contents, that.m_contents);
+ }
- if (other == null)
- return false;
+ protected override int Asn1GetHashCode()
+ {
+ return Arrays.GetHashCode(m_contents);
+ }
- return this.str.Equals(other.str);
+ internal override IAsn1Encoding GetEncoding(int encoding)
+ {
+ return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.Utf8String, m_contents);
}
- internal override int EncodedLength(bool withID)
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
{
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, Encoding.UTF8.GetByteCount(str));
+ return new PrimitiveEncoding(tagClass, tagNo, m_contents);
}
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
+ internal static DerUtf8String CreatePrimitive(byte[] contents)
{
- asn1Out.WriteEncodingDL(withID, Asn1Tags.Utf8String, Encoding.UTF8.GetBytes(str));
+ return new DerUtf8String(contents, false);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUniversalString.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUniversalString.cs
index a1a19f9..4952841 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUniversalString.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerUniversalString.cs
@@ -1,6 +1,8 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.Diagnostics;
+using System.IO;
using System.Text;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -8,106 +10,166 @@
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
{
/**
- * Der UniversalString object.
+ * UniversalString object.
*/
public class DerUniversalString
: DerStringBase
{
- private static readonly char[] table = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+ internal class Meta : Asn1UniversalType
+ {
+ internal static readonly Asn1UniversalType Instance = new Meta();
+
+ private Meta() : base(typeof(DerUniversalString), Asn1Tags.UniversalString) {}
+
+ internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString)
+ {
+ return CreatePrimitive(octetString.GetOctets());
+ }
+ }
- private readonly byte[] str;
+ private static readonly char[] table = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/**
- * return a Universal string from the passed in object.
+ * return a universal string from the passed in object.
*
* @exception ArgumentException if the object cannot be converted.
*/
- public static DerUniversalString GetInstance(
- object obj)
+ public static DerUniversalString GetInstance(object obj)
{
- if (obj == null || obj is DerUniversalString)
+ if (obj == null)
+ return null;
+
+ if (obj is DerUniversalString derUniversalString)
+ return derUniversalString;
+
+ if (obj is IAsn1Convertible asn1Convertible)
{
- return (DerUniversalString)obj;
+ Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+ if (asn1Object is DerUniversalString converted)
+ return converted;
+ }
+ else if (obj is byte[] bytes)
+ {
+ try
+ {
+ return (DerUniversalString)Meta.Instance.FromByteArray(bytes);
+ }
+ catch (IOException e)
+ {
+ throw new ArgumentException("failed to construct universal string from byte[]: " + e.Message);
+ }
}
- throw new ArgumentException("illegal object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("illegal object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
/**
- * return a Universal string from a tagged object.
+ * return a universal string from a tagged object.
*
- * @param obj the tagged object holding the object we want
- * @param explicitly true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception ArgumentException if the tagged object cannot
- * be converted.
+ * @param taggedObject the tagged object holding the object we want
+ * @param declaredExplicit true if the object is meant to be explicitly tagged false otherwise.
+ * @exception ArgumentException if the tagged object cannot be converted.
*/
- public static DerUniversalString GetInstance(
- Asn1TaggedObject obj,
- bool isExplicit)
+ public static DerUniversalString GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- Asn1Object o = obj.GetObject();
+ return (DerUniversalString)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
+ }
- if (isExplicit || o is DerUniversalString)
- {
- return GetInstance(o);
- }
+ private readonly byte[] m_contents;
- return new DerUniversalString(Asn1OctetString.GetInstance(o).GetOctets());
+ public DerUniversalString(byte[] contents)
+ : this(contents, true)
+ {
}
- /**
- * basic constructor - byte encoded string.
- */
- public DerUniversalString(
- byte[] str)
+ internal DerUniversalString(byte[] contents, bool clone)
{
- if (str == null)
- throw new ArgumentNullException("str");
+ if (null == contents)
+ throw new ArgumentNullException("contents");
- this.str = str;
+ m_contents = clone ? Arrays.Clone(contents) : contents;
}
public override string GetString()
{
- StringBuilder buffer = new StringBuilder("#");
- byte[] enc = GetDerEncoded();
+ int dl = m_contents.Length;
+ int capacity = 3 + 2 * (Asn1OutputStream.GetLengthOfDL(dl) + dl);
+ StringBuilder buf = new StringBuilder("#1C", capacity);
+ EncodeHexDL(buf, dl);
- for (int i = 0; i != enc.Length; i++)
- {
- uint ubyte = enc[i];
- buffer.Append(table[(ubyte >> 4) & 0xf]);
- buffer.Append(table[enc[i] & 0xf]);
- }
+ for (int i = 0; i < dl; ++i)
+ {
+ EncodeHexByte(buf, m_contents[i]);
+ }
- return buffer.ToString();
+ Debug.Assert(buf.Length == capacity);
+ return buf.ToString();
}
- public byte[] GetOctets()
+ public byte[] GetOctets()
{
- return (byte[]) str.Clone();
+ return Arrays.Clone(m_contents);
}
- internal override int EncodedLength(bool withID)
+ internal override IAsn1Encoding GetEncoding(int encoding)
{
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, this.str.Length);
+ return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.UniversalString, m_contents);
}
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
{
- asn1Out.WriteEncodingDL(withID, Asn1Tags.UniversalString, this.str);
+ return new PrimitiveEncoding(tagClass, tagNo, m_contents);
}
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
- {
- DerUniversalString other = asn1Object as DerUniversalString;
+ protected override bool Asn1Equals(Asn1Object asn1Object)
+ {
+ DerUniversalString that = asn1Object as DerUniversalString;
+ return null != that
+ && Arrays.AreEqual(this.m_contents, that.m_contents);
+ }
- if (other == null)
- return false;
+ protected override int Asn1GetHashCode()
+ {
+ return Arrays.GetHashCode(m_contents);
+ }
+
+ internal static DerUniversalString CreatePrimitive(byte[] contents)
+ {
+ return new DerUniversalString(contents, false);
+ }
-// return this.GetString().Equals(other.GetString());
- return Arrays.AreEqual(this.str, other.str);
+ private static void EncodeHexByte(StringBuilder buf, int i)
+ {
+ buf.Append(table[(i >> 4) & 0xF]);
+ buf.Append(table[i & 0xF]);
+ }
+
+ private static void EncodeHexDL(StringBuilder buf, int dl)
+ {
+ if (dl < 128)
+ {
+ EncodeHexByte(buf, dl);
+ return;
+ }
+
+ byte[] stack = new byte[5];
+ int pos = 5;
+
+ do
+ {
+ stack[--pos] = (byte)dl;
+ dl >>= 8;
+ }
+ while (dl != 0);
+
+ int count = stack.Length - pos;
+ stack[--pos] = (byte)(0x80 | count);
+
+ do
+ {
+ EncodeHexByte(buf, stack[pos++]);
+ }
+ while (pos < stack.Length);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVideotexString.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVideotexString.cs
index d55b304..b1e5d9a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVideotexString.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVideotexString.cs
@@ -1,6 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -9,10 +10,20 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
public class DerVideotexString
: DerStringBase
{
- private readonly byte[] mString;
+ internal class Meta : Asn1UniversalType
+ {
+ internal static readonly Asn1UniversalType Instance = new Meta();
+
+ private Meta() : base(typeof(DerVideotexString), Asn1Tags.VideotexString) {}
+
+ internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString)
+ {
+ return CreatePrimitive(octetString.GetOctets());
+ }
+ }
/**
- * return a Videotex String from the passed in object
+ * return a videotex string from the passed in object
*
* @param obj a DERVideotexString or an object that can be converted into one.
* @exception IllegalArgumentException if the object cannot be converted.
@@ -20,91 +31,96 @@ public class DerVideotexString
*/
public static DerVideotexString GetInstance(object obj)
{
- if (obj == null || obj is DerVideotexString)
+ if (obj == null)
+ return null;
+
+ if (obj is DerVideotexString derVideotexString)
+ return derVideotexString;
+
+ if (obj is IAsn1Convertible asn1Convertible)
{
- return (DerVideotexString)obj;
+ Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+ if (asn1Object is DerVideotexString converted)
+ return converted;
}
-
- if (obj is byte[])
+ else if (obj is byte[] bytes)
{
try
{
- return (DerVideotexString)FromByteArray((byte[])obj);
+ return (DerVideotexString)Meta.Instance.FromByteArray(bytes);
}
- catch (Exception e)
+ catch (IOException e)
{
- throw new ArgumentException("encoding error in GetInstance: " + e.ToString(), "obj");
+ throw new ArgumentException("failed to construct videotex string from byte[]: " + e.Message);
}
}
- throw new ArgumentException("illegal object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("illegal object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
- * return a Videotex String from a tagged object.
+ * return a videotex string from a tagged object.
*
- * @param obj the tagged object holding the object we want
- * @param explicit true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception IllegalArgumentException if the tagged object cannot
- * be converted.
+ * @param taggedObject the tagged object holding the object we want
+ * @param declaredExplicit true if the object is meant to be explicitly tagged false otherwise.
+ * @exception IllegalArgumentException if the tagged object cannot be converted.
* @return a DERVideotexString instance, or null.
*/
- public static DerVideotexString GetInstance(Asn1TaggedObject obj, bool isExplicit)
+ public static DerVideotexString GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- Asn1Object o = obj.GetObject();
+ return (DerVideotexString)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
+ }
- if (isExplicit || o is DerVideotexString)
- {
- return GetInstance(o);
- }
+ private readonly byte[] m_contents;
- return new DerVideotexString(((Asn1OctetString)o).GetOctets());
+ public DerVideotexString(byte[] contents)
+ : this(contents, true)
+ {
}
- /**
- * basic constructor - with bytes.
- * @param string the byte encoding of the characters making up the string.
- */
- public DerVideotexString(byte[] encoding)
+ internal DerVideotexString(byte[] contents, bool clone)
{
- this.mString = Arrays.Clone(encoding);
+ if (null == contents)
+ throw new ArgumentNullException("contents");
+
+ m_contents = clone ? Arrays.Clone(contents) : contents;
}
public override string GetString()
{
- return Strings.FromByteArray(mString);
+ return Strings.FromByteArray(m_contents);
}
public byte[] GetOctets()
{
- return Arrays.Clone(mString);
+ return Arrays.Clone(m_contents);
}
- internal override int EncodedLength(bool withID)
+ internal override IAsn1Encoding GetEncoding(int encoding)
{
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, mString.Length);
+ return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.VideotexString, m_contents);
}
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
{
- asn1Out.WriteEncodingDL(withID, Asn1Tags.VideotexString, mString);
+ return new PrimitiveEncoding(tagClass, tagNo, m_contents);
}
- protected override int Asn1GetHashCode()
- {
- return Arrays.GetHashCode(mString);
+ protected override bool Asn1Equals(Asn1Object asn1Object)
+ {
+ DerVideotexString that = asn1Object as DerVideotexString;
+ return null != that
+ && Arrays.AreEqual(this.m_contents, that.m_contents);
}
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
+ protected override int Asn1GetHashCode()
{
- DerVideotexString other = asn1Object as DerVideotexString;
-
- if (other == null)
- return false;
+ return Arrays.GetHashCode(m_contents);
+ }
- return Arrays.AreEqual(mString, other.mString);
+ internal static DerVideotexString CreatePrimitive(byte[] contents)
+ {
+ return new DerVideotexString(contents, false);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVisibleString.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVisibleString.cs
index 231dba1..ed1a6c0 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVisibleString.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/DerVisibleString.cs
@@ -1,117 +1,134 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Text;
+using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
{
/**
- * Der VisibleString object.
+ * VisibleString object.
*/
public class DerVisibleString
: DerStringBase
{
- private readonly string str;
+ internal class Meta : Asn1UniversalType
+ {
+ internal static readonly Asn1UniversalType Instance = new Meta();
+
+ private Meta() : base(typeof(DerVisibleString), Asn1Tags.VisibleString) {}
+
+ internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString)
+ {
+ return CreatePrimitive(octetString.GetOctets());
+ }
+ }
/**
- * return a Visible string from the passed in object.
+ * return a visible string from the passed in object.
*
* @exception ArgumentException if the object cannot be converted.
*/
- public static DerVisibleString GetInstance(
- object obj)
+ public static DerVisibleString GetInstance(object obj)
{
- if (obj == null || obj is DerVisibleString)
- {
- return (DerVisibleString)obj;
- }
+ if (obj == null)
+ return null;
+
+ if (obj is DerVisibleString derVisibleString)
+ return derVisibleString;
- if (obj is Asn1OctetString)
+ if (obj is IAsn1Convertible asn1Convertible)
{
- return new DerVisibleString(((Asn1OctetString)obj).GetOctets());
+ Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+ if (asn1Object is DerVisibleString converted)
+ return converted;
}
-
- if (obj is Asn1TaggedObject)
+ else if (obj is byte[] bytes)
{
- return GetInstance(((Asn1TaggedObject)obj).GetObject());
+ try
+ {
+ return (DerVisibleString)Meta.Instance.FromByteArray(bytes);
+ }
+ catch (IOException e)
+ {
+ throw new ArgumentException("failed to construct visible string from byte[]: " + e.Message);
+ }
}
- throw new ArgumentException("illegal object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("illegal object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
/**
- * return a Visible string from a tagged object.
+ * return a visible string from a tagged object.
*
- * @param obj the tagged object holding the object we want
- * @param explicitly true if the object is meant to be explicitly
- * tagged false otherwise.
- * @exception ArgumentException if the tagged object cannot
- * be converted.
+ * @param taggedObject the tagged object holding the object we want
+ * @param declaredExplicit true if the object is meant to be explicitly tagged false otherwise.
+ * @exception ArgumentException if the tagged object cannot be converted.
*/
- public static DerVisibleString GetInstance(
- Asn1TaggedObject obj,
- bool explicitly)
+ public static DerVisibleString GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- return GetInstance(obj.GetObject());
+ return (DerVisibleString)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit);
}
- /**
- * basic constructor - byte encoded string.
- */
- public DerVisibleString(
- byte[] str)
- : this(Strings.FromAsciiByteArray(str))
- {
- }
+ private readonly byte[] m_contents;
- /**
- * basic constructor
- */
- public DerVisibleString(
- string str)
+ public DerVisibleString(string str)
{
if (str == null)
throw new ArgumentNullException("str");
- this.str = str;
+ m_contents = Strings.ToAsciiByteArray(str);
}
- public override string GetString()
+ public DerVisibleString(byte[] contents)
+ : this(contents, true)
{
- return str;
}
- public byte[] GetOctets()
+ internal DerVisibleString(byte[] contents, bool clone)
{
- return Strings.ToAsciiByteArray(str);
+ if (null == contents)
+ throw new ArgumentNullException("contents");
+
+ m_contents = clone ? Arrays.Clone(contents) : contents;
}
- internal override int EncodedLength(bool withID)
+ public override string GetString()
{
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, str.Length);
+ return Strings.FromAsciiByteArray(m_contents);
}
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
+ public byte[] GetOctets()
{
- asn1Out.WriteEncodingDL(withID, Asn1Tags.VisibleString, GetOctets());
+ return Arrays.Clone(m_contents);
}
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
- {
- DerVisibleString other = asn1Object as DerVisibleString;
+ internal override IAsn1Encoding GetEncoding(int encoding)
+ {
+ return new PrimitiveEncoding(Asn1Tags.Universal, Asn1Tags.VisibleString, m_contents);
+ }
- if (other == null)
- return false;
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
+ {
+ return new PrimitiveEncoding(tagClass, tagNo, m_contents);
+ }
+
+ protected override bool Asn1Equals(Asn1Object asn1Object)
+ {
+ DerVisibleString that = asn1Object as DerVisibleString;
+ return null != that
+ && Arrays.AreEqual(this.m_contents, that.m_contents);
+ }
- return this.str.Equals(other.str);
+ protected override int Asn1GetHashCode()
+ {
+ return Arrays.GetHashCode(m_contents);
}
- protected override int Asn1GetHashCode()
- {
- return this.str.GetHashCode();
+ internal static DerVisibleString CreatePrimitive(byte[] contents)
+ {
+ return new DerVisibleString(contents, false);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs
new file mode 100644
index 0000000..55e0466
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs
@@ -0,0 +1,15 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal interface IAsn1Encoding
+ {
+ void Encode(Asn1OutputStream asn1Out);
+
+ int GetLength();
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs.meta
new file mode 100644
index 0000000..164a391
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IAsn1Encoding.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 949eb025ceb7cc645baca227261703ac
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IndefiniteLengthInputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IndefiniteLengthInputStream.cs
index 991d6f8..49db125 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IndefiniteLengthInputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/IndefiniteLengthInputStream.cs
@@ -11,61 +11,47 @@ class IndefiniteLengthInputStream
private int _lookAhead;
private bool _eofOn00 = true;
- internal IndefiniteLengthInputStream(
- Stream inStream,
- int limit)
+ internal IndefiniteLengthInputStream(Stream inStream, int limit)
: base(inStream, limit)
{
_lookAhead = RequireByte();
- CheckForEof();
- }
- internal void SetEofOn00(
- bool eofOn00)
- {
- _eofOn00 = eofOn00;
- if (_eofOn00)
+ if (0 == _lookAhead)
{
- CheckForEof();
+ CheckEndOfContents();
}
}
- private bool CheckForEof()
+ internal void SetEofOn00(bool eofOn00)
{
- if (_lookAhead == 0x00)
+ _eofOn00 = eofOn00;
+ if (_eofOn00 && 0 == _lookAhead)
{
- int extra = RequireByte();
- if (extra != 0)
- {
- throw new IOException("malformed end-of-contents marker");
- }
-
- _lookAhead = -1;
- SetParentEofDetect(true);
- return true;
+ CheckEndOfContents();
}
- return _lookAhead < 0;
}
- public override int Read(
- byte[] buffer,
- int offset,
- int count)
- {
- // Only use this optimisation if we aren't checking for 00
- if (_eofOn00 || count <= 1)
+ private void CheckEndOfContents()
+ {
+ if (0 != RequireByte())
+ throw new IOException("malformed end-of-contents marker");
+
+ _lookAhead = -1;
+ SetParentEofDetect();
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ // Only use this optimisation if we aren't checking for 00
+ if (_eofOn00 || count <= 1)
return base.Read(buffer, offset, count);
if (_lookAhead < 0)
return 0;
int numRead = _in.Read(buffer, offset + 1, count - 1);
-
if (numRead <= 0)
- {
- // Corrupted stream
throw new EndOfStreamException();
- }
buffer[offset] = (byte)_lookAhead;
_lookAhead = RequireByte();
@@ -73,10 +59,37 @@ public override int Read(
return numRead + 1;
}
- public override int ReadByte()
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override int Read(Span buffer)
+ {
+ // Only use this optimisation if we aren't checking for 00
+ if (_eofOn00 || buffer.Length <= 1)
+ return base.Read(buffer);
+
+ if (_lookAhead < 0)
+ return 0;
+
+ int numRead = _in.Read(buffer[1..]);
+ if (numRead <= 0)
+ throw new EndOfStreamException();
+
+ buffer[0] = (byte)_lookAhead;
+ _lookAhead = RequireByte();
+
+ return numRead + 1;
+ }
+#endif
+
+ public override int ReadByte()
{
- if (_eofOn00 && CheckForEof())
- return -1;
+ if (_eofOn00 && _lookAhead <= 0)
+ {
+ if (0 == _lookAhead)
+ {
+ CheckEndOfContents();
+ }
+ return -1;
+ }
int result = _lookAhead;
_lookAhead = RequireByte();
@@ -87,88 +100,11 @@ private int RequireByte()
{
int b = _in.ReadByte();
if (b < 0)
- {
- // Corrupted stream
throw new EndOfStreamException();
- }
+
return b;
}
}
}
-
-//using System;
-//using System.IO;
-
-//namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
-//{
-// class IndefiniteLengthInputStream
-// : LimitedInputStream
-// {
-// private bool _eofReached = false;
-// private bool _eofOn00 = true;
-
-// internal IndefiniteLengthInputStream(
-// Stream inStream,
-// int limit)
-// : base(inStream, limit)
-// {
-// }
-
-// internal void SetEofOn00(
-// bool eofOn00)
-// {
-// _eofOn00 = eofOn00;
-// }
-
-// public override int Read(
-// byte[] buffer,
-// int offset,
-// int count)
-// {
-// if (_eofReached)
-// return 0;
-
-// if (_eofOn00)
-// return base.Read(buffer, offset, count);
-
-// int numRead = _in.Read(buffer, offset, count);
-
-// if (numRead <= 0)
-// throw new EndOfStreamException();
-
-// return numRead;
-// }
-
-// public override int ReadByte()
-// {
-// if (_eofReached)
-// return -1;
-
-// int b1 = _in.ReadByte();
-
-// if (b1 < 0)
-// throw new EndOfStreamException();
-
-// if (b1 == 0 && _eofOn00)
-// {
-// int b2 = _in.ReadByte();
-
-// if (b2 < 0)
-// throw new EndOfStreamException();
-
-// if (b2 == 0)
-// {
-// _eofReached = true;
-// SetParentEofDetect(true);
-// return -1;
-// }
-
-// throw new InvalidDataException();
-// }
-
-// return b1;
-// }
-// }
-//}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyASN1InputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyASN1InputStream.cs
index dd088a2..b3e32cc 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyASN1InputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyASN1InputStream.cs
@@ -8,14 +8,12 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
public class LazyAsn1InputStream
: Asn1InputStream
{
- public LazyAsn1InputStream(
- byte[] input)
+ public LazyAsn1InputStream(byte[] input)
: base(input)
{
}
- public LazyAsn1InputStream(
- Stream inputStream)
+ public LazyAsn1InputStream(Stream inputStream)
: base(inputStream)
{
}
@@ -25,16 +23,14 @@ internal LazyAsn1InputStream(Stream input, int limit, byte[][] tmpBuffers)
{
}
- internal override DerSequence CreateDerSequence(
- DefiniteLengthInputStream dIn)
+ internal override Asn1Sequence CreateDLSequence(DefiniteLengthInputStream defIn)
{
- return new LazyDerSequence(dIn.ToArray());
+ return new LazyDLSequence(defIn.ToArray());
}
- internal override DerSet CreateDerSet(
- DefiniteLengthInputStream dIn)
+ internal override Asn1Set CreateDLSet(DefiniteLengthInputStream defIn)
{
- return new LazyDerSet(dIn.ToArray());
+ return new LazyDLSet(defIn.ToArray());
}
internal override Asn1EncodableVector ReadVector(DefiniteLengthInputStream defIn)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs
index bf784a7..0454b34 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs
@@ -1,96 +1,3 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
-#pragma warning disable
-using System;
-using System.Collections;
-namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
-{
- internal class LazyDerSequence
- : DerSequence
- {
- private byte[] encoded;
-
- internal LazyDerSequence(byte[] encoded)
- : base()
- {
- if (null == encoded)
- throw new ArgumentNullException("encoded");
-
- this.encoded = encoded;
- }
-
- private void Parse()
- {
- lock (this)
- {
- if (null != encoded)
- {
- Asn1InputStream e = new LazyAsn1InputStream(encoded);
- Asn1EncodableVector v = e.ReadVector();
-
- this.elements = v.TakeElements();
- this.encoded = null;
- }
- }
- }
-
- public override Asn1Encodable this[int index]
- {
- get
- {
- Parse();
-
- return base[index];
- }
- }
-
- public override IEnumerator GetEnumerator()
- {
- Parse();
-
- return base.GetEnumerator();
- }
-
- public override int Count
- {
- get
- {
- Parse();
-
- return base.Count;
- }
- }
-
- internal override int EncodedLength(bool withID)
- {
- lock (this)
- {
- if (encoded == null)
- {
- return base.EncodedLength(withID);
- }
- else
- {
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, encoded.Length);
- }
- }
- }
-
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
- {
- lock (this)
- {
- if (encoded == null)
- {
- base.Encode(asn1Out, withID);
- }
- else
- {
- asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | Asn1Tags.Sequence, encoded);
- }
- }
- }
- }
-}
-#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs.meta
index e266c26..db7f567 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs.meta
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSequence.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 05b54ca5e1058684db4f666dfd635913
+guid: cbdd39fdc49876048aef91ae0de8ced9
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs
index 596a93c..0454b34 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs
@@ -1,96 +1,3 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
-#pragma warning disable
-using System;
-using System.Collections;
-namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
-{
- internal class LazyDerSet
- : DerSet
- {
- private byte[] encoded;
-
- internal LazyDerSet(byte[] encoded)
- : base()
- {
- if (null == encoded)
- throw new ArgumentNullException("encoded");
-
- this.encoded = encoded;
- }
-
- private void Parse()
- {
- lock (this)
- {
- if (encoded != null)
- {
- Asn1InputStream e = new LazyAsn1InputStream(encoded);
- Asn1EncodableVector v = e.ReadVector();
-
- this.elements = v.TakeElements();
- this.encoded = null;
- }
- }
- }
-
- public override Asn1Encodable this[int index]
- {
- get
- {
- Parse();
-
- return base[index];
- }
- }
-
- public override IEnumerator GetEnumerator()
- {
- Parse();
-
- return base.GetEnumerator();
- }
-
- public override int Count
- {
- get
- {
- Parse();
-
- return base.Count;
- }
- }
-
- internal override int EncodedLength(bool withID)
- {
- lock (this)
- {
- if (encoded == null)
- {
- return base.EncodedLength(withID);
- }
- else
- {
- return Asn1OutputStream.GetLengthOfEncodingDL(withID, encoded.Length);
- }
- }
- }
-
- internal override void Encode(Asn1OutputStream asn1Out, bool withID)
- {
- lock (this)
- {
- if (encoded == null)
- {
- base.Encode(asn1Out, withID);
- }
- else
- {
- asn1Out.WriteEncodingDL(withID, Asn1Tags.Constructed | Asn1Tags.Set, encoded);
- }
- }
- }
- }
-}
-#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs.meta
index 25ae00b..0c29184 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs.meta
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDERSet.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 76bf92893e66b884594d31a9693939d6
+guid: 8cc1ad753f557e943a6a5397371c9680
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs
new file mode 100644
index 0000000..9408820
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs
@@ -0,0 +1,69 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal class LazyDLEnumerator
+ : IEnumerator
+ {
+ private readonly byte[] m_contents;
+
+ private Asn1InputStream m_input;
+ private Asn1Object m_current;
+
+ internal LazyDLEnumerator(byte[] contents)
+ {
+ this.m_contents = contents;
+
+ Reset();
+ }
+
+ object System.Collections.IEnumerator.Current
+ {
+ get { return Current; }
+ }
+
+ public Asn1Encodable Current
+ {
+ get
+ {
+ if (null == m_current)
+ throw new InvalidOperationException();
+
+ return m_current;
+ }
+ }
+
+ public virtual void Dispose()
+ {
+ }
+
+ public bool MoveNext()
+ {
+ return null != (this.m_current = ReadObject());
+ }
+
+ public void Reset()
+ {
+ this.m_input = new LazyAsn1InputStream(m_contents);
+ this.m_current = null;
+ }
+
+ private Asn1Object ReadObject()
+ {
+ try
+ {
+ return m_input.ReadObject();
+ }
+ catch (IOException e)
+ {
+ throw new Asn1ParsingException("malformed ASN.1: " + e.Message, e);
+ }
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs.meta
new file mode 100644
index 0000000..49d5be0
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLEnumerator.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e013eba2cec788241b17adad97d20283
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs
new file mode 100644
index 0000000..60e20af
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs
@@ -0,0 +1,129 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal class LazyDLSequence
+ : DLSequence
+ {
+ private byte[] encoded;
+
+ internal LazyDLSequence(byte[] encoded)
+ : base()
+ {
+ if (null == encoded)
+ throw new ArgumentNullException("encoded");
+
+ this.encoded = encoded;
+ }
+
+ public override Asn1Encodable this[int index]
+ {
+ get
+ {
+ Force();
+
+ return base[index];
+ }
+ }
+
+ public override IEnumerator GetEnumerator()
+ {
+ byte[] encoded = GetContents();
+ if (null != encoded)
+ {
+ return new LazyDLEnumerator(encoded);
+ }
+
+ return base.GetEnumerator();
+ }
+
+ public override int Count
+ {
+ get
+ {
+ Force();
+
+ return base.Count;
+ }
+ }
+
+ public override Asn1Encodable[] ToArray()
+ {
+ Force();
+
+ return base.ToArray();
+ }
+
+ public override string ToString()
+ {
+ Force();
+
+ return base.ToString();
+ }
+
+ internal override IAsn1Encoding GetEncoding(int encoding)
+ {
+ if (Asn1OutputStream.EncodingBer == encoding)
+ {
+ byte[] encoded = GetContents();
+ if (encoded != null)
+ return new ConstructedLazyDLEncoding(Asn1Tags.Universal, Asn1Tags.Sequence, encoded);
+ }
+ else
+ {
+ Force();
+ }
+
+ return base.GetEncoding(encoding);
+ }
+
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
+ {
+ if (Asn1OutputStream.EncodingBer == encoding)
+ {
+ byte[] encoded = GetContents();
+ if (encoded != null)
+ return new ConstructedLazyDLEncoding(tagClass, tagNo, encoded);
+ }
+ else
+ {
+ Force();
+ }
+
+ return base.GetEncodingImplicit(encoding, tagClass, tagNo);
+ }
+
+ private void Force()
+ {
+ lock (this)
+ {
+ if (null != encoded)
+ {
+ Asn1InputStream input = new LazyAsn1InputStream(encoded);
+ try
+ {
+ Asn1EncodableVector v = input.ReadVector();
+
+ this.elements = v.TakeElements();
+ this.encoded = null;
+ }
+ catch (IOException e)
+ {
+ throw new Asn1ParsingException("malformed ASN.1: " + e.Message, e);
+ }
+ }
+ }
+ }
+
+ private byte[] GetContents()
+ {
+ lock (this) return encoded;
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs.meta
new file mode 100644
index 0000000..c46d40c
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSequence.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7f4a719db5e2c874eb236ba3f734acca
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs
new file mode 100644
index 0000000..fe5de4c
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs
@@ -0,0 +1,128 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal class LazyDLSet
+ : DLSet
+ {
+ private byte[] encoded;
+
+ internal LazyDLSet(byte[] encoded)
+ : base()
+ {
+ if (null == encoded)
+ throw new ArgumentNullException("encoded");
+
+ this.encoded = encoded;
+ }
+
+ public override Asn1Encodable this[int index]
+ {
+ get
+ {
+ Force();
+
+ return base[index];
+ }
+ }
+
+ public override IEnumerator GetEnumerator()
+ {
+ byte[] encoded = GetContents();
+ if (null != encoded)
+ return new LazyDLEnumerator(encoded);
+
+ return base.GetEnumerator();
+ }
+
+ public override int Count
+ {
+ get
+ {
+ Force();
+
+ return base.Count;
+ }
+ }
+
+ public override Asn1Encodable[] ToArray()
+ {
+ Force();
+
+ return base.ToArray();
+ }
+
+ public override string ToString()
+ {
+ Force();
+
+ return base.ToString();
+ }
+
+ internal override IAsn1Encoding GetEncoding(int encoding)
+ {
+ if (Asn1OutputStream.EncodingBer == encoding)
+ {
+ byte[] encoded = GetContents();
+ if (null != encoded)
+ return new ConstructedLazyDLEncoding(Asn1Tags.Universal, Asn1Tags.Set, encoded);
+ }
+ else
+ {
+ Force();
+ }
+
+ return base.GetEncoding(encoding);
+ }
+
+ internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
+ {
+ if (Asn1OutputStream.EncodingBer == encoding)
+ {
+ byte[] encoded = GetContents();
+ if (null != encoded)
+ return new ConstructedLazyDLEncoding(tagClass, tagNo, encoded);
+ }
+ else
+ {
+ Force();
+ }
+
+ return base.GetEncodingImplicit(encoding, tagClass, tagNo);
+ }
+
+ private void Force()
+ {
+ lock (this)
+ {
+ if (null != encoded)
+ {
+ Asn1InputStream input = new LazyAsn1InputStream(encoded);
+ try
+ {
+ Asn1EncodableVector v = input.ReadVector();
+
+ this.elements = v.TakeElements();
+ this.isSorted = elements.Length < 2;
+ this.encoded = null;
+ }
+ catch (IOException e)
+ {
+ throw new Asn1ParsingException("malformed ASN.1: " + e.Message, e);
+ }
+ }
+ }
+ }
+
+ private byte[] GetContents()
+ {
+ lock (this) return encoded;
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs.meta
new file mode 100644
index 0000000..1d4592c
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LazyDLSet.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b2a69dabb4519d84a9de7f3158fe1588
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LimitedInputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LimitedInputStream.cs
index f97cd24..9e4dd13 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LimitedInputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/LimitedInputStream.cs
@@ -23,11 +23,11 @@ internal virtual int Limit
get { return _limit; }
}
- protected virtual void SetParentEofDetect(bool on)
+ protected void SetParentEofDetect()
{
if (_in is IndefiniteLengthInputStream)
{
- ((IndefiniteLengthInputStream)_in).SetEofOn00(on);
+ ((IndefiniteLengthInputStream)_in).SetEofOn00(true);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs
new file mode 100644
index 0000000..9bdd08b
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs
@@ -0,0 +1,37 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal class PrimitiveEncoding
+ : IAsn1Encoding
+ {
+ private readonly int m_tagClass;
+ private readonly int m_tagNo;
+ private readonly byte[] m_contentsOctets;
+
+ internal PrimitiveEncoding(int tagClass, int tagNo, byte[] contentsOctets)
+ {
+ m_tagClass = tagClass;
+ m_tagNo = tagNo;
+ m_contentsOctets = contentsOctets;
+ }
+
+ void IAsn1Encoding.Encode(Asn1OutputStream asn1Out)
+ {
+ asn1Out.WriteIdentifier(m_tagClass, m_tagNo);
+ asn1Out.WriteDL(m_contentsOctets.Length);
+ asn1Out.Write(m_contentsOctets, 0, m_contentsOctets.Length);
+ }
+
+ int IAsn1Encoding.GetLength()
+ {
+ return Asn1OutputStream.GetLengthOfIdentifier(m_tagNo)
+ + Asn1OutputStream.GetLengthOfDL(m_contentsOctets.Length)
+ + m_contentsOctets.Length;
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs.meta
new file mode 100644
index 0000000..11d0603
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncoding.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9d78fe1945b88734e92a3fb89251c0d8
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs
new file mode 100644
index 0000000..c399c53
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs
@@ -0,0 +1,40 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1
+{
+ internal class PrimitiveEncodingSuffixed
+ : IAsn1Encoding
+ {
+ private readonly int m_tagClass;
+ private readonly int m_tagNo;
+ private readonly byte[] m_contentsOctets;
+ private readonly byte m_contentsSuffix;
+
+ internal PrimitiveEncodingSuffixed(int tagClass, int tagNo, byte[] contentsOctets, byte contentsSuffix)
+ {
+ m_tagClass = tagClass;
+ m_tagNo = tagNo;
+ m_contentsOctets = contentsOctets;
+ m_contentsSuffix = contentsSuffix;
+ }
+
+ void IAsn1Encoding.Encode(Asn1OutputStream asn1Out)
+ {
+ asn1Out.WriteIdentifier(m_tagClass, m_tagNo);
+ asn1Out.WriteDL(m_contentsOctets.Length);
+ asn1Out.Write(m_contentsOctets, 0, m_contentsOctets.Length - 1);
+ asn1Out.WriteByte(m_contentsSuffix);
+ }
+
+ int IAsn1Encoding.GetLength()
+ {
+ return Asn1OutputStream.GetLengthOfIdentifier(m_tagNo)
+ + Asn1OutputStream.GetLengthOfDL(m_contentsOctets.Length)
+ + m_contentsOctets.Length;
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs.meta
new file mode 100644
index 0000000..76c5fab
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/PrimitiveEncodingSuffixed.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ce5b5c34049b0fe4ca5b509fb2b50cd2
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/anssi/ANSSINamedCurves.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/anssi/ANSSINamedCurves.cs
index b1b6531..a30d65d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/anssi/ANSSINamedCurves.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/anssi/ANSSINamedCurves.cs
@@ -1,19 +1,19 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Anssi
{
- public class AnssiNamedCurves
+ /// Elliptic curve registry for ANSSI.
+ public static class AnssiNamedCurves
{
private static X9ECPoint ConfigureBasepoint(ECCurve curve, string encoding)
{
@@ -32,9 +32,6 @@ private static BigInteger FromHex(string hex)
return new BigInteger(1, Hex.DecodeStrict(hex));
}
- /*
- * FRP256v1
- */
internal class Frp256v1Holder
: X9ECParametersHolder
{
@@ -42,34 +39,39 @@ private Frp256v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new Frp256v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger p = FromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C03");
BigInteger a = FromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C00");
BigInteger b = FromHex("EE353FCA5428A9300D4ABA754A44C00FDFEC0C9AE4B1A1803075ED967B7BB73F");
- byte[] S = null;
BigInteger n = FromHex("F1FD178C0B3AD58F10126DE8CE42435B53DC67E140D2BF941FFDD459C6D655E1");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
+ return ConfigureCurve(new FpCurve(p, a, b, n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
+
X9ECPoint G = ConfigureBasepoint(curve,
"04B6B3D4C356C139EB31183D4749D423958C27D2DCAF98B70164C97A2DD98F5CFF6142E0F7C8B204911F9271F0F3ECEF8C2701C307E8E4C9E183115A1554062CFB");
- return new X9ECParameters(curve, G, n, h, S);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
- };
-
+ }
- private static readonly IDictionary objIds = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary curves = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary names = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private static readonly Dictionary objIds =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private static readonly Dictionary curves =
+ new Dictionary();
+ private static readonly Dictionary names =
+ new Dictionary();
- private static void DefineCurve(
- string name,
- DerObjectIdentifier oid,
- X9ECParametersHolder holder)
+ private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
{
- objIds.Add(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), oid);
+ objIds.Add(name, oid);
names.Add(oid, name);
curves.Add(oid, holder);
}
@@ -79,54 +81,64 @@ static AnssiNamedCurves()
DefineCurve("FRP256v1", AnssiObjectIdentifiers.FRP256v1, Frp256v1Holder.Instance);
}
- public static X9ECParameters GetByName(
- string name)
+ /// Look up the for the curve with the given name.
+ /// The name of the curve.
+ public static X9ECParameters GetByName(string name)
{
DerObjectIdentifier oid = GetOid(name);
return oid == null ? null : GetByOid(oid);
}
- /**
- * return the X9ECParameters object for the named curve represented by
- * the passed in object identifier. Null if the curve isn't present.
- *
- * @param oid an object identifier representing a named curve, if present.
- */
- public static X9ECParameters GetByOid(
- DerObjectIdentifier oid)
+ /// Look up an for the curve with the given name.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of the
+ /// full .
+ ///
+ /// The name of the curve.
+ public static X9ECParametersHolder GetByNameLazy(string name)
+ {
+ DerObjectIdentifier oid = GetOid(name);
+ return oid == null ? null : GetByOidLazy(oid);
+ }
+
+ /// Look up the for the curve with the given
+ /// OID.
+ /// The OID for the curve.
+ public static X9ECParameters GetByOid(DerObjectIdentifier oid)
+ {
+ return GetByOidLazy(oid)?.Parameters;
+ }
+
+ /// Look up an for the curve with the given
+ /// OID.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of the
+ /// full .
+ ///
+ /// The OID for the curve.
+ public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
{
- X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
- return holder == null ? null : holder.Parameters;
+ return CollectionUtilities.GetValueOrNull(curves, oid);
}
- /**
- * return the object identifier signified by the passed in name. Null
- * if there is no object identifier associated with name.
- *
- * @return the object identifier associated with name, if present.
- */
- public static DerObjectIdentifier GetOid(
- string name)
+ /// Look up the name of the curve with the given OID.
+ /// The OID for the curve.
+ public static string GetName(DerObjectIdentifier oid)
{
- return (DerObjectIdentifier)objIds[BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name)];
+ return CollectionUtilities.GetValueOrNull(names, oid);
}
- /**
- * return the named curve name represented by the given object identifier.
- */
- public static string GetName(
- DerObjectIdentifier oid)
+ /// Look up the OID of the curve with the given name.
+ /// The name of the curve.
+ public static DerObjectIdentifier GetOid(string name)
{
- return (string)names[oid];
+ return CollectionUtilities.GetValueOrNull(objIds, name);
}
- /**
- * returns an enumeration containing the name strings for curves
- * contained in this structure.
- */
- public static IEnumerable Names
+ /// Enumerate the available curve names in this registry.
+ public static IEnumerable Names
{
- get { return new EnumerableProxy(names.Values); }
+ get { return CollectionUtilities.Proxy(objIds.Keys); }
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/bc/BCObjectIdentifiers.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/bc/BCObjectIdentifiers.cs
index ff2ccbc..e5950f2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/bc/BCObjectIdentifiers.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/bc/BCObjectIdentifiers.cs
@@ -93,6 +93,53 @@ public abstract class BCObjectIdentifiers
public static readonly DerObjectIdentifier xmss_mt_with_SHA512 = xmss_mt.Branch("2");
public static readonly DerObjectIdentifier xmss_mt_with_SHAKE128 = xmss_mt.Branch("3");
public static readonly DerObjectIdentifier xmss_mt_with_SHAKE256 = xmss_mt.Branch("4");
+
+ /**
+ * SPHINCS+
+ */
+ public static readonly DerObjectIdentifier sphincsPlus = bc_sig.Branch("5");
+ public static readonly DerObjectIdentifier sphincsPlus_shake_256 = sphincsPlus.Branch("1");
+ public static readonly DerObjectIdentifier sphincsPlus_sha_256 = sphincsPlus.Branch("2");
+ public static readonly DerObjectIdentifier sphincsPlus_sha_512 = sphincsPlus.Branch("3");
+
+ /**
+ * Picnic
+ */
+ public static readonly DerObjectIdentifier picnic = bc_sig.Branch("6");
+ public static readonly DerObjectIdentifier picnicl1fs = picnic.Branch("1");
+ public static readonly DerObjectIdentifier picnicl1ur = picnic.Branch("2");
+ public static readonly DerObjectIdentifier picnicl3fs = picnic.Branch("3");
+ public static readonly DerObjectIdentifier picnicl3ur = picnic.Branch("4");
+ public static readonly DerObjectIdentifier picnicl5fs = picnic.Branch("5");
+ public static readonly DerObjectIdentifier picnicl5ur = picnic.Branch("6");
+ public static readonly DerObjectIdentifier picnic3l1 = picnic.Branch("7");
+ public static readonly DerObjectIdentifier picnic3l3 = picnic.Branch("8");
+ public static readonly DerObjectIdentifier picnic3l5 = picnic.Branch("9");
+ public static readonly DerObjectIdentifier picnicl1full = picnic.Branch("10");
+ public static readonly DerObjectIdentifier picnicl3full = picnic.Branch("11");
+ public static readonly DerObjectIdentifier picnicl5full = picnic.Branch("12");
+
+ /*
+ * Falcon
+ */
+ public static readonly DerObjectIdentifier falcon = bc_sig.Branch("7");
+
+ public static readonly DerObjectIdentifier falcon_512 = new DerObjectIdentifier("1.3.9999.3.1"); // falcon.branch("1");
+ public static readonly DerObjectIdentifier falcon_1024 = new DerObjectIdentifier("1.3.9999.3.4"); // falcon.branch("2");
+
+ /*
+ * Dilithium
+ */
+ public static readonly DerObjectIdentifier dilithium = bc_sig.Branch("8");
+
+ // OpenSSL OIDs
+ public static readonly DerObjectIdentifier dilithium2 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.7.4.4"); // dilithium.branch("1");
+ public static readonly DerObjectIdentifier dilithium3 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.7.6.5"); // dilithium.branch("2");
+ public static readonly DerObjectIdentifier dilithium5 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.7.8.7"); // dilithium.branch("3");
+ public static readonly DerObjectIdentifier dilithium2_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.11.4.4"); // dilithium.branch("4");
+ public static readonly DerObjectIdentifier dilithium3_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.11.6.5"); // dilithium.branch("5");
+ public static readonly DerObjectIdentifier dilithium5_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.11.8.7"); // dilithium.branch("6");
+
/**
* key_exchange(3) algorithms
@@ -106,13 +153,100 @@ public abstract class BCObjectIdentifiers
/**
* X.509 extension(4) values
- *
+ *
* 1.3.6.1.4.1.22554.4
*/
public static readonly DerObjectIdentifier bc_ext = bc.Branch("4");
public static readonly DerObjectIdentifier linkedCertificate = bc_ext.Branch("1");
- }
+
+ /**
+ * KEM(4) algorithms
+ */
+ public static readonly DerObjectIdentifier bc_kem = bc.Branch("5");
+
+ /**
+ * Classic McEliece
+ */
+ public static readonly DerObjectIdentifier pqc_kem_mceliece = bc_kem.Branch("1");
+
+ public static readonly DerObjectIdentifier mceliece348864_r3 = pqc_kem_mceliece.Branch("1");
+ public static readonly DerObjectIdentifier mceliece348864f_r3 = pqc_kem_mceliece.Branch("2");
+ public static readonly DerObjectIdentifier mceliece460896_r3 = pqc_kem_mceliece.Branch("3");
+ public static readonly DerObjectIdentifier mceliece460896f_r3 = pqc_kem_mceliece.Branch("4");
+ public static readonly DerObjectIdentifier mceliece6688128_r3 = pqc_kem_mceliece.Branch("5");
+ public static readonly DerObjectIdentifier mceliece6688128f_r3 = pqc_kem_mceliece.Branch("6");
+ public static readonly DerObjectIdentifier mceliece6960119_r3 = pqc_kem_mceliece.Branch("7");
+ public static readonly DerObjectIdentifier mceliece6960119f_r3 = pqc_kem_mceliece.Branch("8");
+ public static readonly DerObjectIdentifier mceliece8192128_r3 = pqc_kem_mceliece.Branch("9");
+ public static readonly DerObjectIdentifier mceliece8192128f_r3 = pqc_kem_mceliece.Branch("10");
+
+ /**
+ * SABER
+ */
+ public static readonly DerObjectIdentifier pqc_kem_saber = bc_kem.Branch("3");
+ public static readonly DerObjectIdentifier lightsaberkem128r3 = pqc_kem_saber.Branch("1");
+ public static readonly DerObjectIdentifier saberkem128r3 = pqc_kem_saber.Branch("2");
+ public static readonly DerObjectIdentifier firesaberkem128r3 = pqc_kem_saber.Branch("3");
+ public static readonly DerObjectIdentifier lightsaberkem192r3 = pqc_kem_saber.Branch("4");
+ public static readonly DerObjectIdentifier saberkem192r3 = pqc_kem_saber.Branch("5");
+ public static readonly DerObjectIdentifier firesaberkem192r3 = pqc_kem_saber.Branch("6");
+ public static readonly DerObjectIdentifier lightsaberkem256r3 = pqc_kem_saber.Branch("7");
+ public static readonly DerObjectIdentifier saberkem256r3 = pqc_kem_saber.Branch("8");
+ public static readonly DerObjectIdentifier firesaberkem256r3 = pqc_kem_saber.Branch("9");
+ public static readonly DerObjectIdentifier ulightsaberkemr3 = pqc_kem_saber.Branch("10");
+ public static readonly DerObjectIdentifier usaberkemr3 = pqc_kem_saber.Branch("11");
+ public static readonly DerObjectIdentifier ufiresaberkemr3 = pqc_kem_saber.Branch("12");
+ public static readonly DerObjectIdentifier lightsaberkem90sr3 = pqc_kem_saber.Branch("13");
+ public static readonly DerObjectIdentifier saberkem90sr3 = pqc_kem_saber.Branch("14");
+ public static readonly DerObjectIdentifier firesaberkem90sr3 = pqc_kem_saber.Branch("15");
+ public static readonly DerObjectIdentifier ulightsaberkem90sr3 = pqc_kem_saber.Branch("16");
+ public static readonly DerObjectIdentifier usaberkem90sr3 = pqc_kem_saber.Branch("17");
+ public static readonly DerObjectIdentifier ufiresaberkem90sr3 = pqc_kem_saber.Branch("18");
+
+ /**
+ * SIKE
+ */
+ public static readonly DerObjectIdentifier pqc_kem_sike = bc_kem.Branch("4");
+ public static readonly DerObjectIdentifier sikep434 = pqc_kem_sike.Branch("1");
+ public static readonly DerObjectIdentifier sikep503 = pqc_kem_sike.Branch("2");
+ public static readonly DerObjectIdentifier sikep610 = pqc_kem_sike.Branch("3");
+ public static readonly DerObjectIdentifier sikep751 = pqc_kem_sike.Branch("4");
+ public static readonly DerObjectIdentifier sikep434_compressed = pqc_kem_sike.Branch("5");
+ public static readonly DerObjectIdentifier sikep503_compressed = pqc_kem_sike.Branch("6");
+ public static readonly DerObjectIdentifier sikep610_compressed = pqc_kem_sike.Branch("7");
+ public static readonly DerObjectIdentifier sikep751_compressed = pqc_kem_sike.Branch("8");
+
+ /**
+ * Kyber
+ */
+ public static readonly DerObjectIdentifier pqc_kem_kyber = bc_kem.Branch("6");
+
+ public static readonly DerObjectIdentifier kyber512 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.8.2.2"); // pqc_kem_kyber.Branch("1");
+ public static readonly DerObjectIdentifier kyber768 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.8.3.3"); // pqc_kem_kyber.Branch("2");
+ public static readonly DerObjectIdentifier kyber1024 = new DerObjectIdentifier("1.3.6.1.4.1.2.267.8.4.4"); // pqc_kem_kyber.Branch("3");
+ public static readonly DerObjectIdentifier kyber512_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.10.2.2"); // pqc_kem_kyber.Branch("4");
+ public static readonly DerObjectIdentifier kyber768_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.10.3.3"); // pqc_kem_kyber.Branch("5");
+ public static readonly DerObjectIdentifier kyber1024_aes = new DerObjectIdentifier("1.3.6.1.4.1.2.267.10.4.4"); // pqc_kem_kyber.Branch("6");
+
+ /**
+ * BIKE
+ */
+ public static readonly DerObjectIdentifier pqc_kem_bike = bc_kem.Branch("8");
+
+ public static readonly DerObjectIdentifier bike128 = pqc_kem_bike.Branch("1");
+ public static readonly DerObjectIdentifier bike192 = pqc_kem_bike.Branch("2");
+ public static readonly DerObjectIdentifier bike256 = pqc_kem_bike.Branch("3");
+
+ /**
+ * HQC
+ */
+ public static readonly DerObjectIdentifier pqc_kem_hqc = bc_kem.Branch("9");
+
+ public static readonly DerObjectIdentifier hqc128 = pqc_kem_hqc.Branch("1");
+ public static readonly DerObjectIdentifier hqc192 = pqc_kem_hqc.Branch("2");
+ public static readonly DerObjectIdentifier hqc256 = pqc_kem_hqc.Branch("3");
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CAKeyUpdAnnContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CAKeyUpdAnnContent.cs
index 84ee8c3..b690548 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CAKeyUpdAnnContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CAKeyUpdAnnContent.cs
@@ -9,42 +9,33 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
public class CAKeyUpdAnnContent
: Asn1Encodable
{
- private readonly CmpCertificate oldWithNew;
- private readonly CmpCertificate newWithOld;
- private readonly CmpCertificate newWithNew;
+ public static CAKeyUpdAnnContent GetInstance(object obj)
+ {
+ if (obj is CAKeyUpdAnnContent content)
+ return content;
- private CAKeyUpdAnnContent(Asn1Sequence seq)
- {
- oldWithNew = CmpCertificate.GetInstance(seq[0]);
- newWithOld = CmpCertificate.GetInstance(seq[1]);
- newWithNew = CmpCertificate.GetInstance(seq[2]);
- }
+ if (obj is Asn1Sequence seq)
+ return new CAKeyUpdAnnContent(seq);
- public static CAKeyUpdAnnContent GetInstance(object obj)
- {
- if (obj is CAKeyUpdAnnContent)
- return (CAKeyUpdAnnContent)obj;
+ throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
+ }
- if (obj is Asn1Sequence)
- return new CAKeyUpdAnnContent((Asn1Sequence)obj);
+ private readonly CmpCertificate m_oldWithNew;
+ private readonly CmpCertificate m_newWithOld;
+ private readonly CmpCertificate m_newWithNew;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
-
- public virtual CmpCertificate OldWithNew
- {
- get { return oldWithNew; }
- }
-
- public virtual CmpCertificate NewWithOld
+ private CAKeyUpdAnnContent(Asn1Sequence seq)
{
- get { return newWithOld; }
+ m_oldWithNew = CmpCertificate.GetInstance(seq[0]);
+ m_newWithOld = CmpCertificate.GetInstance(seq[1]);
+ m_newWithNew = CmpCertificate.GetInstance(seq[2]);
}
- public virtual CmpCertificate NewWithNew
- {
- get { return newWithNew; }
- }
+ public virtual CmpCertificate OldWithNew => m_oldWithNew;
+
+ public virtual CmpCertificate NewWithOld => m_newWithOld;
+
+ public virtual CmpCertificate NewWithNew => m_newWithNew;
/**
*
@@ -58,7 +49,7 @@ public virtual CmpCertificate NewWithNew
*/
public override Asn1Object ToAsn1Object()
{
- return new DerSequence(oldWithNew, newWithOld, newWithNew);
+ return new DerSequence(m_oldWithNew, m_newWithOld, m_newWithNew);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs
new file mode 100644
index 0000000..f3f2106
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs
@@ -0,0 +1,76 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+using System.IO;
+
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
+{
+ /**
+ * CertAnnContent ::= CMPCertificate
+ */
+ public class CertAnnContent
+ : CmpCertificate
+ {
+ public static new CertAnnContent GetInstance(object obj)
+ {
+ // TODO[cmp]
+ if (obj == null)
+ return null;
+
+ if (obj is CertAnnContent content)
+ return content;
+
+ if (obj is CmpCertificate cmpCertificate)
+ return GetInstance(cmpCertificate.GetEncoded());
+
+ if (obj is byte[] bs)
+ {
+ try
+ {
+ obj = Asn1Object.FromByteArray(bs);
+ }
+ catch (IOException)
+ {
+ throw new ArgumentException("Invalid encoding in CertAnnContent");
+ }
+ }
+
+ if (obj is Asn1Sequence)
+ return new CertAnnContent(X509CertificateStructure.GetInstance(obj));
+
+ // TODO[cmp]
+ if (obj is Asn1TaggedObject taggedObject)
+ return new CertAnnContent(taggedObject.TagNo, taggedObject.GetObject());
+
+ throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
+ }
+
+ public static new CertAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+ {
+ // TODO[cmp]
+ if (taggedObject == null)
+ return null;
+
+ if (!declaredExplicit)
+ throw new ArgumentException("tag must be explicit");
+
+ // TODO[cmp]
+ return GetInstance(taggedObject.GetObject());
+ }
+
+ public CertAnnContent(int type, Asn1Object otherCert)
+ : base(type, otherCert)
+ {
+ }
+
+ public CertAnnContent(X509CertificateStructure x509v3PKCert)
+ : base(x509v3PKCert)
+ {
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs.meta
new file mode 100644
index 0000000..0755ed3
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertAnnContent.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ac1d7e1613f79474e99c1cb95dbda39d
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertConfirmContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertConfirmContent.cs
index 77d8852..018537b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertConfirmContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertConfirmContent.cs
@@ -9,32 +9,27 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
public class CertConfirmContent
: Asn1Encodable
{
- private readonly Asn1Sequence content;
-
- private CertConfirmContent(Asn1Sequence seq)
- {
- content = seq;
- }
-
public static CertConfirmContent GetInstance(object obj)
{
- if (obj is CertConfirmContent)
- return (CertConfirmContent)obj;
+ if (obj is CertConfirmContent content)
+ return content;
- if (obj is Asn1Sequence)
- return new CertConfirmContent((Asn1Sequence)obj);
+ if (obj is Asn1Sequence seq)
+ return new CertConfirmContent(seq);
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
}
- public virtual CertStatus[] ToCertStatusArray()
+ private readonly Asn1Sequence m_content;
+
+ private CertConfirmContent(Asn1Sequence seq)
+ {
+ m_content = seq;
+ }
+
+ public virtual CertStatus[] ToCertStatusArray()
{
- CertStatus[] result = new CertStatus[content.Count];
- for (int i = 0; i != result.Length; i++)
- {
- result[i] = CertStatus.GetInstance(content[i]);
- }
- return result;
+ return m_content.MapElements(CertStatus.GetInstance);
}
/**
@@ -45,7 +40,7 @@ public virtual CertStatus[] ToCertStatusArray()
*/
public override Asn1Object ToAsn1Object()
{
- return content;
+ return m_content;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertOrEncCert.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertOrEncCert.cs
index 05bc6a3..837feec 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertOrEncCert.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertOrEncCert.cs
@@ -10,79 +10,79 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
public class CertOrEncCert
: Asn1Encodable, IAsn1Choice
{
- private readonly CmpCertificate certificate;
- private readonly EncryptedValue encryptedCert;
+ public static CertOrEncCert GetInstance(object obj)
+ {
+ if (obj is CertOrEncCert certOrEncCert)
+ return certOrEncCert;
- private CertOrEncCert(Asn1TaggedObject tagged)
+ if (obj is Asn1TaggedObject taggedObject)
+ return new CertOrEncCert(taggedObject);
+
+ throw new ArgumentException("Invalid object: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
+ }
+
+ private readonly CmpCertificate m_certificate;
+ private readonly EncryptedKey m_encryptedCert;
+
+ private CertOrEncCert(Asn1TaggedObject taggedObject)
{
- if (tagged.TagNo == 0)
+ if (taggedObject.TagNo == 0)
{
- certificate = CmpCertificate.GetInstance(tagged.GetObject());
+ m_certificate = CmpCertificate.GetInstance(taggedObject.GetObject());
}
- else if (tagged.TagNo == 1)
+ else if (taggedObject.TagNo == 1)
{
- encryptedCert = EncryptedValue.GetInstance(tagged.GetObject());
+ m_encryptedCert = EncryptedKey.GetInstance(taggedObject.GetObject());
}
else
{
- throw new ArgumentException("unknown tag: " + tagged.TagNo, "tagged");
- }
- }
-
- public static CertOrEncCert GetInstance(object obj)
- {
- if (obj is CertOrEncCert)
- return (CertOrEncCert)obj;
-
- if (obj is Asn1TaggedObject)
- return new CertOrEncCert((Asn1TaggedObject)obj);
-
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
+ throw new ArgumentException("unknown tag: " + taggedObject.TagNo, nameof(taggedObject));
+ }
+ }
public CertOrEncCert(CmpCertificate certificate)
{
if (certificate == null)
- throw new ArgumentNullException("certificate");
+ throw new ArgumentNullException(nameof(certificate));
- this.certificate = certificate;
+ m_certificate = certificate;
}
- public CertOrEncCert(EncryptedValue encryptedCert)
+ public CertOrEncCert(EncryptedValue encryptedValue)
{
- if (encryptedCert == null)
- throw new ArgumentNullException("encryptedCert");
+ if (encryptedValue == null)
+ throw new ArgumentNullException(nameof(encryptedValue));
- this.encryptedCert = encryptedCert;
+ m_encryptedCert = new EncryptedKey(encryptedValue);
}
- public virtual CmpCertificate Certificate
- {
- get { return certificate; }
- }
+ public CertOrEncCert(EncryptedKey encryptedKey)
+ {
+ if (encryptedKey == null)
+ throw new ArgumentNullException(nameof(encryptedKey));
- public virtual EncryptedValue EncryptedCert
- {
- get { return encryptedCert; }
- }
+ m_encryptedCert = encryptedKey;
+ }
- /**
+ public virtual CmpCertificate Certificate => m_certificate;
+
+ public virtual EncryptedKey EncryptedCert => m_encryptedCert;
+
+ /**
*
+ */
+ public class CertReqTemplateContent
+ : Asn1Encodable
+ {
+ public static CertReqTemplateContent GetInstance(object obj)
+ {
+ if (obj is CertReqTemplateContent certReqTemplateContent)
+ return certReqTemplateContent;
+
+ if (obj != null)
+ return new CertReqTemplateContent(Asn1Sequence.GetInstance(obj));
+
+ return null;
+ }
+
+ private readonly CertTemplate m_certTemplate;
+ private readonly Asn1Sequence m_keySpec;
+
+ private CertReqTemplateContent(Asn1Sequence seq)
+ {
+ if (seq.Count != 1 && seq.Count != 2)
+ throw new ArgumentException("expected sequence size of 1 or 2");
+
+ m_certTemplate = CertTemplate.GetInstance(seq[0]);
+
+ if (seq.Count > 1)
+ {
+ m_keySpec = Asn1Sequence.GetInstance(seq[1]);
+ }
+ }
+
+ public CertReqTemplateContent(CertTemplate certTemplate, Asn1Sequence keySpec)
+ {
+ m_certTemplate = certTemplate;
+ m_keySpec = keySpec;
+ }
+
+ public virtual CertTemplate CertTemplate => m_certTemplate;
+
+ public virtual Asn1Sequence KeySpec => m_keySpec;
+
+ public override Asn1Object ToAsn1Object()
+ {
+ Asn1EncodableVector v = new Asn1EncodableVector(m_certTemplate);
+ v.AddOptional(m_keySpec);
+ return new DerSequence(v);
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertReqTemplateContent.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertReqTemplateContent.cs.meta
new file mode 100644
index 0000000..281d5e2
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertReqTemplateContent.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: be9a5338c205ad742b1ecd78f88ba2b9
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertResponse.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertResponse.cs
index 0e7d4cd..ed392de 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertResponse.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertResponse.cs
@@ -2,22 +2,31 @@
#pragma warning disable
using System;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class CertResponse
: Asn1Encodable
{
- private readonly DerInteger certReqId;
- private readonly PkiStatusInfo status;
- private readonly CertifiedKeyPair certifiedKeyPair;
- private readonly Asn1OctetString rspInfo;
+ public static CertResponse GetInstance(object obj)
+ {
+ if (obj is CertResponse certResponse)
+ return certResponse;
+
+ if (obj != null)
+ return new CertResponse(Asn1Sequence.GetInstance(obj));
+
+ return null;
+ }
+
+ private readonly DerInteger m_certReqId;
+ private readonly PkiStatusInfo m_status;
+ private readonly CertifiedKeyPair m_certifiedKeyPair;
+ private readonly Asn1OctetString m_rspInfo;
private CertResponse(Asn1Sequence seq)
{
- certReqId = DerInteger.GetInstance(seq[0]);
- status = PkiStatusInfo.GetInstance(seq[1]);
+ m_certReqId = DerInteger.GetInstance(seq[0]);
+ m_status = PkiStatusInfo.GetInstance(seq[1]);
if (seq.Count >= 3)
{
@@ -26,71 +35,46 @@ private CertResponse(Asn1Sequence seq)
Asn1Encodable o = seq[2];
if (o is Asn1OctetString)
{
- rspInfo = Asn1OctetString.GetInstance(o);
+ m_rspInfo = Asn1OctetString.GetInstance(o);
}
else
{
- certifiedKeyPair = CertifiedKeyPair.GetInstance(o);
+ m_certifiedKeyPair = CertifiedKeyPair.GetInstance(o);
}
}
else
{
- certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
- rspInfo = Asn1OctetString.GetInstance(seq[3]);
+ m_certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
+ m_rspInfo = Asn1OctetString.GetInstance(seq[3]);
}
}
}
- public static CertResponse GetInstance(object obj)
- {
- if (obj is CertResponse)
- return (CertResponse)obj;
-
- if (obj is Asn1Sequence)
- return new CertResponse((Asn1Sequence)obj);
-
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
-
- public CertResponse(
- DerInteger certReqId,
- PkiStatusInfo status)
+ public CertResponse(DerInteger certReqId, PkiStatusInfo status)
: this(certReqId, status, null, null)
{
}
- public CertResponse(
- DerInteger certReqId,
- PkiStatusInfo status,
- CertifiedKeyPair certifiedKeyPair,
- Asn1OctetString rspInfo)
- {
- if (certReqId == null)
- throw new ArgumentNullException("certReqId");
+ public CertResponse(DerInteger certReqId, PkiStatusInfo status, CertifiedKeyPair certifiedKeyPair,
+ Asn1OctetString rspInfo)
+ {
+ if (certReqId == null)
+ throw new ArgumentNullException(nameof(certReqId));
if (status == null)
- throw new ArgumentNullException("status");
+ throw new ArgumentNullException(nameof(status));
- this.certReqId = certReqId;
- this.status = status;
- this.certifiedKeyPair = certifiedKeyPair;
- this.rspInfo = rspInfo;
+ m_certReqId = certReqId;
+ m_status = status;
+ m_certifiedKeyPair = certifiedKeyPair;
+ m_rspInfo = rspInfo;
}
- public virtual DerInteger CertReqID
- {
- get { return certReqId; }
- }
+ public virtual DerInteger CertReqID => m_certReqId;
- public virtual PkiStatusInfo Status
- {
- get { return status; }
- }
+ public virtual PkiStatusInfo Status => m_status;
- public virtual CertifiedKeyPair CertifiedKeyPair
- {
- get { return certifiedKeyPair; }
- }
+ public virtual CertifiedKeyPair CertifiedKeyPair => m_certifiedKeyPair;
/**
*
@@ -110,8 +94,8 @@ public virtual CertifiedKeyPair CertifiedKeyPair
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(certReqId, status);
- v.AddOptional(certifiedKeyPair, rspInfo);
+ Asn1EncodableVector v = new Asn1EncodableVector(m_certReqId, m_status);
+ v.AddOptional(m_certifiedKeyPair, m_rspInfo);
return new DerSequence(v);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertStatus.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertStatus.cs
index 8b64711..646fa56 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertStatus.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/CertStatus.cs
@@ -2,85 +2,103 @@
#pragma warning disable
using System;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class CertStatus
: Asn1Encodable
{
- private readonly Asn1OctetString certHash;
- private readonly DerInteger certReqId;
- private readonly PkiStatusInfo statusInfo;
+ public static CertStatus GetInstance(object obj)
+ {
+ if (obj is CertStatus certStatus)
+ return certStatus;
- private CertStatus(Asn1Sequence seq)
+ if (obj != null)
+ return new CertStatus(Asn1Sequence.GetInstance(obj));
+
+ return null;
+ }
+
+ private readonly Asn1OctetString m_certHash;
+ private readonly DerInteger m_certReqID;
+ private readonly PkiStatusInfo m_statusInfo;
+ private readonly AlgorithmIdentifier m_hashAlg;
+
+ private CertStatus(Asn1Sequence seq)
{
- certHash = Asn1OctetString.GetInstance(seq[0]);
- certReqId = DerInteger.GetInstance(seq[1]);
+ m_certHash = Asn1OctetString.GetInstance(seq[0]);
+ m_certReqID = DerInteger.GetInstance(seq[1]);
if (seq.Count > 2)
{
- statusInfo = PkiStatusInfo.GetInstance(seq[2]);
+ for (int t = 2; t < seq.Count; t++)
+ {
+ Asn1Object p = seq[t].ToAsn1Object();
+ if (p is Asn1Sequence s)
+ {
+ m_statusInfo = PkiStatusInfo.GetInstance(s);
+ }
+ if (p is Asn1TaggedObject dto)
+ {
+ if (dto.TagNo != 0)
+ throw new ArgumentException("unknown tag " + dto.TagNo);
+
+ m_hashAlg = AlgorithmIdentifier.GetInstance(dto, true);
+ }
+ }
}
}
- public CertStatus(byte[] certHash, BigInteger certReqId)
+ public CertStatus(byte[] certHash, BigInteger certReqID)
{
- this.certHash = new DerOctetString(certHash);
- this.certReqId = new DerInteger(certReqId);
+ m_certHash = new DerOctetString(certHash);
+ m_certReqID = new DerInteger(certReqID);
}
- public CertStatus(byte[] certHash, BigInteger certReqId, PkiStatusInfo statusInfo)
+ public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo)
{
- this.certHash = new DerOctetString(certHash);
- this.certReqId = new DerInteger(certReqId);
- this.statusInfo = statusInfo;
+ m_certHash = new DerOctetString(certHash);
+ m_certReqID = new DerInteger(certReqID);
+ m_statusInfo = statusInfo;
}
- public static CertStatus GetInstance(object obj)
- {
- if (obj is CertStatus)
- return (CertStatus)obj;
+ public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo, AlgorithmIdentifier hashAlg)
+ {
+ m_certHash = new DerOctetString(certHash);
+ m_certReqID = new DerInteger(certReqID);
+ m_statusInfo = statusInfo;
+ m_hashAlg = hashAlg;
+ }
- if (obj is Asn1Sequence)
- return new CertStatus((Asn1Sequence)obj);
+ public virtual Asn1OctetString CertHash => m_certHash;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
+ public virtual DerInteger CertReqID => m_certReqID;
- public virtual Asn1OctetString CertHash
- {
- get { return certHash; }
- }
-
- public virtual DerInteger CertReqID
- {
- get { return certReqId; }
- }
+ public virtual PkiStatusInfo StatusInfo => m_statusInfo;
- public virtual PkiStatusInfo StatusInfo
- {
- get { return statusInfo; }
- }
+ public virtual AlgorithmIdentifier HashAlg => m_hashAlg;
- /**
- *
- * CertStatus ::= SEQUENCE {
- * certHash OCTET STRING,
- * -- the hash of the certificate, using the same hash algorithm
- * -- as is used to create and verify the certificate signature
- * certReqId INTEGER,
- * -- to match this confirmation with the corresponding req/rep
- * statusInfo PKIStatusInfo OPTIONAL
- * }
- *
- * @return a basic ASN.1 object representation.
- */
- public override Asn1Object ToAsn1Object()
+ /**
+ *
@@ -99,9 +91,9 @@ public virtual PkiPublicationInfo PublicationInfo
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(certOrEncCert);
- v.AddOptionalTagged(true, 0, privateKey);
- v.AddOptionalTagged(true, 1, publicationInfo);
+ Asn1EncodableVector v = new Asn1EncodableVector(m_certOrEncCert);
+ v.AddOptionalTagged(true, 0, m_privateKey);
+ v.AddOptionalTagged(true, 1, m_publicationInfo);
return new DerSequence(v);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/Challenge.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/Challenge.cs
index 72af824..093ea91 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/Challenge.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/Challenge.cs
@@ -3,16 +3,52 @@
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
- public class Challenge
+ /**
+ *
+ * Challenge ::= SEQUENCE {
+ * owf AlgorithmIdentifier OPTIONAL,
+ *
+ * -- MUST be present in the first Challenge; MAY be omitted in
+ * -- any subsequent Challenge in POPODecKeyChallContent (if
+ * -- omitted, then the owf used in the immediately preceding
+ * -- Challenge is to be used).
+ *
+ * witness OCTET STRING,
+ * -- the result of applying the one-way function (owf) to a
+ * -- randomly-generated INTEGER, A. [Note that a different
+ * -- INTEGER MUST be used for each Challenge.]
+ * challenge OCTET STRING
+ * -- the encryption (under the public key for which the cert.
+ * -- request is being made) of Rand, where Rand is specified as
+ * -- Rand ::= SEQUENCE {
+ * -- int INTEGER,
+ * -- - the randomly-generated INTEGER A (above)
+ * -- sender GeneralName
+ * -- - the sender's name (as included in PKIHeader)
+ * -- }
+ * }
+ *
+ */
+ public class Challenge
: Asn1Encodable
{
- private readonly AlgorithmIdentifier owf;
- private readonly Asn1OctetString witness;
- private readonly Asn1OctetString challenge;
+ public static Challenge GetInstance(object obj)
+ {
+ if (obj is Challenge challenge)
+ return challenge;
+
+ if (obj != null)
+ return new Challenge(Asn1Sequence.GetInstance(obj));
+
+ return null;
+ }
+
+ private readonly AlgorithmIdentifier m_owf;
+ private readonly Asn1OctetString m_witness;
+ private readonly Asn1OctetString m_challenge;
private Challenge(Asn1Sequence seq)
{
@@ -20,30 +56,32 @@ private Challenge(Asn1Sequence seq)
if (seq.Count == 3)
{
- owf = AlgorithmIdentifier.GetInstance(seq[index++]);
+ m_owf = AlgorithmIdentifier.GetInstance(seq[index++]);
}
- witness = Asn1OctetString.GetInstance(seq[index++]);
- challenge = Asn1OctetString.GetInstance(seq[index]);
+ m_witness = Asn1OctetString.GetInstance(seq[index++]);
+ m_challenge = Asn1OctetString.GetInstance(seq[index]);
}
- public static Challenge GetInstance(object obj)
- {
- if (obj is Challenge)
- return (Challenge)obj;
+ public Challenge(byte[] witness, byte[] challenge)
+ : this(null, witness, challenge)
+ {
+ }
- if (obj is Asn1Sequence)
- return new Challenge((Asn1Sequence)obj);
+ public Challenge(AlgorithmIdentifier owf, byte[] witness, byte[] challenge)
+ {
+ m_owf = owf;
+ m_witness = new DerOctetString(witness);
+ m_challenge = new DerOctetString(challenge);
+ }
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
+ public virtual AlgorithmIdentifier Owf => m_owf;
- public virtual AlgorithmIdentifier Owf
- {
- get { return owf; }
- }
+ public virtual Asn1OctetString Witness => m_witness;
+
+ public virtual Asn1OctetString ChallengeValue => m_challenge;
- /**
+ /**
*
* @return a basic ASN.1 object representation.
*/
- public override Asn1Object ToAsn1Object()
+ public override Asn1Object ToAsn1Object()
+ {
+ return m_content;
+ }
+
+ private static DerInteger[] SequenceToDerIntegerArray(Asn1Sequence seq)
+ {
+ return seq.MapElements(DerInteger.GetInstance);
+ }
+
+ private static DerSequence[] IntsToSequence(DerInteger[] ids)
{
- return content;
+ DerSequence[] result = new DerSequence[ids.Length];
+
+ for (int i = 0; i != result.Length; i++)
+ {
+ result[i] = new DerSequence(ids[i]);
+ }
+
+ return result;
+ }
+
+ private static DerInteger[] IntsToAsn1(BigInteger[] ids)
+ {
+ DerInteger[] result = new DerInteger[ids.Length];
+
+ for (int i = 0; i != result.Length; i++)
+ {
+ result[i] = new DerInteger(ids[i]);
+ }
+
+ return result;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyChallContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyChallContent.cs
index c04381a..e662a7a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyChallContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyChallContent.cs
@@ -2,39 +2,32 @@
#pragma warning disable
using System;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class PopoDecKeyChallContent
: Asn1Encodable
{
- private readonly Asn1Sequence content;
+ public static PopoDecKeyChallContent GetInstance(object obj)
+ {
+ if (obj is PopoDecKeyChallContent popoDecKeyChallContent)
+ return popoDecKeyChallContent;
- private PopoDecKeyChallContent(Asn1Sequence seq)
- {
- content = seq;
- }
+ if (obj != null)
+ return new PopoDecKeyChallContent(Asn1Sequence.GetInstance(obj));
- public static PopoDecKeyChallContent GetInstance(object obj)
- {
- if (obj is PopoDecKeyChallContent)
- return (PopoDecKeyChallContent)obj;
+ return null;
+ }
- if (obj is Asn1Sequence)
- return new PopoDecKeyChallContent((Asn1Sequence)obj);
+ private readonly Asn1Sequence m_content;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ private PopoDecKeyChallContent(Asn1Sequence seq)
+ {
+ m_content = seq;
}
public virtual Challenge[] ToChallengeArray()
{
- Challenge[] result = new Challenge[content.Count];
- for (int i = 0; i != result.Length; ++i)
- {
- result[i] = Challenge.GetInstance(content[i]);
- }
- return result;
+ return m_content.MapElements(Challenge.GetInstance);
}
/**
@@ -45,7 +38,7 @@ public virtual Challenge[] ToChallengeArray()
*/
public override Asn1Object ToAsn1Object()
{
- return content;
+ return m_content;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyRespContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyRespContent.cs
index bf59de1..0341c14 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyRespContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/PopoDecKeyRespContent.cs
@@ -1,40 +1,31 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class PopoDecKeyRespContent
: Asn1Encodable
{
- private readonly Asn1Sequence content;
+ public static PopoDecKeyRespContent GetInstance(object obj)
+ {
+ if (obj is PopoDecKeyRespContent popoDecKeyRespContent)
+ return popoDecKeyRespContent;
- private PopoDecKeyRespContent(Asn1Sequence seq)
- {
- content = seq;
- }
+ if (obj != null)
+ return new PopoDecKeyRespContent(Asn1Sequence.GetInstance(obj));
- public static PopoDecKeyRespContent GetInstance(object obj)
- {
- if (obj is PopoDecKeyRespContent)
- return (PopoDecKeyRespContent)obj;
+ return null;
+ }
- if (obj is Asn1Sequence)
- return new PopoDecKeyRespContent((Asn1Sequence)obj);
+ private readonly Asn1Sequence m_content;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ private PopoDecKeyRespContent(Asn1Sequence seq)
+ {
+ m_content = seq;
}
- public virtual DerInteger[] ToDerIntegerArray()
+ public virtual DerInteger[] ToIntegerArray()
{
- DerInteger[] result = new DerInteger[content.Count];
- for (int i = 0; i != result.Length; ++i)
- {
- result[i] = DerInteger.GetInstance(content[i]);
- }
- return result;
+ return m_content.MapElements(DerInteger.GetInstance);
}
/**
@@ -45,7 +36,7 @@ public virtual DerInteger[] ToDerIntegerArray()
*/
public override Asn1Object ToAsn1Object()
{
- return content;
+ return m_content;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/ProtectedPart.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/ProtectedPart.cs
index a7f4fdb..6bf2ce6 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/ProtectedPart.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/ProtectedPart.cs
@@ -1,49 +1,39 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class ProtectedPart
: Asn1Encodable
{
- private readonly PkiHeader header;
- private readonly PkiBody body;
-
- private ProtectedPart(Asn1Sequence seq)
- {
- header = PkiHeader.GetInstance(seq[0]);
- body = PkiBody.GetInstance(seq[1]);
- }
+ public static ProtectedPart GetInstance(object obj)
+ {
+ if (obj is ProtectedPart protectedPart)
+ return protectedPart;
- public static ProtectedPart GetInstance(object obj)
- {
- if (obj is ProtectedPart)
- return (ProtectedPart)obj;
+ if (obj != null)
+ return new ProtectedPart(Asn1Sequence.GetInstance(obj));
- if (obj is Asn1Sequence)
- return new ProtectedPart((Asn1Sequence)obj);
+ return null;
+ }
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
+ private readonly PkiHeader m_header;
+ private readonly PkiBody m_body;
- public ProtectedPart(PkiHeader header, PkiBody body)
+ private ProtectedPart(Asn1Sequence seq)
{
- this.header = header;
- this.body = body;
+ m_header = PkiHeader.GetInstance(seq[0]);
+ m_body = PkiBody.GetInstance(seq[1]);
}
- public virtual PkiHeader Header
+ public ProtectedPart(PkiHeader header, PkiBody body)
{
- get { return header; }
+ m_header = header;
+ m_body = body;
}
- public virtual PkiBody Body
- {
- get { return body; }
- }
+ public virtual PkiHeader Header => m_header;
+
+ public virtual PkiBody Body => m_body;
/**
*
@@ -56,7 +46,7 @@ public virtual PkiBody Body
*/
public override Asn1Object ToAsn1Object()
{
- return new DerSequence(header, body);
+ return new DerSequence(m_header, m_body);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevAnnContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevAnnContent.cs
index 0a02b55..3af7a4f 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevAnnContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevAnnContent.cs
@@ -1,70 +1,68 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class RevAnnContent
: Asn1Encodable
{
- private readonly PkiStatusEncodable status;
- private readonly CertId certId;
- private readonly DerGeneralizedTime willBeRevokedAt;
- private readonly DerGeneralizedTime badSinceDate;
- private readonly X509Extensions crlDetails;
+ public static RevAnnContent GetInstance(object obj)
+ {
+ if (obj is RevAnnContent revAnnContent)
+ return revAnnContent;
- private RevAnnContent(Asn1Sequence seq)
- {
- status = PkiStatusEncodable.GetInstance(seq[0]);
- certId = CertId.GetInstance(seq[1]);
- willBeRevokedAt = DerGeneralizedTime.GetInstance(seq[2]);
- badSinceDate = DerGeneralizedTime.GetInstance(seq[3]);
+ if (obj != null)
+ return new RevAnnContent(Asn1Sequence.GetInstance(obj));
- if (seq.Count > 4)
- {
- crlDetails = X509Extensions.GetInstance(seq[4]);
- }
- }
+ return null;
+ }
- public static RevAnnContent GetInstance(object obj)
- {
- if (obj is RevAnnContent)
- return (RevAnnContent)obj;
-
- if (obj is Asn1Sequence)
- return new RevAnnContent((Asn1Sequence)obj);
+ private readonly PkiStatusEncodable m_status;
+ private readonly CertId m_certID;
+ private readonly Asn1GeneralizedTime m_willBeRevokedAt;
+ private readonly Asn1GeneralizedTime m_badSinceDate;
+ private readonly X509Extensions m_crlDetails;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ public RevAnnContent(PkiStatusEncodable status, CertId certID, Asn1GeneralizedTime willBeRevokedAt,
+ Asn1GeneralizedTime badSinceDate)
+ : this(status, certID, willBeRevokedAt, badSinceDate, null)
+ {
}
- public virtual PkiStatusEncodable Status
- {
- get { return status; }
- }
+ public RevAnnContent(PkiStatusEncodable status, CertId certID, Asn1GeneralizedTime willBeRevokedAt,
+ Asn1GeneralizedTime badSinceDate, X509Extensions crlDetails)
+ {
+ m_status = status;
+ m_certID = certID;
+ m_willBeRevokedAt = willBeRevokedAt;
+ m_badSinceDate = badSinceDate;
+ m_crlDetails = crlDetails;
+ }
- public virtual CertId CertID
+ private RevAnnContent(Asn1Sequence seq)
{
- get { return certId; }
- }
+ m_status = PkiStatusEncodable.GetInstance(seq[0]);
+ m_certID = CertId.GetInstance(seq[1]);
+ m_willBeRevokedAt = Asn1GeneralizedTime.GetInstance(seq[2]);
+ m_badSinceDate = Asn1GeneralizedTime.GetInstance(seq[3]);
- public virtual DerGeneralizedTime WillBeRevokedAt
- {
- get { return willBeRevokedAt; }
+ if (seq.Count > 4)
+ {
+ m_crlDetails = X509Extensions.GetInstance(seq[4]);
+ }
}
- public virtual DerGeneralizedTime BadSinceDate
- {
- get { return badSinceDate; }
- }
+ public virtual PkiStatusEncodable Status => m_status;
- public virtual X509Extensions CrlDetails
- {
- get { return crlDetails; }
- }
+ public virtual CertId CertID => m_certID;
+
+ public virtual Asn1GeneralizedTime WillBeRevokedAt => m_willBeRevokedAt;
+
+ public virtual Asn1GeneralizedTime BadSinceDate => m_badSinceDate;
+
+ public virtual X509Extensions CrlDetails => m_crlDetails;
/**
*
@@ -81,8 +79,8 @@ public virtual X509Extensions CrlDetails
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(status, certId, willBeRevokedAt, badSinceDate);
- v.AddOptional(crlDetails);
+ Asn1EncodableVector v = new Asn1EncodableVector(m_status, m_certID, m_willBeRevokedAt, m_badSinceDate);
+ v.AddOptional(m_crlDetails);
return new DerSequence(v);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevDetails.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevDetails.cs
index bee4aa3..72bcd10 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevDetails.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevDetails.cs
@@ -1,58 +1,63 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
- public class RevDetails
+ /**
+ *
+ * RevDetails ::= SEQUENCE {
+ * certDetails CertTemplate,
+ * -- allows requester to specify as much as they can about
+ * -- the cert. for which revocation is requested
+ * -- (e.g., for cases in which serialNumber is not available)
+ * crlEntryDetails Extensions OPTIONAL
+ * -- requested crlEntryExtensions
+ * }
+ *
+ */
+ public class RevDetails
: Asn1Encodable
{
- private readonly CertTemplate certDetails;
- private readonly X509Extensions crlEntryDetails;
+ public static RevDetails GetInstance(object obj)
+ {
+ if (obj is RevDetails revDetails)
+ return revDetails;
- private RevDetails(Asn1Sequence seq)
- {
- certDetails = CertTemplate.GetInstance(seq[0]);
- crlEntryDetails = seq.Count <= 1
- ? null
- : X509Extensions.GetInstance(seq[1]);
- }
+ if (obj != null)
+ return new RevDetails(Asn1Sequence.GetInstance(obj));
- public static RevDetails GetInstance(object obj)
- {
- if (obj is RevDetails)
- return (RevDetails)obj;
+ return null;
+ }
- if (obj is Asn1Sequence)
- return new RevDetails((Asn1Sequence)obj);
+ private readonly CertTemplate m_certDetails;
+ private readonly X509Extensions m_crlEntryDetails;
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ private RevDetails(Asn1Sequence seq)
+ {
+ m_certDetails = CertTemplate.GetInstance(seq[0]);
+
+ if (seq.Count > 1)
+ {
+ m_crlEntryDetails = X509Extensions.GetInstance(seq[1]);
+ }
}
public RevDetails(CertTemplate certDetails)
- : this(certDetails, null)
+ : this(certDetails, null)
{
}
public RevDetails(CertTemplate certDetails, X509Extensions crlEntryDetails)
{
- this.certDetails = certDetails;
- this.crlEntryDetails = crlEntryDetails;
+ m_certDetails = certDetails;
+ m_crlEntryDetails = crlEntryDetails;
}
- public virtual CertTemplate CertDetails
- {
- get { return certDetails; }
- }
+ public virtual CertTemplate CertDetails => m_certDetails;
- public virtual X509Extensions CrlEntryDetails
- {
- get { return crlEntryDetails; }
- }
+ public virtual X509Extensions CrlEntryDetails => m_crlEntryDetails;
/**
*
@@ -69,8 +74,8 @@ public virtual X509Extensions CrlEntryDetails
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(certDetails);
- v.AddOptional(crlEntryDetails);
+ Asn1EncodableVector v = new Asn1EncodableVector(m_certDetails);
+ v.AddOptional(m_crlEntryDetails);
return new DerSequence(v);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContent.cs
index 95e6473..8f7f27f 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContent.cs
@@ -1,23 +1,45 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
- public class RevRepContent
+ /**
+ *
+ * RevRepContent ::= SEQUENCE {
+ * status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
+ * -- in same order as was sent in RevReqContent
+ * revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId
+ * OPTIONAL,
+ * -- IDs for which revocation was requested
+ * -- (same order as status)
+ * crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList OPTIONAL
+ * -- the resulting CRLs (there may be more than one)
+ * }
+ *
+ */
+ public class RevRepContent
: Asn1Encodable
{
- private readonly Asn1Sequence status;
- private readonly Asn1Sequence revCerts;
- private readonly Asn1Sequence crls;
+ public static RevRepContent GetInstance(object obj)
+ {
+ if (obj is RevRepContent revRepContent)
+ return revRepContent;
+
+ if (obj != null)
+ return new RevRepContent(Asn1Sequence.GetInstance(obj));
+
+ return null;
+ }
+
+ private readonly Asn1Sequence m_status;
+ private readonly Asn1Sequence m_revCerts;
+ private readonly Asn1Sequence m_crls;
private RevRepContent(Asn1Sequence seq)
{
- status = Asn1Sequence.GetInstance(seq[0]);
+ m_status = Asn1Sequence.GetInstance(seq[0]);
for (int pos = 1; pos < seq.Count; ++pos)
{
@@ -25,60 +47,34 @@ private RevRepContent(Asn1Sequence seq)
if (tObj.TagNo == 0)
{
- revCerts = Asn1Sequence.GetInstance(tObj, true);
+ m_revCerts = Asn1Sequence.GetInstance(tObj, true);
}
else
{
- crls = Asn1Sequence.GetInstance(tObj, true);
+ m_crls = Asn1Sequence.GetInstance(tObj, true);
}
}
}
- public static RevRepContent GetInstance(object obj)
- {
- if (obj is RevRepContent)
- return (RevRepContent)obj;
-
- if (obj is Asn1Sequence)
- return new RevRepContent((Asn1Sequence)obj);
-
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
-
public virtual PkiStatusInfo[] GetStatus()
{
- PkiStatusInfo[] results = new PkiStatusInfo[status.Count];
- for (int i = 0; i != results.Length; ++i)
- {
- results[i] = PkiStatusInfo.GetInstance(status[i]);
- }
- return results;
+ return m_status.MapElements(PkiStatusInfo.GetInstance);
}
public virtual CertId[] GetRevCerts()
{
- if (revCerts == null)
+ if (m_revCerts == null)
return null;
- CertId[] results = new CertId[revCerts.Count];
- for (int i = 0; i != results.Length; ++i)
- {
- results[i] = CertId.GetInstance(revCerts[i]);
- }
- return results;
+ return m_revCerts.MapElements(CertId.GetInstance);
}
public virtual CertificateList[] GetCrls()
{
- if (crls == null)
+ if (m_crls == null)
return null;
- CertificateList[] results = new CertificateList[crls.Count];
- for (int i = 0; i != results.Length; ++i)
- {
- results[i] = CertificateList.GetInstance(crls[i]);
- }
- return results;
+ return m_crls.MapElements(CertificateList.GetInstance);
}
/**
@@ -97,9 +93,9 @@ public virtual CertificateList[] GetCrls()
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(status);
- v.AddOptionalTagged(true, 0, revCerts);
- v.AddOptionalTagged(true, 1, crls);
+ Asn1EncodableVector v = new Asn1EncodableVector(m_status);
+ v.AddOptionalTagged(true, 0, m_revCerts);
+ v.AddOptionalTagged(true, 1, m_crls);
return new DerSequence(v);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContentBuilder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContentBuilder.cs
index 3d82c6f..15e8867 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContentBuilder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevRepContentBuilder.cs
@@ -9,29 +9,29 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
{
public class RevRepContentBuilder
{
- private readonly Asn1EncodableVector status = new Asn1EncodableVector();
- private readonly Asn1EncodableVector revCerts = new Asn1EncodableVector();
- private readonly Asn1EncodableVector crls = new Asn1EncodableVector();
+ private readonly Asn1EncodableVector m_status = new Asn1EncodableVector();
+ private readonly Asn1EncodableVector m_revCerts = new Asn1EncodableVector();
+ private readonly Asn1EncodableVector m_crls = new Asn1EncodableVector();
public virtual RevRepContentBuilder Add(PkiStatusInfo status)
{
- this.status.Add(status);
+ m_status.Add(status);
return this;
}
public virtual RevRepContentBuilder Add(PkiStatusInfo status, CertId certId)
{
- if (this.status.Count != this.revCerts.Count)
+ if (m_status.Count != m_revCerts.Count)
throw new InvalidOperationException("status and revCerts sequence must be in common order");
- this.status.Add(status);
- this.revCerts.Add(certId);
+ m_status.Add(status);
+ m_revCerts.Add(certId);
return this;
}
public virtual RevRepContentBuilder AddCrl(CertificateList crl)
{
- this.crls.Add(crl);
+ m_crls.Add(crl);
return this;
}
@@ -39,16 +39,16 @@ public virtual RevRepContent Build()
{
Asn1EncodableVector v = new Asn1EncodableVector();
- v.Add(new DerSequence(status));
+ v.Add(new DerSequence(m_status));
- if (revCerts.Count != 0)
+ if (m_revCerts.Count != 0)
{
- v.Add(new DerTaggedObject(true, 0, new DerSequence(revCerts)));
+ v.Add(new DerTaggedObject(true, 0, new DerSequence(m_revCerts)));
}
- if (crls.Count != 0)
+ if (m_crls.Count != 0)
{
- v.Add(new DerTaggedObject(true, 1, new DerSequence(crls)));
+ v.Add(new DerTaggedObject(true, 1, new DerSequence(m_crls)));
}
return RevRepContent.GetInstance(new DerSequence(v));
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevReqContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevReqContent.cs
index 8ac7dad..a7f61c9 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevReqContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RevReqContent.cs
@@ -9,37 +9,37 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
public class RevReqContent
: Asn1Encodable
{
- private readonly Asn1Sequence content;
-
- private RevReqContent(Asn1Sequence seq)
- {
- content = seq;
- }
+ public static RevReqContent GetInstance(object obj)
+ {
+ if (obj is RevReqContent revReqContent)
+ return revReqContent;
- public static RevReqContent GetInstance(object obj)
- {
- if (obj is RevReqContent)
- return (RevReqContent)obj;
+ if (obj != null)
+ return new RevReqContent(Asn1Sequence.GetInstance(obj));
- if (obj is Asn1Sequence)
- return new RevReqContent((Asn1Sequence)obj);
+ return null;
+ }
- throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ private readonly Asn1Sequence m_content;
+
+ private RevReqContent(Asn1Sequence seq)
+ {
+ m_content = seq;
}
- public RevReqContent(params RevDetails[] revDetails)
+ public RevReqContent(RevDetails revDetails)
+ {
+ m_content = new DerSequence(revDetails);
+ }
+
+ public RevReqContent(params RevDetails[] revDetailsArray)
{
- this.content = new DerSequence(revDetails);
+ m_content = new DerSequence(revDetailsArray);
}
public virtual RevDetails[] ToRevDetailsArray()
{
- RevDetails[] result = new RevDetails[content.Count];
- for (int i = 0; i != result.Length; ++i)
- {
- result[i] = RevDetails.GetInstance(content[i]);
- }
- return result;
+ return m_content.MapElements(RevDetails.GetInstance);
}
/**
@@ -50,7 +50,7 @@ public virtual RevDetails[] ToRevDetailsArray()
*/
public override Asn1Object ToAsn1Object()
{
- return content;
+ return m_content;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RootCaKeyUpdateContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RootCaKeyUpdateContent.cs
new file mode 100644
index 0000000..53080c1
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/cmp/RootCaKeyUpdateContent.cs
@@ -0,0 +1,95 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp
+{
+ /**
+ * GenMsg: {id-it 20}, RootCaCertValue | < absent >
+ * GenRep: {id-it 18}, RootCaKeyUpdateContent | < absent >
+ *
* DSTU4145 in polynomial basis has 2 oids, one for little-endian representation and one for big-endian
*/
public abstract class UAObjectIdentifiers
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/Asn1Dump.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/Asn1Dump.cs
index 4167789..8df74b1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/Asn1Dump.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/Asn1Dump.cs
@@ -4,19 +4,12 @@
using System.IO;
using System.Text;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Utilities
{
- public sealed class Asn1Dump
+ public static class Asn1Dump
{
- private static readonly string NewLine = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
-
- private Asn1Dump()
- {
- }
-
private const string Tab = " ";
private const int SampleSize = 32;
@@ -25,243 +18,252 @@ private Asn1Dump()
*
* @param obj the Asn1Object to be dumped out.
*/
- private static void AsString(
- string indent,
- bool verbose,
- Asn1Object obj,
- StringBuilder buf)
+ private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf)
{
if (obj is Asn1Null)
{
buf.Append(indent);
- buf.Append("NULL");
- buf.Append(NewLine);
+ buf.AppendLine("NULL");
}
- else if (obj is Asn1Sequence)
+ else if (obj is Asn1Sequence asn1Sequence)
{
buf.Append(indent);
- if (obj is BerSequence)
+
+ if (asn1Sequence is BerSequence)
{
- buf.Append("BER Sequence");
+ buf.AppendLine("BER Sequence");
}
- else if (obj is DerSequence)
+ else if (!(asn1Sequence is DLSequence))
{
- buf.Append("DER Sequence");
+ buf.AppendLine("DER Sequence");
}
else
{
- buf.Append("Sequence");
+ buf.AppendLine("Sequence");
}
- buf.Append(NewLine);
- Asn1Sequence sequence = (Asn1Sequence)obj;
string elementsIndent = indent + Tab;
- for (int i = 0, count = sequence.Count; i < count; ++i)
+ for (int i = 0, count = asn1Sequence.Count; i < count; ++i)
{
- AsString(elementsIndent, verbose, sequence[i].ToAsn1Object(), buf);
+ AsString(elementsIndent, verbose, asn1Sequence[i].ToAsn1Object(), buf);
}
}
- else if (obj is Asn1Set)
+ else if (obj is Asn1Set asn1Set)
{
buf.Append(indent);
- if (obj is BerSet)
+
+ if (asn1Set is BerSet)
{
- buf.Append("BER Set");
+ buf.AppendLine("BER Set");
+ }
+ else if (!(asn1Set is DLSet))
+ {
+ buf.AppendLine("DER Set");
+ }
+ else
+ {
+ buf.AppendLine("Set");
}
- else if (obj is DerSet)
- {
- buf.Append("DER Set");
- }
- else
- {
- buf.Append("Set");
- }
- buf.Append(NewLine);
- Asn1Set set = (Asn1Set)obj;
string elementsIndent = indent + Tab;
- for (int i = 0, count = set.Count; i < count; ++i)
+ for (int i = 0, count = asn1Set.Count; i < count; ++i)
{
- AsString(elementsIndent, verbose, set[i].ToAsn1Object(), buf);
+ AsString(elementsIndent, verbose, asn1Set[i].ToAsn1Object(), buf);
}
}
- else if (obj is Asn1TaggedObject)
+ else if (obj is Asn1TaggedObject taggedObject)
{
- string tab = indent + Tab;
buf.Append(indent);
- if (obj is BerTaggedObject)
+
+ if (taggedObject is BerTaggedObject)
+ {
+ buf.Append("BER Tagged ");
+ }
+ else if (!(taggedObject is DLTaggedObject))
{
- buf.Append("BER Tagged [");
+ buf.Append("DER Tagged ");
}
else
{
- buf.Append("Tagged [");
+ buf.Append("Tagged ");
}
- Asn1TaggedObject o = (Asn1TaggedObject)obj;
+ buf.Append(Asn1Utilities.GetTagText(taggedObject));
- buf.Append(o.TagNo.ToString());
- buf.Append(']');
-
- if (!o.IsExplicit())
+ if (!taggedObject.IsExplicit())
{
buf.Append(" IMPLICIT ");
}
- buf.Append(NewLine);
+ buf.AppendLine();
- if (o.IsEmpty())
- {
- buf.Append(tab);
- buf.Append("EMPTY");
- buf.Append(NewLine);
- }
- else
- {
- AsString(tab, verbose, o.GetObject(), buf);
- }
- }
- else if (obj is DerObjectIdentifier)
- {
- buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine);
- }
- else if (obj is DerBoolean)
- {
- buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine);
+ string baseIndent = indent + Tab;
+
+ AsString(baseIndent, verbose, taggedObject.GetBaseObject().ToAsn1Object(), buf);
}
- else if (obj is DerInteger)
+ else if (obj is DerObjectIdentifier oid)
{
- buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("ObjectIdentifier(" + oid.Id + ")");
}
- else if (obj is BerOctetString)
+ else if (obj is Asn1RelativeOid relativeOid)
{
- byte[] octets = ((Asn1OctetString)obj).GetOctets();
- string extra = verbose ? dumpBinaryDataAsString(indent, octets) : Hex.ToHexString(octets);
- buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("RelativeOID(" + relativeOid.Id + ")");
}
- else if (obj is DerOctetString)
+ else if (obj is DerBoolean derBoolean)
{
- byte[] octets = ((Asn1OctetString)obj).GetOctets();
- string extra = verbose ? dumpBinaryDataAsString(indent, octets) : Hex.ToHexString(octets);
- buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("Boolean(" + derBoolean.IsTrue + ")");
}
- else if (obj is DerBitString)
+ else if (obj is DerInteger derInteger)
{
- DerBitString bt = (DerBitString)obj;
- byte[] bytes = bt.GetBytes();
- string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : "";
- buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("Integer(" + derInteger.Value + ")");
}
- else if (obj is DerIA5String)
+ else if (obj is Asn1OctetString oct)
{
- buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine);
+ byte[] octets = oct.GetOctets();
+
+ buf.Append(indent);
+
+ if (obj is BerOctetString)
+ {
+ buf.AppendLine("BER Octet String[" + octets.Length + "]");
+ }
+ else
+ {
+ buf.AppendLine("DER Octet String[" + octets.Length + "]");
+ }
+
+ if (verbose)
+ {
+ DumpBinaryDataAsString(buf, indent, octets);
+ }
}
- else if (obj is DerUtf8String)
+ else if (obj is DerBitString bitString)
{
- buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine);
+ byte[] bytes = bitString.GetBytes();
+ int padBits = bitString.PadBits;
+
+ buf.Append(indent);
+
+ if (bitString is BerBitString)
+ {
+ buf.AppendLine("BER Bit String[" + bytes.Length + ", " + padBits + "]");
+ }
+ else if (bitString is DLBitString)
+ {
+ buf.AppendLine("DL Bit String[" + bytes.Length + ", " + padBits + "]");
+ }
+ else
+ {
+ buf.AppendLine("DER Bit String[" + bytes.Length + ", " + padBits + "]");
+ }
+
+ if (verbose)
+ {
+ DumpBinaryDataAsString(buf, indent, bytes);
+ }
}
- else if (obj is DerPrintableString)
+ else if (obj is DerIA5String ia5String)
{
- buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("IA5String(" + ia5String.GetString() + ")");
}
- else if (obj is DerVisibleString)
+ else if (obj is DerUtf8String utf8String)
{
- buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("UTF8String(" + utf8String.GetString() + ")");
}
- else if (obj is DerBmpString)
+ else if (obj is DerPrintableString printableString)
{
- buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("PrintableString(" + printableString.GetString() + ")");
}
- else if (obj is DerT61String)
+ else if (obj is DerVisibleString visibleString)
{
- buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("VisibleString(" + visibleString.GetString() + ")");
}
- else if (obj is DerGraphicString)
+ else if (obj is DerBmpString bmpString)
{
- buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("BMPString(" + bmpString.GetString() + ")");
}
- else if (obj is DerVideotexString)
+ else if (obj is DerT61String t61String)
{
- buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("T61String(" + t61String.GetString() + ")");
}
- else if (obj is DerUtcTime)
+ else if (obj is DerGraphicString graphicString)
{
- buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("GraphicString(" + graphicString.GetString() + ")");
}
- else if (obj is DerGeneralizedTime)
+ else if (obj is DerVideotexString videotexString)
{
- buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("VideotexString(" + videotexString.GetString() + ")");
}
- else if (obj is BerApplicationSpecific)
+ else if (obj is Asn1UtcTime utcTime)
{
- buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
+ buf.Append(indent);
+ buf.AppendLine("UTCTime(" + utcTime.TimeString + ")");
}
- else if (obj is DerApplicationSpecific)
+ else if (obj is Asn1GeneralizedTime generalizedTime)
{
- buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
+ buf.Append(indent);
+ buf.AppendLine("GeneralizedTime(" + generalizedTime.TimeString + ")");
}
- else if (obj is DerEnumerated)
+ else if (obj is DerEnumerated en)
{
- DerEnumerated en = (DerEnumerated)obj;
- buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("DER Enumerated(" + en.Value + ")");
}
- else if (obj is DerExternal)
+ else if (obj is DerExternal ext)
{
- DerExternal ext = (DerExternal)obj;
- buf.Append(indent + "External " + NewLine);
+ buf.Append(indent);
+ buf.AppendLine("External ");
string tab = indent + Tab;
if (ext.DirectReference != null)
{
- buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine);
+ buf.Append(tab);
+ buf.AppendLine("Direct Reference: " + ext.DirectReference.Id);
}
if (ext.IndirectReference != null)
{
- buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine);
+ buf.Append(tab);
+ buf.AppendLine("Indirect Reference: " + ext.IndirectReference.ToString());
}
if (ext.DataValueDescriptor != null)
{
AsString(tab, verbose, ext.DataValueDescriptor, buf);
}
- buf.Append(tab + "Encoding: " + ext.Encoding + NewLine);
+ buf.Append(tab);
+ buf.AppendLine("Encoding: " + ext.Encoding);
AsString(tab, verbose, ext.ExternalContent, buf);
}
else
{
- buf.Append(indent + obj.ToString() + NewLine);
+ buf.Append(indent);
+ buf.Append(obj);
+ buf.AppendLine();
}
}
- private static string outputApplicationSpecific(
- string type,
- string indent,
- bool verbose,
- DerApplicationSpecific app)
+ /// Parse ASN.1 objects from input , and write them to the output.
+ public static void Dump(Stream input, TextWriter output)
{
- StringBuilder buf = new StringBuilder();
-
- if (app.IsConstructed())
+ Asn1InputStream asn1InputStream = new Asn1InputStream(input);
+ Asn1Object asn1Object;
+ while ((asn1Object = asn1InputStream.ReadObject()) != null)
{
- try
- {
- Asn1Sequence s = Asn1Sequence.GetInstance(app.GetObject(Asn1Tags.Sequence));
- buf.Append(indent + type + " ApplicationSpecific[" + app.ApplicationTag + "]" + NewLine);
- foreach (Asn1Encodable ae in s)
- {
- AsString(indent + Tab, verbose, ae.ToAsn1Object(), buf);
- }
- }
- catch (IOException e)
- {
- buf.Append(e);
- }
- return buf.ToString();
+ output.Write(DumpAsString(asn1Object));
}
-
- return indent + type + " ApplicationSpecific[" + app.ApplicationTag + "] ("
- + Hex.ToHexString(app.GetContents()) + ")" + NewLine;
}
/**
@@ -270,8 +272,7 @@ private static string outputApplicationSpecific(
* @param obj the Asn1Encodable to be dumped out.
* @return the resulting string.
*/
- public static string DumpAsString(
- Asn1Encodable obj)
+ public static string DumpAsString(Asn1Encodable obj)
{
return DumpAsString(obj, false);
}
@@ -283,55 +284,39 @@ public static string DumpAsString(
* @param verbose if true, dump out the contents of octet and bit strings.
* @return the resulting string.
*/
- public static string DumpAsString(
- Asn1Encodable obj,
- bool verbose)
+ public static string DumpAsString(Asn1Encodable obj, bool verbose)
{
StringBuilder buf = new StringBuilder();
AsString("", verbose, obj.ToAsn1Object(), buf);
return buf.ToString();
}
- private static string dumpBinaryDataAsString(string indent, byte[] bytes)
+ private static void DumpBinaryDataAsString(StringBuilder buf, string indent, byte[] bytes)
{
- indent += Tab;
+ if (bytes.Length < 1)
+ return;
- StringBuilder buf = new StringBuilder(NewLine);
+ indent += Tab;
for (int i = 0; i < bytes.Length; i += SampleSize)
{
- if (bytes.Length - i > SampleSize)
- {
- buf.Append(indent);
- buf.Append(Hex.ToHexString(bytes, i, SampleSize));
- buf.Append(Tab);
- buf.Append(calculateAscString(bytes, i, SampleSize));
- buf.Append(NewLine);
- }
- else
+ int remaining = bytes.Length - i;
+ int chunk = System.Math.Min(remaining, SampleSize);
+
+ buf.Append(indent);
+ buf.Append(Hex.ToHexString(bytes, i, chunk));
+ for (int j = chunk; j < SampleSize; ++j)
{
- buf.Append(indent);
- buf.Append(Hex.ToHexString(bytes, i, bytes.Length - i));
- for (int j = bytes.Length - i; j != SampleSize; j++)
- {
- buf.Append(" ");
- }
- buf.Append(Tab);
- buf.Append(calculateAscString(bytes, i, bytes.Length - i));
- buf.Append(NewLine);
+ buf.Append(" ");
}
+ buf.Append(Tab);
+ AppendAscString(buf, bytes, i, chunk);
+ buf.AppendLine();
}
-
- return buf.ToString();
}
- private static string calculateAscString(
- byte[] bytes,
- int off,
- int len)
+ private static void AppendAscString(StringBuilder buf, byte[] bytes, int off, int len)
{
- StringBuilder buf = new StringBuilder();
-
for (int i = off; i != off + len; i++)
{
char c = (char)bytes[i];
@@ -340,8 +325,6 @@ private static string calculateAscString(
buf.Append(c);
}
}
-
- return buf.ToString();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs
index 8b6aa38..0454b34 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs
@@ -1,87 +1,3 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
-#pragma warning disable
-using System;
-using System.IO;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
-namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Utilities
-{
-
- public class FilterStream : Stream
- {
-
- public FilterStream(Stream s)
- {
- this.s = s;
- }
- public override bool CanRead
- {
- get { return s.CanRead; }
- }
- public override bool CanSeek
- {
- get { return s.CanSeek; }
- }
- public override bool CanWrite
- {
- get { return s.CanWrite; }
- }
- public override long Length
- {
- get { return s.Length; }
- }
- public override long Position
- {
- get { return s.Position; }
- set { s.Position = value; }
- }
-#if PORTABLE || NETFX_CORE
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(s);
- }
- base.Dispose(disposing);
- }
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(s);
- base.Close();
- }
-#endif
- public override void Flush()
- {
- s.Flush();
- }
- public override long Seek(long offset, SeekOrigin origin)
- {
- return s.Seek(offset, origin);
- }
- public override void SetLength(long value)
- {
- s.SetLength(value);
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- return s.Read(buffer, offset, count);
- }
- public override int ReadByte()
- {
- return s.ReadByte();
- }
- public override void Write(byte[] buffer, int offset, int count)
- {
- s.Write(buffer, offset, count);
- }
- public override void WriteByte(byte value)
- {
- s.WriteByte(value);
- }
- protected readonly Stream s;
- }
-}
-#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs.meta
index 7871a25..4c3c298 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs.meta
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/util/FilterStream.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: ecc1ac8ab2a920c418f97b8619491c2a
+guid: 2bdac595e49fdea498ef77f610df00fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/DirectoryString.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/DirectoryString.cs
index 6535a93..f336f5c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/DirectoryString.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/DirectoryString.cs
@@ -28,7 +28,7 @@ public static DirectoryString GetInstance(object obj)
}
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static DirectoryString GetInstance(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/style/IetfUtilities.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/style/IetfUtilities.cs
index 3b0cd11..e6bc456 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/style/IetfUtilities.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x500/style/IetfUtilities.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using System.Text;
@@ -96,15 +95,15 @@ public static string ValueToString(Asn1Encodable value)
public static string Canonicalize(string s)
{
- string value = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToLowerInvariant(s);
+ string value = s.ToLowerInvariant();
if (value.Length > 0 && value[0] == '#')
{
Asn1Object obj = DecodeObject(value);
- if (obj is IAsn1String)
+ if (obj is IAsn1String str)
{
- value = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToLowerInvariant(((IAsn1String)obj).GetString());
+ value = str.GetString().ToLowerInvariant();
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AccessDescription.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AccessDescription.cs
index ccdd01a..3ac4ef7 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AccessDescription.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AccessDescription.cs
@@ -32,7 +32,7 @@ public static AccessDescription GetInstance(
if (obj is Asn1Sequence)
return new AccessDescription((Asn1Sequence) obj);
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private AccessDescription(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AlgorithmIdentifier.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AlgorithmIdentifier.cs
index 8dd3e77..7be4643 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AlgorithmIdentifier.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AlgorithmIdentifier.cs
@@ -33,13 +33,6 @@ public AlgorithmIdentifier(
this.algorithm = algorithm;
}
-
- public AlgorithmIdentifier(
- string algorithm)
- {
- this.algorithm = new DerObjectIdentifier(algorithm);
- }
-
public AlgorithmIdentifier(
DerObjectIdentifier algorithm,
Asn1Encodable parameters)
@@ -66,12 +59,6 @@ public virtual DerObjectIdentifier Algorithm
get { return algorithm; }
}
-
- public virtual DerObjectIdentifier ObjectID
- {
- get { return algorithm; }
- }
-
///
/// Return the parameters structure in the Parameters entry of this identifier.
///
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertIssuer.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertIssuer.cs
index 60a068f..6973bde 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertIssuer.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertIssuer.cs
@@ -36,7 +36,7 @@ public static AttCertIssuer GetInstance(
return new AttCertIssuer(GeneralNames.GetInstance(obj));
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static AttCertIssuer GetInstance(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertValidityPeriod.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertValidityPeriod.cs
index a54321e..2550488 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertValidityPeriod.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttCertValidityPeriod.cs
@@ -9,8 +9,8 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
public class AttCertValidityPeriod
: Asn1Encodable
{
- private readonly DerGeneralizedTime notBeforeTime;
- private readonly DerGeneralizedTime notAfterTime;
+ private readonly Asn1GeneralizedTime notBeforeTime;
+ private readonly Asn1GeneralizedTime notAfterTime;
public static AttCertValidityPeriod GetInstance(
object obj)
@@ -25,7 +25,7 @@ public static AttCertValidityPeriod GetInstance(
return new AttCertValidityPeriod((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static AttCertValidityPeriod GetInstance(
@@ -41,24 +41,24 @@ private AttCertValidityPeriod(
if (seq.Count != 2)
throw new ArgumentException("Bad sequence size: " + seq.Count);
- notBeforeTime = DerGeneralizedTime.GetInstance(seq[0]);
- notAfterTime = DerGeneralizedTime.GetInstance(seq[1]);
+ notBeforeTime = Asn1GeneralizedTime.GetInstance(seq[0]);
+ notAfterTime = Asn1GeneralizedTime.GetInstance(seq[1]);
}
public AttCertValidityPeriod(
- DerGeneralizedTime notBeforeTime,
- DerGeneralizedTime notAfterTime)
+ Asn1GeneralizedTime notBeforeTime,
+ Asn1GeneralizedTime notAfterTime)
{
this.notBeforeTime = notBeforeTime;
this.notAfterTime = notAfterTime;
}
- public DerGeneralizedTime NotBeforeTime
+ public Asn1GeneralizedTime NotBeforeTime
{
get { return notBeforeTime; }
}
- public DerGeneralizedTime NotAfterTime
+ public Asn1GeneralizedTime NotAfterTime
{
get { return notAfterTime; }
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Attribute.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Attribute.cs
index e175a49..578bcd8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Attribute.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Attribute.cs
@@ -31,7 +31,7 @@ public static AttributeX509 GetInstance(
return new AttributeX509((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private AttributeX509(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeCertificateInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeCertificateInfo.cs
index 85b185f..8390d86 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeCertificateInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeCertificateInfo.cs
@@ -39,7 +39,7 @@ public static AttributeCertificateInfo GetInstance(
return new AttributeCertificateInfo((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private AttributeCertificateInfo(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeTable.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeTable.cs
index bb21878..5d7f921 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeTable.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AttributeTable.cs
@@ -1,75 +1,52 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
public class AttributeTable
{
- private readonly IDictionary attributes;
+ private readonly IDictionary m_attributes;
- public AttributeTable(
- IDictionary attrs)
+ public AttributeTable(IDictionary attrs)
{
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(attrs);
+ m_attributes = new Dictionary(attrs);
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- [Obsolete]
- public AttributeTable(
- Hashtable attrs)
+ public AttributeTable(Asn1EncodableVector v)
{
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(attrs);
- }
-#endif
+ m_attributes = new Dictionary(v.Count);
- public AttributeTable(
- Asn1EncodableVector v)
- {
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(v.Count);
-
- for (int i = 0; i != v.Count; i++)
+ for (int i = 0; i != v.Count; i++)
{
AttributeX509 a = AttributeX509.GetInstance(v[i]);
- attributes.Add(a.AttrType, a);
+ m_attributes.Add(a.AttrType, a);
}
}
- public AttributeTable(
- Asn1Set s)
+ public AttributeTable(Asn1Set s)
{
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(s.Count);
+ m_attributes = new Dictionary(s.Count);
- for (int i = 0; i != s.Count; i++)
+ for (int i = 0; i != s.Count; i++)
{
AttributeX509 a = AttributeX509.GetInstance(s[i]);
- attributes.Add(a.AttrType, a);
+ m_attributes.Add(a.AttrType, a);
}
}
- public AttributeX509 Get(
- DerObjectIdentifier oid)
+ public AttributeX509 Get(DerObjectIdentifier oid)
{
- return (AttributeX509) attributes[oid];
+ return CollectionUtilities.GetValueOrNull(m_attributes, oid);
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
-
- public Hashtable ToHashtable()
- {
- return new Hashtable(attributes);
- }
-#endif
-
- public IDictionary ToDictionary()
+ public IDictionary ToDictionary()
{
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(attributes);
+ return new Dictionary(m_attributes);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityInformationAccess.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityInformationAccess.cs
index 7e01c9c..9a9a0e3 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityInformationAccess.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityInformationAccess.cs
@@ -1,10 +1,8 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.Text;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
@@ -98,18 +96,13 @@ public override string ToString()
//return "AuthorityInformationAccess: Oid(" + this.descriptions[0].AccessMethod.Id + ")";
StringBuilder buf = new StringBuilder();
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
-
- buf.Append("AuthorityInformationAccess:");
- buf.Append(sep);
-
+ buf.AppendLine("AuthorityInformationAccess:");
foreach (AccessDescription description in descriptions)
{
- buf.Append(" ");
- buf.Append(description);
- buf.Append(sep);
+ buf.Append(" ")
+ .Append(description)
+ .AppendLine();
}
-
return buf.ToString();
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityKeyIdentifier.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityKeyIdentifier.cs
index 3b632e5..9be2163 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityKeyIdentifier.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/AuthorityKeyIdentifier.cs
@@ -1,12 +1,10 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CRLDistPoint.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CRLDistPoint.cs
index e2d8688..b8b2e7a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CRLDistPoint.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CRLDistPoint.cs
@@ -74,16 +74,12 @@ public override Asn1Object ToAsn1Object()
public override string ToString()
{
StringBuilder buf = new StringBuilder();
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
-
- buf.Append("CRLDistPoint:");
- buf.Append(sep);
- DistributionPoint[] dp = GetDistributionPoints();
- for (int i = 0; i != dp.Length; i++)
+ buf.AppendLine("CRLDistPoint:");
+ foreach (DistributionPoint dp in GetDistributionPoints())
{
- buf.Append(" ");
- buf.Append(dp[i]);
- buf.Append(sep);
+ buf.Append(" ")
+ .Append(dp)
+ .AppendLine();
}
return buf.ToString();
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificateList.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificateList.cs
index 6d4b814..e2f6509 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificateList.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificateList.cs
@@ -1,9 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
+using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
@@ -67,7 +65,7 @@ public CrlEntry[] GetRevokedCertificates()
return tbsCertList.GetRevokedCertificates();
}
- public IEnumerable GetRevokedCertificateEnumeration()
+ public IEnumerable GetRevokedCertificateEnumeration()
{
return tbsCertList.GetRevokedCertificateEnumeration();
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificatePair.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificatePair.cs
index 1f50468..66cb3f8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificatePair.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/CertificatePair.cs
@@ -57,7 +57,7 @@ public static CertificatePair GetInstance(
return new CertificatePair((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DSAParameter.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DSAParameter.cs
index 42cfcf9..ca9d721 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DSAParameter.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DSAParameter.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -33,7 +32,7 @@ public static DsaParameter GetInstance(
return new DsaParameter((Asn1Sequence) obj);
}
- throw new ArgumentException("Invalid DsaParameter: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("Invalid DsaParameter: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
public DsaParameter(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DigestInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DigestInfo.cs
index 5fa8601..92c70d1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DigestInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DigestInfo.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -41,7 +40,7 @@ public static DigestInfo GetInstance(
return new DigestInfo((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public DigestInfo(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DisplayText.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DisplayText.cs
index f5cebd2..7dabc51 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DisplayText.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DisplayText.cs
@@ -155,7 +155,7 @@ public static DisplayText GetInstance(
return (DisplayText) obj;
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public override Asn1Object ToAsn1Object()
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPoint.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPoint.cs
index c6b2769..48ece19 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPoint.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPoint.cs
@@ -44,7 +44,7 @@ public static DistributionPoint GetInstance(
return new DistributionPoint((Asn1Sequence) obj);
}
- throw new ArgumentException("Invalid DistributionPoint: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("Invalid DistributionPoint: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
private DistributionPoint(
@@ -108,43 +108,34 @@ public override Asn1Object ToAsn1Object()
public override string ToString()
{
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
StringBuilder buf = new StringBuilder();
- buf.Append("DistributionPoint: [");
- buf.Append(sep);
+ buf.AppendLine("DistributionPoint: [");
if (distributionPoint != null)
{
- appendObject(buf, sep, "distributionPoint", distributionPoint.ToString());
+ AppendObject(buf, "distributionPoint", distributionPoint.ToString());
}
if (reasons != null)
{
- appendObject(buf, sep, "reasons", reasons.ToString());
+ AppendObject(buf, "reasons", reasons.ToString());
}
if (cRLIssuer != null)
{
- appendObject(buf, sep, "cRLIssuer", cRLIssuer.ToString());
+ AppendObject(buf, "cRLIssuer", cRLIssuer.ToString());
}
- buf.Append("]");
- buf.Append(sep);
+ buf.AppendLine("]");
return buf.ToString();
}
- private void appendObject(
- StringBuilder buf,
- string sep,
- string name,
- string val)
+ private void AppendObject(StringBuilder buf, string name, string val)
{
string indent = " ";
-
buf.Append(indent);
buf.Append(name);
- buf.Append(":");
- buf.Append(sep);
+ buf.AppendLine(":");
buf.Append(indent);
buf.Append(indent);
buf.Append(val);
- buf.Append(sep);
+ buf.AppendLine();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPointName.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPointName.cs
index b100750..32e8d6c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPointName.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/DistributionPointName.cs
@@ -45,7 +45,7 @@ public static DistributionPointName GetInstance(
return new DistributionPointName((Asn1TaggedObject) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public DistributionPointName(
@@ -94,41 +94,32 @@ public override Asn1Object ToAsn1Object()
public override string ToString()
{
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
StringBuilder buf = new StringBuilder();
- buf.Append("DistributionPointName: [");
- buf.Append(sep);
+ buf.AppendLine("DistributionPointName: [");
if (type == FullName)
{
- appendObject(buf, sep, "fullName", name.ToString());
+ AppendObject(buf, "fullName", name.ToString());
}
else
{
- appendObject(buf, sep, "nameRelativeToCRLIssuer", name.ToString());
+ AppendObject(buf, "nameRelativeToCRLIssuer", name.ToString());
}
- buf.Append("]");
- buf.Append(sep);
+ buf.AppendLine("]");
return buf.ToString();
}
- private void appendObject(
- StringBuilder buf,
- string sep,
- string name,
- string val)
+ private void AppendObject(StringBuilder buf, string name, string val)
{
string indent = " ";
-
buf.Append(indent);
buf.Append(name);
- buf.Append(":");
- buf.Append(sep);
+ buf.AppendLine(":");
buf.Append(indent);
buf.Append(indent);
buf.Append(val);
- buf.Append(sep);
- }
- }
+ buf.AppendLine();
+ }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ExtendedKeyUsage.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ExtendedKeyUsage.cs
index da302e3..bde2923 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ExtendedKeyUsage.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ExtendedKeyUsage.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -40,11 +40,10 @@ public static ExtendedKeyUsage FromExtensions(X509Extensions extensions)
return GetInstance(X509Extensions.GetExtensionParsedValue(extensions, X509Extensions.ExtendedKeyUsage));
}
- internal readonly IDictionary usageTable = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ internal readonly ISet m_usageTable = new HashSet();
internal readonly Asn1Sequence seq;
- private ExtendedKeyUsage(
- Asn1Sequence seq)
+ private ExtendedKeyUsage(Asn1Sequence seq)
{
this.seq = seq;
@@ -52,32 +51,21 @@ private ExtendedKeyUsage(
{
DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(element);
- this.usageTable[oid] = oid;
+ m_usageTable.Add(oid);
}
}
- public ExtendedKeyUsage(
- params KeyPurposeID[] usages)
+ public ExtendedKeyUsage(params KeyPurposeID[] usages)
{
this.seq = new DerSequence(usages);
foreach (KeyPurposeID usage in usages)
{
- this.usageTable[usage] = usage;
+ m_usageTable.Add(usage);
}
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- [Obsolete]
- public ExtendedKeyUsage(
- ArrayList usages)
- : this((IEnumerable)usages)
- {
- }
-#endif
-
- public ExtendedKeyUsage(
- IEnumerable usages)
+ public ExtendedKeyUsage(IEnumerable usages)
{
Asn1EncodableVector v = new Asn1EncodableVector();
@@ -86,39 +74,30 @@ public ExtendedKeyUsage(
DerObjectIdentifier oid = DerObjectIdentifier.GetInstance(usage);
v.Add(oid);
- this.usageTable[oid] = oid;
+ m_usageTable.Add(oid);
}
this.seq = new DerSequence(v);
}
- public bool HasKeyPurposeId(
- KeyPurposeID keyPurposeId)
+ public bool HasKeyPurposeId(KeyPurposeID keyPurposeId)
{
- return usageTable.Contains(keyPurposeId);
+ return m_usageTable.Contains(keyPurposeId);
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
-
- public ArrayList GetUsages()
- {
- return new ArrayList(usageTable.Values);
- }
-#endif
-
/**
* Returns all extended key usages.
* The returned ArrayList contains DerObjectIdentifier instances.
* @return An ArrayList with all key purposes.
*/
- public IList GetAllUsages()
+ public IList GetAllUsages()
{
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(usageTable.Values);
+ return new List(m_usageTable);
}
public int Count
{
- get { return usageTable.Count; }
+ get { return m_usageTable.Count; }
}
public override Asn1Object ToAsn1Object()
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralName.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralName.cs
index 47376a7..7999ae8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralName.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralName.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
@@ -206,7 +206,7 @@ public static GeneralName GetInstance(
}
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static GeneralName GetInstance(
@@ -321,7 +321,7 @@ private byte[] toGeneralNameEncoding(
private void parseIPv4Mask(string mask, byte[] addr, int offset)
{
- int maskVal = Int32.Parse(mask);
+ int maskVal = int.Parse(mask);
for (int i = 0; i != maskVal; i++)
{
@@ -333,14 +333,14 @@ private void parseIPv4(string ip, byte[] addr, int offset)
{
foreach (string token in ip.Split('.', '/'))
{
- addr[offset++] = (byte)Int32.Parse(token);
+ addr[offset++] = (byte)int.Parse(token);
}
}
private int[] parseMask(string mask)
{
int[] res = new int[8];
- int maskVal = Int32.Parse(mask);
+ int maskVal = int.Parse(mask);
for (int i = 0; i != maskVal; i++)
{
@@ -360,16 +360,17 @@ private void copyInts(int[] parsedIp, byte[] addr, int offSet)
private int[] parseIPv6(string ip)
{
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(ip, "::"))
+ if (Org.BouncyCastle.Utilities.Platform.StartsWith(ip, "::"))
{
ip = ip.Substring(1);
}
- else if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EndsWith(ip, "::"))
+ else if (Org.BouncyCastle.Utilities.Platform.EndsWith(ip, "::"))
{
ip = ip.Substring(0, ip.Length - 1);
}
- IEnumerator sEnum = ip.Split(':').GetEnumerator();
+ IEnumerable split = ip.Split(':');
+ var sEnum = split.GetEnumerator();
int index = 0;
int[] val = new int[8];
@@ -378,7 +379,7 @@ private int[] parseIPv6(string ip)
while (sEnum.MoveNext())
{
- string e = (string) sEnum.Current;
+ string e = sEnum.Current;
if (e.Length == 0)
{
@@ -389,14 +390,14 @@ private int[] parseIPv6(string ip)
{
if (e.IndexOf('.') < 0)
{
- val[index++] = Int32.Parse(e, NumberStyles.AllowHexSpecifier);
+ val[index++] = int.Parse(e, NumberStyles.AllowHexSpecifier);
}
else
{
string[] tokens = e.Split('.');
- val[index++] = (Int32.Parse(tokens[0]) << 8) | Int32.Parse(tokens[1]);
- val[index++] = (Int32.Parse(tokens[2]) << 8) | Int32.Parse(tokens[3]);
+ val[index++] = (int.Parse(tokens[0]) << 8) | int.Parse(tokens[1]);
+ val[index++] = (int.Parse(tokens[2]) << 8) | int.Parse(tokens[3]);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralNames.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralNames.cs
index 6c55512..326cbbc 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralNames.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/GeneralNames.cs
@@ -80,18 +80,13 @@ public override Asn1Object ToAsn1Object()
public override string ToString()
{
StringBuilder buf = new StringBuilder();
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
-
- buf.Append("GeneralNames:");
- buf.Append(sep);
-
+ buf.AppendLine("GeneralNames:");
foreach (GeneralName name in names)
{
- buf.Append(" ");
- buf.Append(name);
- buf.Append(sep);
+ buf.Append(" ")
+ .Append(name)
+ .AppendLine();
}
-
return buf.ToString();
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Holder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Holder.cs
index 3f6e160..c6d7a14 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Holder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Holder.cs
@@ -62,7 +62,7 @@ public static Holder GetInstance(
return new Holder((Asn1TaggedObject) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IetfAttrSyntax.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IetfAttrSyntax.cs
index bd4a318..3feebc4 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IetfAttrSyntax.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IetfAttrSyntax.cs
@@ -1,9 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuerSerial.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuerSerial.cs
index 5d05ec1..549c25b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuerSerial.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuerSerial.cs
@@ -26,7 +26,7 @@ public static IssuerSerial GetInstance(
return new IssuerSerial((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static IssuerSerial GetInstance(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuingDistributionPoint.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuingDistributionPoint.cs
index 7acae10..7f58f7e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuingDistributionPoint.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/IssuingDistributionPoint.cs
@@ -50,7 +50,7 @@ public static IssuingDistributionPoint GetInstance(
return new IssuingDistributionPoint((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
@@ -194,56 +194,46 @@ public override Asn1Object ToAsn1Object()
public override string ToString()
{
- string sep = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
StringBuilder buf = new StringBuilder();
-
- buf.Append("IssuingDistributionPoint: [");
- buf.Append(sep);
+ buf.AppendLine("IssuingDistributionPoint: [");
if (_distributionPoint != null)
{
- appendObject(buf, sep, "distributionPoint", _distributionPoint.ToString());
+ AppendObject(buf, "distributionPoint", _distributionPoint.ToString());
}
if (_onlyContainsUserCerts)
{
- appendObject(buf, sep, "onlyContainsUserCerts", _onlyContainsUserCerts.ToString());
+ AppendObject(buf, "onlyContainsUserCerts", _onlyContainsUserCerts.ToString());
}
if (_onlyContainsCACerts)
{
- appendObject(buf, sep, "onlyContainsCACerts", _onlyContainsCACerts.ToString());
+ AppendObject(buf, "onlyContainsCACerts", _onlyContainsCACerts.ToString());
}
if (_onlySomeReasons != null)
{
- appendObject(buf, sep, "onlySomeReasons", _onlySomeReasons.ToString());
+ AppendObject(buf, "onlySomeReasons", _onlySomeReasons.ToString());
}
if (_onlyContainsAttributeCerts)
{
- appendObject(buf, sep, "onlyContainsAttributeCerts", _onlyContainsAttributeCerts.ToString());
+ AppendObject(buf, "onlyContainsAttributeCerts", _onlyContainsAttributeCerts.ToString());
}
if (_indirectCRL)
{
- appendObject(buf, sep, "indirectCRL", _indirectCRL.ToString());
+ AppendObject(buf, "indirectCRL", _indirectCRL.ToString());
}
- buf.Append("]");
- buf.Append(sep);
+ buf.AppendLine("]");
return buf.ToString();
}
- private void appendObject(
- StringBuilder buf,
- string sep,
- string name,
- string val)
+ private void AppendObject(StringBuilder buf, string name, string val)
{
string indent = " ";
-
buf.Append(indent);
buf.Append(name);
- buf.Append(":");
- buf.Append(sep);
+ buf.AppendLine(":");
buf.Append(indent);
buf.Append(indent);
buf.Append(val);
- buf.Append(sep);
+ buf.AppendLine();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/KeyPurposeId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/KeyPurposeId.cs
index 977d22b..0389fa2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/KeyPurposeId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/KeyPurposeId.cs
@@ -1,5 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
+using System;
+
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
/**
@@ -11,31 +13,87 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
public sealed class KeyPurposeID
: DerObjectIdentifier
{
- private const string IdKP = "1.3.6.1.5.5.7.3";
+ private const string id_kp = "1.3.6.1.5.5.7.3";
- private KeyPurposeID(
- string id)
+ private KeyPurposeID(string id)
: base(id)
{
}
public static readonly KeyPurposeID AnyExtendedKeyUsage = new KeyPurposeID(X509Extensions.ExtendedKeyUsage.Id + ".0");
- public static readonly KeyPurposeID IdKPServerAuth = new KeyPurposeID(IdKP + ".1");
- public static readonly KeyPurposeID IdKPClientAuth = new KeyPurposeID(IdKP + ".2");
- public static readonly KeyPurposeID IdKPCodeSigning = new KeyPurposeID(IdKP + ".3");
- public static readonly KeyPurposeID IdKPEmailProtection = new KeyPurposeID(IdKP + ".4");
- public static readonly KeyPurposeID IdKPIpsecEndSystem = new KeyPurposeID(IdKP + ".5");
- public static readonly KeyPurposeID IdKPIpsecTunnel = new KeyPurposeID(IdKP + ".6");
- public static readonly KeyPurposeID IdKPIpsecUser = new KeyPurposeID(IdKP + ".7");
- public static readonly KeyPurposeID IdKPTimeStamping = new KeyPurposeID(IdKP + ".8");
- public static readonly KeyPurposeID IdKPOcspSigning = new KeyPurposeID(IdKP + ".9");
-
- //
+
+ public static readonly KeyPurposeID id_kp_serverAuth = new KeyPurposeID(id_kp + ".1");
+ public static readonly KeyPurposeID id_kp_clientAuth = new KeyPurposeID(id_kp + ".2");
+ public static readonly KeyPurposeID id_kp_codeSigning = new KeyPurposeID(id_kp + ".3");
+ public static readonly KeyPurposeID id_kp_emailProtection = new KeyPurposeID(id_kp + ".4");
+ public static readonly KeyPurposeID id_kp_ipsecEndSystem = new KeyPurposeID(id_kp + ".5");
+ public static readonly KeyPurposeID id_kp_ipsecTunnel = new KeyPurposeID(id_kp + ".6");
+ public static readonly KeyPurposeID id_kp_ipsecUser = new KeyPurposeID(id_kp + ".7");
+ public static readonly KeyPurposeID id_kp_timeStamping = new KeyPurposeID(id_kp + ".8");
+ public static readonly KeyPurposeID id_kp_OCSPSigning = new KeyPurposeID(id_kp + ".9");
+ public static readonly KeyPurposeID id_kp_dvcs = new KeyPurposeID(id_kp + ".10");
+ public static readonly KeyPurposeID id_kp_sbgpCertAAServerAuth = new KeyPurposeID(id_kp + ".11");
+ public static readonly KeyPurposeID id_kp_scvp_responder = new KeyPurposeID(id_kp + ".12");
+ public static readonly KeyPurposeID id_kp_eapOverPPP = new KeyPurposeID(id_kp + ".13");
+ public static readonly KeyPurposeID id_kp_eapOverLAN = new KeyPurposeID(id_kp + ".14");
+ public static readonly KeyPurposeID id_kp_scvpServer = new KeyPurposeID(id_kp + ".15");
+ public static readonly KeyPurposeID id_kp_scvpClient = new KeyPurposeID(id_kp + ".16");
+ public static readonly KeyPurposeID id_kp_ipsecIKE = new KeyPurposeID(id_kp + ".17");
+ public static readonly KeyPurposeID id_kp_capwapAC = new KeyPurposeID(id_kp + ".18");
+ public static readonly KeyPurposeID id_kp_capwapWTP = new KeyPurposeID(id_kp + ".19");
+
+ public static readonly KeyPurposeID id_kp_cmcCA = new KeyPurposeID(id_kp + ".27");
+ public static readonly KeyPurposeID id_kp_cmcRA = new KeyPurposeID(id_kp + ".28");
+ public static readonly KeyPurposeID id_kp_cmKGA = new KeyPurposeID(id_kp + ".32");
+
+ //
// microsoft key purpose ids
//
- public static readonly KeyPurposeID IdKPSmartCardLogon = new KeyPurposeID("1.3.6.1.4.1.311.20.2.2");
+ public static readonly KeyPurposeID id_kp_smartcardlogon = new KeyPurposeID("1.3.6.1.4.1.311.20.2.2");
+
+ public static readonly KeyPurposeID id_kp_macAddress = new KeyPurposeID("1.3.6.1.1.1.1.22");
+
+ /// Microsoft Server Gated Crypto (msSGC).
+ /// see https://www.alvestrand.no/objectid/1.3.6.1.4.1.311.10.3.3.html
+ public static readonly KeyPurposeID id_kp_msSGC = new KeyPurposeID("1.3.6.1.4.1.311.10.3.3");
+
+ private const string id_pkinit = "1.3.6.1.5.2.3";
+
+ public static readonly KeyPurposeID scSysNodeNumber = new KeyPurposeID(id_pkinit + ".0");
+ public static readonly KeyPurposeID id_pkinit_authData = new KeyPurposeID(id_pkinit + ".1");
+ public static readonly KeyPurposeID id_pkinit_DHKeyData = new KeyPurposeID(id_pkinit + ".2");
+ public static readonly KeyPurposeID id_pkinit_rkeyData = new KeyPurposeID(id_pkinit + ".3");
+ public static readonly KeyPurposeID keyPurposeClientAuth = new KeyPurposeID(id_pkinit + ".4");
+ public static readonly KeyPurposeID keyPurposeKdc = new KeyPurposeID(id_pkinit + ".5");
+
+ /// Netscape Server Gated Crypto (nsSGC).
+ /// see https://www.alvestrand.no/objectid/2.16.840.1.113730.4.1.html
+ public static readonly KeyPurposeID id_kp_nsSGC = new KeyPurposeID("2.16.840.1.113730.4.1");
+
+
+ public static readonly KeyPurposeID IdKPServerAuth = id_kp_serverAuth;
+
+ public static readonly KeyPurposeID IdKPClientAuth = id_kp_clientAuth;
+
+ public static readonly KeyPurposeID IdKPCodeSigning = id_kp_codeSigning;
+
+ public static readonly KeyPurposeID IdKPEmailProtection = id_kp_emailProtection;
+
+ public static readonly KeyPurposeID IdKPIpsecEndSystem = id_kp_ipsecEndSystem;
+
+ public static readonly KeyPurposeID IdKPIpsecTunnel = id_kp_ipsecTunnel;
+
+ public static readonly KeyPurposeID IdKPIpsecUser = id_kp_ipsecUser;
+
+ public static readonly KeyPurposeID IdKPTimeStamping = id_kp_timeStamping;
+
+ public static readonly KeyPurposeID IdKPOcspSigning = id_kp_OCSPSigning;
+
+
+ public static readonly KeyPurposeID IdKPSmartCardLogon = id_kp_smartcardlogon;
+
- public static readonly KeyPurposeID IdKPMacAddress = new KeyPurposeID("1.3.6.1.1.1.1.22");
+ public static readonly KeyPurposeID IdKPMacAddress = id_kp_macAddress;
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NameConstraints.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NameConstraints.cs
index 99efdcb..e0c2a74 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NameConstraints.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NameConstraints.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -25,7 +25,7 @@ public static NameConstraints GetInstance(
return new NameConstraints((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public NameConstraints(
@@ -45,15 +45,6 @@ public NameConstraints(
}
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- public NameConstraints(
- ArrayList permitted,
- ArrayList excluded)
- : this((IList)permitted, (IList)excluded)
- {
- }
-#endif
-
/**
* Constructor from a given details.
*
@@ -63,8 +54,8 @@ public NameConstraints(
* @param excluded Excluded subtrees
*/
public NameConstraints(
- IList permitted,
- IList excluded)
+ IList permitted,
+ IList excluded)
{
if (permitted != null)
{
@@ -77,13 +68,12 @@ public NameConstraints(
}
}
- private DerSequence CreateSequence(
- IList subtrees)
+ private DerSequence CreateSequence(IList subtrees)
{
GeneralSubtree[] gsts = new GeneralSubtree[subtrees.Count];
for (int i = 0; i < subtrees.Count; ++i)
{
- gsts[i] = (GeneralSubtree)subtrees[i];
+ gsts[i] = subtrees[i];
}
return new DerSequence(gsts);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NoticeReference.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NoticeReference.cs
index 38023d0..904bc5b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NoticeReference.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/NoticeReference.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
@@ -28,7 +28,7 @@ public class NoticeReference
private readonly DisplayText organization;
private readonly Asn1Sequence noticeNumbers;
- private static Asn1EncodableVector ConvertVector(IList numbers)
+ private static Asn1EncodableVector ConvertVector(IList numbers)
{
Asn1EncodableVector av = new Asn1EncodableVector();
@@ -60,7 +60,7 @@ private static Asn1EncodableVector ConvertVector(IList numbers)
* @param organization a String value
* @param numbers a Vector value
*/
- public NoticeReference(string organization, IList numbers)
+ public NoticeReference(string organization, IList numbers)
: this(organization, ConvertVector(numbers))
{
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ObjectDigestInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ObjectDigestInfo.cs
index e3ee0ba..8b3042f 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ObjectDigestInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/ObjectDigestInfo.cs
@@ -62,7 +62,7 @@ public static ObjectDigestInfo GetInstance(
return new ObjectDigestInfo((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public static ObjectDigestInfo GetInstance(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PolicyMappings.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PolicyMappings.cs
index 85250f7..02e00eb 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PolicyMappings.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PolicyMappings.cs
@@ -1,6 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System.Collections;
+using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
@@ -31,14 +31,6 @@ public PolicyMappings(
this.seq = seq;
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- public PolicyMappings(
- Hashtable mappings)
- : this((IDictionary)mappings)
- {
- }
-#endif
-
/**
* Creates a new PolicyMappings instance.
*
@@ -46,14 +38,14 @@ public PolicyMappings(
* string oids
* to other string oids.
*/
- public PolicyMappings(
- IDictionary mappings)
+ public PolicyMappings(IDictionary mappings)
{
Asn1EncodableVector v = new Asn1EncodableVector();
- foreach (string idp in mappings.Keys)
+ foreach (var entry in mappings)
{
- string sdp = (string) mappings[idp];
+ string idp = entry.Key;
+ string sdp = entry.Value;
v.Add(
new DerSequence(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PrivateKeyUsagePeriod.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PrivateKeyUsagePeriod.cs
index dac39ea..7b245a0 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PrivateKeyUsagePeriod.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/PrivateKeyUsagePeriod.cs
@@ -35,10 +35,10 @@ public static PrivateKeyUsagePeriod GetInstance(
return GetInstance(X509Extension.ConvertValueToObject((X509Extension) obj));
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
- private DerGeneralizedTime _notBefore, _notAfter;
+ private Asn1GeneralizedTime _notBefore, _notAfter;
private PrivateKeyUsagePeriod(
Asn1Sequence seq)
@@ -47,21 +47,21 @@ private PrivateKeyUsagePeriod(
{
if (tObj.TagNo == 0)
{
- _notBefore = DerGeneralizedTime.GetInstance(tObj, false);
+ _notBefore = Asn1GeneralizedTime.GetInstance(tObj, false);
}
else if (tObj.TagNo == 1)
{
- _notAfter = DerGeneralizedTime.GetInstance(tObj, false);
+ _notAfter = Asn1GeneralizedTime.GetInstance(tObj, false);
}
}
}
- public DerGeneralizedTime NotBefore
+ public Asn1GeneralizedTime NotBefore
{
get { return _notBefore; }
}
- public DerGeneralizedTime NotAfter
+ public Asn1GeneralizedTime NotAfter
{
get { return _notAfter; }
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/RSAPublicKeyStructure.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/RSAPublicKeyStructure.cs
index 6b450c4..2ec0a79 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/RSAPublicKeyStructure.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/RSAPublicKeyStructure.cs
@@ -1,9 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -35,7 +33,7 @@ public static RsaPublicKeyStructure GetInstance(
return new RsaPublicKeyStructure((Asn1Sequence) obj);
}
- throw new ArgumentException("Invalid RsaPublicKeyStructure: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
+ throw new ArgumentException("Invalid RsaPublicKeyStructure: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
}
public RsaPublicKeyStructure(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectDirectoryAttributes.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectDirectoryAttributes.cs
index 5c6a31b..a294df4 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectDirectoryAttributes.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectDirectoryAttributes.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
@@ -30,7 +30,7 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
public class SubjectDirectoryAttributes
: Asn1Encodable
{
- private readonly IList attributes;
+ private readonly IList m_attributes;
public static SubjectDirectoryAttributes GetInstance(
object obj)
@@ -45,7 +45,7 @@ public static SubjectDirectoryAttributes GetInstance(
return new SubjectDirectoryAttributes((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
@@ -72,23 +72,15 @@ public static SubjectDirectoryAttributes GetInstance(
private SubjectDirectoryAttributes(
Asn1Sequence seq)
{
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ m_attributes = new List();
+
foreach (object o in seq)
{
Asn1Sequence s = Asn1Sequence.GetInstance(o);
- attributes.Add(AttributeX509.GetInstance(s));
+ m_attributes.Add(AttributeX509.GetInstance(s));
}
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- [Obsolete]
- public SubjectDirectoryAttributes(
- ArrayList attributes)
- : this((IList)attributes)
- {
- }
-#endif
-
/**
* Constructor from an ArrayList of attributes.
*
@@ -97,11 +89,10 @@ public SubjectDirectoryAttributes(
* @param attributes The attributes.
*
*/
- public SubjectDirectoryAttributes(
- IList attributes)
+ public SubjectDirectoryAttributes(IList attributes)
{
- this.attributes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(attributes);
- }
+ m_attributes = new List(attributes);
+ }
/**
* Produce an object suitable for an Asn1OutputStream.
@@ -125,10 +116,10 @@ public SubjectDirectoryAttributes(
*/
public override Asn1Object ToAsn1Object()
{
- AttributeX509[] v = new AttributeX509[attributes.Count];
- for (int i = 0; i < attributes.Count; ++i)
+ AttributeX509[] v = new AttributeX509[m_attributes.Count];
+ for (int i = 0; i < m_attributes.Count; ++i)
{
- v[i] = (AttributeX509)attributes[i];
+ v[i] = m_attributes[i];
}
return new DerSequence(v);
}
@@ -136,9 +127,9 @@ public override Asn1Object ToAsn1Object()
/**
* @return Returns the attributes.
*/
- public IEnumerable Attributes
+ public IEnumerable Attributes
{
- get { return new EnumerableProxy(attributes); }
+ get { return CollectionUtilities.Proxy(m_attributes); }
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectPublicKeyInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectPublicKeyInfo.cs
index 67d24a3..4c935b9 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectPublicKeyInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/SubjectPublicKeyInfo.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
@@ -80,19 +79,6 @@ public Asn1Object ParsePublicKey()
return Asn1Object.FromByteArray(keyData.GetOctets());
}
- /**
- * for when the public key is an encoded object - if the bitstring
- * can't be decoded this routine raises an IOException.
- *
- * @exception IOException - if the bit string doesn't represent a Der
- * encoded object.
- */
-
- public Asn1Object GetPublicKey()
- {
- return Asn1Object.FromByteArray(keyData.GetOctets());
- }
-
/**
* for when the public key is raw bits...
*/
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertList.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertList.cs
index 909555f..afc4918 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertList.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertList.cs
@@ -1,10 +1,9 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
@@ -16,13 +15,10 @@ public class CrlEntry
internal Time revocationDate;
internal X509Extensions crlEntryExtensions;
- public CrlEntry(
- Asn1Sequence seq)
+ public CrlEntry(Asn1Sequence seq)
{
if (seq.Count < 2 || seq.Count > 3)
- {
throw new ArgumentException("Bad sequence size: " + seq.Count);
- }
this.seq = seq;
@@ -84,32 +80,39 @@ public class TbsCertificateList
: Asn1Encodable
{
private class RevokedCertificatesEnumeration
- : IEnumerable
+ : IEnumerable
{
- private readonly IEnumerable en;
+ private readonly IEnumerable en;
- internal RevokedCertificatesEnumeration(
- IEnumerable en)
+ internal RevokedCertificatesEnumeration(IEnumerable en)
{
this.en = en;
}
- public IEnumerator GetEnumerator()
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public IEnumerator GetEnumerator()
{
return new RevokedCertificatesEnumerator(en.GetEnumerator());
}
private class RevokedCertificatesEnumerator
- : IEnumerator
+ : IEnumerator
{
- private readonly IEnumerator e;
+ private readonly IEnumerator e;
- internal RevokedCertificatesEnumerator(
- IEnumerator e)
+ internal RevokedCertificatesEnumerator(IEnumerator e)
{
this.e = e;
}
+ public virtual void Dispose()
+ {
+ }
+
public bool MoveNext()
{
return e.MoveNext();
@@ -120,7 +123,12 @@ public void Reset()
e.Reset();
}
- public object Current
+ object System.Collections.IEnumerator.Current
+ {
+ get { return Current; }
+ }
+
+ public CrlEntry Current
{
get { return new CrlEntry(Asn1Sequence.GetInstance(e.Current)); }
}
@@ -158,7 +166,7 @@ public static TbsCertificateList GetInstance(
return new TbsCertificateList((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
internal TbsCertificateList(
@@ -187,8 +195,8 @@ internal TbsCertificateList(
thisUpdate = Time.GetInstance(seq[seqPos++]);
if (seqPos < seq.Count
- && (seq[seqPos] is DerUtcTime
- || seq[seqPos] is DerGeneralizedTime
+ && (seq[seqPos] is Asn1UtcTime
+ || seq[seqPos] is Asn1GeneralizedTime
|| seq[seqPos] is Time))
{
nextUpdate = Time.GetInstance(seq[seqPos++]);
@@ -254,12 +262,10 @@ public CrlEntry[] GetRevokedCertificates()
return entries;
}
- public IEnumerable GetRevokedCertificateEnumeration()
+ public IEnumerable GetRevokedCertificateEnumeration()
{
if (revokedCertificates == null)
- {
- return EmptyEnumerable.Instance;
- }
+ return new List(0);
return new RevokedCertificatesEnumeration(revokedCertificates);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertificateStructure.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertificateStructure.cs
index 2a38737..66fd8a2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertificateStructure.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TBSCertificateStructure.cs
@@ -215,7 +215,7 @@ public X509Extensions Extensions
public override Asn1Object ToAsn1Object()
{
string property = Org.BouncyCastle.Utilities.Platform.GetEnvironmentVariable("BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Allow_Non-DER_TBSCert");
- if (null == property || BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.EqualsIgnoreCase("true", property))
+ if (null == property || Org.BouncyCastle.Utilities.Platform.EqualsIgnoreCase("true", property))
return seq;
Asn1EncodableVector v = new Asn1EncodableVector();
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Target.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Target.cs
index b3e84cf..9c3f53a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Target.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Target.cs
@@ -57,7 +57,7 @@ public static Target GetInstance(
return new Target((Asn1TaggedObject) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TargetInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TargetInformation.cs
index 3edd2c4..46deb5d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TargetInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/TargetInformation.cs
@@ -42,7 +42,7 @@ public static TargetInformation GetInstance(
return new TargetInformation((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Targets.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Targets.cs
index 3c4f903..24f88ef 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Targets.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Targets.cs
@@ -56,7 +56,7 @@ public static Targets GetInstance(
return new Targets((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Time.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Time.cs
index da84df1..d27a4d8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Time.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/Time.cs
@@ -10,24 +10,41 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
public class Time
: Asn1Encodable, IAsn1Choice
{
- private readonly Asn1Object time;
+ public static Time GetInstance(object obj)
+ {
+ if (obj == null)
+ return null;
+ if (obj is Time time)
+ return time;
+ if (obj is Asn1UtcTime utcTime)
+ return new Time(utcTime);
+ if (obj is Asn1GeneralizedTime generalizedTime)
+ return new Time(generalizedTime);
+
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), nameof(obj));
+ }
- public static Time GetInstance(
- Asn1TaggedObject obj,
- bool explicitly)
+ public static Time GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- return GetInstance(obj.GetObject());
+ return GetInstance(taggedObject.GetObject());
}
- public Time(
- Asn1Object time)
+ private readonly Asn1Object m_timeObject;
+
+ public Time(Asn1GeneralizedTime generalizedTime)
{
- if (time == null)
- throw new ArgumentNullException("time");
- if (!(time is DerUtcTime) && !(time is DerGeneralizedTime))
- throw new ArgumentException("unknown object passed to Time");
+ this.m_timeObject = generalizedTime ?? throw new ArgumentNullException(nameof(generalizedTime));
+ }
- this.time = time;
+ public Time(Asn1UtcTime utcTime)
+ {
+ if (utcTime == null)
+ throw new ArgumentNullException(nameof(utcTime));
+
+ // Validate utcTime is in the appropriate year range
+ utcTime.ToDateTime(2049);
+
+ this.m_timeObject = utcTime;
}
/**
@@ -35,48 +52,18 @@ public Time(
* and 2049 a UTCTime object is Generated, otherwise a GeneralizedTime
* is used.
*/
- public Time(
- DateTime date)
+ public Time(DateTime date)
{
-#if PORTABLE || NETFX_CORE
- string d = date.ToUniversalTime().ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z";
-#else
- string d = date.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z";
-#endif
+ DateTime utc = date.ToUniversalTime();
- int year = int.Parse(d.Substring(0, 4));
-
- if (year < 1950 || year > 2049)
+ if (utc.Year < 1950 || utc.Year > 2049)
{
- time = new DerGeneralizedTime(d);
+ m_timeObject = new DerGeneralizedTime(utc);
}
else
{
- time = new DerUtcTime(d.Substring(2));
- }
- }
-
- public static Time GetInstance(
- object obj)
- {
- if (obj == null || obj is Time)
- return (Time)obj;
- if (obj is DerUtcTime)
- return new Time((DerUtcTime)obj);
- if (obj is DerGeneralizedTime)
- return new Time((DerGeneralizedTime)obj);
-
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
- }
-
- public string GetTime()
- {
- if (time is DerUtcTime)
- {
- return ((DerUtcTime) time).AdjustedTimeString;
+ m_timeObject = new DerUtcTime(utc, 2049);
}
-
- return ((DerGeneralizedTime) time).GetTime();
}
///
@@ -87,14 +74,10 @@ public DateTime ToDateTime()
{
try
{
- if (time is DerUtcTime)
- {
- return ((DerUtcTime)time).ToAdjustedDateTime();
- }
- else
- {
- return ((DerGeneralizedTime)time).ToDateTime();
- }
+ if (m_timeObject is Asn1UtcTime utcTime)
+ return utcTime.ToDateTime(2049);
+
+ return ((Asn1GeneralizedTime)m_timeObject).ToDateTime();
}
catch (FormatException e)
{
@@ -113,12 +96,18 @@ public DateTime ToDateTime()
*/
public override Asn1Object ToAsn1Object()
{
- return time;
+ return m_timeObject;
}
public override string ToString()
{
- return GetTime();
+ if (m_timeObject is Asn1UtcTime utcTime)
+ return utcTime.ToDateTime(2049).ToString(@"yyyyMMddHHmmssK", DateTimeFormatInfo.InvariantInfo);
+
+ if (m_timeObject is Asn1GeneralizedTime generalizedTime)
+ return generalizedTime.ToDateTime().ToString(@"yyyyMMddHHmmss.FFFFFFFK", DateTimeFormatInfo.InvariantInfo);
+
+ throw new InvalidOperationException();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/UserNotice.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/UserNotice.cs
index 091f258..281601e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/UserNotice.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/UserNotice.cs
@@ -51,18 +51,7 @@ public UserNotice(
{
}
- /**
- * Creates a new UserNotice instance.
- *
Useful from reconstructing a UserNotice instance
- * from its encodable/encoded form.
- *
- * @param as an ASN1Sequence value obtained from either
- * calling @{link toASN1Object()} for a UserNotice
- * instance or from parsing it from a DER-encoded stream.
- */
-
- public UserNotice(
- Asn1Sequence seq)
+ private UserNotice(Asn1Sequence seq)
{
if (seq.Count == 2)
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V1TBSCertificateGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V1TBSCertificateGenerator.cs
index 20565c9..138a412 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V1TBSCertificateGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V1TBSCertificateGenerator.cs
@@ -58,7 +58,7 @@ public void SetStartDate(
}
public void SetStartDate(
- DerUtcTime startDate)
+ Asn1UtcTime startDate)
{
this.startDate = new Time(startDate);
}
@@ -70,7 +70,7 @@ public void SetEndDate(
}
public void SetEndDate(
- DerUtcTime endDate)
+ Asn1UtcTime endDate)
{
this.endDate = new Time(endDate);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2AttributeCertificateInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2AttributeCertificateInfoGenerator.cs
index bd1afd0..f561369 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2AttributeCertificateInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2AttributeCertificateInfoGenerator.cs
@@ -28,11 +28,13 @@ public class V2AttributeCertificateInfoGenerator
internal AttCertIssuer issuer;
internal AlgorithmIdentifier signature;
internal DerInteger serialNumber;
-// internal AttCertValidityPeriod attrCertValidityPeriod;
internal Asn1EncodableVector attributes;
internal DerBitString issuerUniqueID;
internal X509Extensions extensions;
- internal DerGeneralizedTime startDate, endDate;
+
+ // Note: validity period start/end dates stored directly
+ //internal AttCertValidityPeriod attrCertValidityPeriod;
+ internal Asn1GeneralizedTime startDate, endDate;
public V2AttributeCertificateInfoGenerator()
{
@@ -80,13 +82,13 @@ public void SetIssuer(
}
public void SetStartDate(
- DerGeneralizedTime startDate)
+ Asn1GeneralizedTime startDate)
{
this.startDate = startDate;
}
public void SetEndDate(
- DerGeneralizedTime endDate)
+ Asn1GeneralizedTime endDate)
{
this.endDate = endDate;
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2TBSCertListGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2TBSCertListGenerator.cs
index 70cdd36..b489785 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2TBSCertListGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V2TBSCertListGenerator.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -38,7 +38,7 @@ public class V2TbsCertListGenerator
private X509Name issuer;
private Time thisUpdate, nextUpdate;
private X509Extensions extensions;
- private IList crlEntries;
+ private List crlEntries;
public V2TbsCertListGenerator()
{
@@ -57,13 +57,13 @@ public void SetIssuer(
}
public void SetThisUpdate(
- DerUtcTime thisUpdate)
+ Asn1UtcTime thisUpdate)
{
this.thisUpdate = new Time(thisUpdate);
}
public void SetNextUpdate(
- DerUtcTime nextUpdate)
+ Asn1UtcTime nextUpdate)
{
this.nextUpdate = (nextUpdate != null)
? new Time(nextUpdate)
@@ -82,18 +82,17 @@ public void SetNextUpdate(
this.nextUpdate = nextUpdate;
}
- public void AddCrlEntry(
- Asn1Sequence crlEntry)
+ public void AddCrlEntry(Asn1Sequence crlEntry)
{
if (crlEntries == null)
{
- crlEntries = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ crlEntries = new List();
}
crlEntries.Add(crlEntry);
}
- public void AddCrlEntry(DerInteger userCertificate, DerUtcTime revocationDate, int reason)
+ public void AddCrlEntry(DerInteger userCertificate, Asn1UtcTime revocationDate, int reason)
{
AddCrlEntry(userCertificate, new Time(revocationDate), reason);
}
@@ -104,10 +103,10 @@ public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int rea
}
public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason,
- DerGeneralizedTime invalidityDate)
+ Asn1GeneralizedTime invalidityDate)
{
- IList extOids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- IList extValues = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var extOids = new List();
+ var extValues = new List();
if (reason != 0)
{
@@ -149,8 +148,7 @@ public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int rea
public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, X509Extensions extensions)
{
- Asn1EncodableVector v = new Asn1EncodableVector(
- userCertificate, revocationDate);
+ Asn1EncodableVector v = new Asn1EncodableVector(userCertificate, revocationDate);
if (extensions != null)
{
@@ -184,12 +182,7 @@ public TbsCertificateList GenerateTbsCertList()
// Add CRLEntries if they exist
if (crlEntries != null)
{
- Asn1Sequence[] certs = new Asn1Sequence[crlEntries.Count];
- for (int i = 0; i < crlEntries.Count; ++i)
- {
- certs[i] = (Asn1Sequence)crlEntries[i];
- }
- v.Add(new DerSequence(certs));
+ v.Add(new DerSequence(crlEntries.ToArray()));
}
if (extensions != null)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V3TBSCertificateGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V3TBSCertificateGenerator.cs
index 0ef0a85..1b6a18e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V3TBSCertificateGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/V3TBSCertificateGenerator.cs
@@ -60,7 +60,7 @@ public void SetIssuer(
}
public void SetStartDate(
- DerUtcTime startDate)
+ Asn1UtcTime startDate)
{
this.startDate = new Time(startDate);
}
@@ -72,7 +72,7 @@ public void SetStartDate(
}
public void SetEndDate(
- DerUtcTime endDate)
+ Asn1UtcTime endDate)
{
this.endDate = new Time(endDate);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509DefaultEntryConverter.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509DefaultEntryConverter.cs
index b842699..279ad4c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509DefaultEntryConverter.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509DefaultEntryConverter.cs
@@ -48,7 +48,7 @@ public override Asn1Object GetConvertedValue(
if (oid.Equals(X509Name.DateOfBirth)) // accept time string as well as # (for compatibility)
{
- return new DerGeneralizedTime(value);
+ return new Asn1GeneralizedTime(value);
}
if (oid.Equals(X509Name.C)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Extensions.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Extensions.cs
index 09157f2..cd4cca1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Extensions.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Extensions.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
@@ -171,8 +171,9 @@ public class X509Extensions
*/
public static readonly DerObjectIdentifier ExpiredCertsOnCrl = new DerObjectIdentifier("2.5.29.60");
- private readonly IDictionary extensions = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private readonly IList ordering;
+ private readonly Dictionary m_extensions =
+ new Dictionary();
+ private readonly List m_ordering;
public static X509Extension GetExtension(X509Extensions extensions, DerObjectIdentifier oid)
{
@@ -184,11 +185,9 @@ public static Asn1Encodable GetExtensionParsedValue(X509Extensions extensions, D
return null == extensions ? null : extensions.GetExtensionParsedValue(oid);
}
- public static X509Extensions GetInstance(
- Asn1TaggedObject obj,
- bool explicitly)
+ public static X509Extensions GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
- return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
+ return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
public static X509Extensions GetInstance(
@@ -209,7 +208,7 @@ public static X509Extensions GetInstance(
return GetInstance(((Asn1TaggedObject) obj).GetObject());
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
@@ -217,10 +216,9 @@ public static X509Extensions GetInstance(
*
* the extensions are a list of constructed sequences, either with (Oid, OctetString) or (Oid, Boolean, OctetString)
*/
- private X509Extensions(
- Asn1Sequence seq)
+ private X509Extensions(Asn1Sequence seq)
{
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ m_ordering = new List();
foreach (Asn1Encodable ae in seq)
{
@@ -236,11 +234,11 @@ private X509Extensions(
Asn1OctetString octets = Asn1OctetString.GetInstance(s[s.Count - 1].ToAsn1Object());
- if (extensions.Contains(oid))
+ if (m_extensions.ContainsKey(oid))
throw new ArgumentException("repeated extension found: " + oid);
- extensions.Add(oid, new X509Extension(isCritical, octets));
- ordering.Add(oid);
+ m_extensions.Add(oid, new X509Extension(isCritical, octets));
+ m_ordering.Add(oid);
}
}
@@ -249,8 +247,7 @@ private X509Extensions(
*
* it's is assumed the table contains Oid/string pairs.
*/
- public X509Extensions(
- IDictionary extensions)
+ public X509Extensions(IDictionary extensions)
: this(null, extensions)
{
}
@@ -260,22 +257,21 @@ public X509Extensions(
*
* It's is assumed the table contains Oid/string pairs.
*/
- public X509Extensions(
- IList ordering,
- IDictionary extensions)
+ public X509Extensions(IList ordering,
+ IDictionary extensions)
{
if (ordering == null)
{
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(extensions.Keys);
+ m_ordering = new List(extensions.Keys);
}
else
{
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(ordering);
+ m_ordering = new List(ordering);
}
- foreach (DerObjectIdentifier oid in this.ordering)
+ foreach (DerObjectIdentifier oid in m_ordering)
{
- this.extensions.Add(oid, (X509Extension)extensions[oid]);
+ m_extensions.Add(oid, extensions[oid]);
}
}
@@ -285,90 +281,23 @@ public X509Extensions(
* @param objectIDs an ArrayList of the object identifiers.
* @param values an ArrayList of the extension values.
*/
- public X509Extensions(
- IList oids,
- IList values)
+ public X509Extensions(IList oids, IList values)
{
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(oids);
+ m_ordering = new List(oids);
int count = 0;
- foreach (DerObjectIdentifier oid in this.ordering)
+ foreach (DerObjectIdentifier oid in m_ordering)
{
- this.extensions.Add(oid, (X509Extension)values[count++]);
+ m_extensions.Add(oid, values[count++]);
}
}
-#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
- /**
- * constructor from a table of extensions.
- *
- * it's is assumed the table contains Oid/string pairs.
- */
- [Obsolete]
- public X509Extensions(
- Hashtable extensions)
- : this(null, extensions)
- {
- }
-
- /**
- * Constructor from a table of extensions with ordering.
- *
- * It's is assumed the table contains Oid/string pairs.
- */
- [Obsolete]
- public X509Extensions(
- ArrayList ordering,
- Hashtable extensions)
- {
- if (ordering == null)
- {
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(extensions.Keys);
- }
- else
- {
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(ordering);
- }
-
- foreach (DerObjectIdentifier oid in this.ordering)
- {
- this.extensions.Add(oid, (X509Extension) extensions[oid]);
- }
- }
-
- /**
- * Constructor from two vectors
- *
- * @param objectIDs an ArrayList of the object identifiers.
- * @param values an ArrayList of the extension values.
- */
- [Obsolete]
- public X509Extensions(
- ArrayList oids,
- ArrayList values)
- {
- this.ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(oids);
-
- int count = 0;
- foreach (DerObjectIdentifier oid in this.ordering)
- {
- this.extensions.Add(oid, (X509Extension) values[count++]);
- }
- }
-#endif
-
-
- public IEnumerator Oids()
- {
- return ExtensionOids.GetEnumerator();
- }
-
/**
* return an Enumeration of the extension field's object ids.
*/
- public IEnumerable ExtensionOids
+ public IEnumerable ExtensionOids
{
- get { return new EnumerableProxy(ordering); }
+ get { return CollectionUtilities.Proxy(m_ordering); }
}
/**
@@ -377,10 +306,9 @@ public IEnumerable ExtensionOids
*
* @return the extension if it's present, null otherwise.
*/
- public X509Extension GetExtension(
- DerObjectIdentifier oid)
+ public X509Extension GetExtension(DerObjectIdentifier oid)
{
- return (X509Extension)extensions[oid];
+ return CollectionUtilities.GetValueOrNull(m_extensions, oid);
}
/**
@@ -391,9 +319,7 @@ public X509Extension GetExtension(
*/
public Asn1Encodable GetExtensionParsedValue(DerObjectIdentifier oid)
{
- X509Extension ext = GetExtension(oid);
-
- return ext == null ? null : ext.GetParsedValue();
+ return GetExtension(oid)?.GetParsedValue();
}
/**
@@ -408,44 +334,41 @@ public Asn1Encodable GetExtensionParsedValue(DerObjectIdentifier oid)
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector vec = new Asn1EncodableVector();
+ Asn1EncodableVector v = new Asn1EncodableVector(m_ordering.Count);
- foreach (DerObjectIdentifier oid in ordering)
+ foreach (DerObjectIdentifier oid in m_ordering)
{
- X509Extension ext = (X509Extension) extensions[oid];
- Asn1EncodableVector v = new Asn1EncodableVector(oid);
-
- if (ext.IsCritical)
+ X509Extension ext = m_extensions[oid];
+ if (ext.IsCritical)
{
- v.Add(DerBoolean.True);
+ v.Add(new DerSequence(oid, DerBoolean.True, ext.Value));
+ }
+ else
+ {
+ v.Add(new DerSequence(oid, ext.Value));
}
-
- v.Add(ext.Value);
-
- vec.Add(new DerSequence(v));
}
- return new DerSequence(vec);
+ return new DerSequence(v);
}
- public bool Equivalent(
- X509Extensions other)
+ public bool Equivalent(X509Extensions other)
{
- if (extensions.Count != other.extensions.Count)
+ if (m_extensions.Count != other.m_extensions.Count)
return false;
- foreach (DerObjectIdentifier oid in extensions.Keys)
- {
- if (!extensions[oid].Equals(other.extensions[oid]))
- return false;
- }
+ foreach (var entry in m_extensions)
+ {
+ if (!entry.Value.Equals(other.GetExtension(entry.Key)))
+ return false;
+ }
return true;
}
public DerObjectIdentifier[] GetExtensionOids()
{
- return ToOidArray(ordering);
+ return m_ordering.ToArray();
}
public DerObjectIdentifier[] GetNonCriticalExtensionOids()
@@ -460,25 +383,17 @@ public DerObjectIdentifier[] GetCriticalExtensionOids()
private DerObjectIdentifier[] GetExtensionOids(bool isCritical)
{
- IList oids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var oids = new List();
- foreach (DerObjectIdentifier oid in this.ordering)
+ foreach (DerObjectIdentifier oid in m_ordering)
{
- X509Extension ext = (X509Extension)extensions[oid];
- if (ext.IsCritical == isCritical)
+ if (m_extensions[oid].IsCritical == isCritical)
{
oids.Add(oid);
}
}
- return ToOidArray(oids);
- }
-
- private static DerObjectIdentifier[] ToOidArray(IList oids)
- {
- DerObjectIdentifier[] oidArray = new DerObjectIdentifier[oids.Count];
- oids.CopyTo(oidArray, 0);
- return oidArray;
+ return oids.ToArray();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509ExtensionsGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509ExtensionsGenerator.cs
index 5cdca84..8e4d9d9 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509ExtensionsGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509ExtensionsGenerator.cs
@@ -1,36 +1,30 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using System.Collections.Generic;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
{
/// Generator for X.509 extensions
public class X509ExtensionsGenerator
{
- private IDictionary extensions = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private IList extOrdering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- private static readonly IDictionary dupsAllowed = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private Dictionary m_extensions =
+ new Dictionary();
+ private List m_ordering = new List();
- static X509ExtensionsGenerator()
+ private static readonly ISet m_dupsAllowed = new HashSet()
{
- dupsAllowed.Add(X509Extensions.SubjectAlternativeName, true);
- dupsAllowed.Add(X509Extensions.IssuerAlternativeName, true);
- dupsAllowed.Add(X509Extensions.SubjectDirectoryAttributes, true);
- dupsAllowed.Add(X509Extensions.CertificateIssuer, true);
-
- }
-
-
+ X509Extensions.SubjectAlternativeName,
+ X509Extensions.IssuerAlternativeName,
+ X509Extensions.SubjectDirectoryAttributes,
+ X509Extensions.CertificateIssuer
+ };
/// Reset the generator
public void Reset()
{
- extensions = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- extOrdering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ m_extensions = new Dictionary();
+ m_ordering = new List();
}
///
@@ -40,10 +34,7 @@ public void Reset()
/// OID for the extension.
/// True if critical, false otherwise.
/// The ASN.1 object to be included in the extension.
- public void AddExtension(
- DerObjectIdentifier oid,
- bool critical,
- Asn1Encodable extValue)
+ public void AddExtension(DerObjectIdentifier oid, bool critical, Asn1Encodable extValue)
{
byte[] encoded;
try
@@ -65,38 +56,30 @@ public void AddExtension(
/// OID for the extension.
/// True if critical, false otherwise.
/// The byte array to be wrapped.
- public void AddExtension(
- DerObjectIdentifier oid,
- bool critical,
- byte[] extValue)
+ public void AddExtension(DerObjectIdentifier oid, bool critical, byte[] extValue)
{
- if (extensions.Contains(oid))
+ if (m_extensions.TryGetValue(oid, out X509Extension existingExtension))
{
- if (dupsAllowed.Contains(oid))
- {
- X509Extension existingExtension = (X509Extension)extensions[oid];
-
- Asn1Sequence seq1 = Asn1Sequence.GetInstance(DerOctetString.GetInstance(existingExtension.Value).GetOctets());
- Asn1EncodableVector items = Asn1EncodableVector.FromEnumerable(seq1);
- Asn1Sequence seq2 = Asn1Sequence.GetInstance(extValue);
-
- foreach (Asn1Encodable enc in seq2)
- {
- items.Add(enc);
- }
+ if (!m_dupsAllowed.Contains(oid))
+ throw new ArgumentException("extension " + oid + " already added");
- extensions[oid] = new X509Extension(existingExtension.IsCritical, new DerOctetString(new DerSequence(items).GetEncoded()));
+ Asn1Sequence seq1 = Asn1Sequence.GetInstance(
+ Asn1OctetString.GetInstance(existingExtension.Value).GetOctets());
+ Asn1EncodableVector items = Asn1EncodableVector.FromEnumerable(seq1);
+ Asn1Sequence seq2 = Asn1Sequence.GetInstance(extValue);
- }
- else
+ foreach (Asn1Encodable enc in seq2)
{
- throw new ArgumentException("extension " + oid + " already added");
+ items.Add(enc);
}
+
+ m_extensions[oid] = new X509Extension(existingExtension.IsCritical,
+ new DerOctetString(new DerSequence(items).GetEncoded()));
}
else
{
- extOrdering.Add(oid);
- extensions.Add(oid, new X509Extension(critical, new DerOctetString(extValue)));
+ m_ordering.Add(oid);
+ m_extensions.Add(oid, new X509Extension(critical, new DerOctetString(extValue)));
}
}
@@ -115,25 +98,23 @@ public void AddExtensions(X509Extensions extensions)
/// True if empty, false otherwise
public bool IsEmpty
{
- get { return extOrdering.Count < 1; }
+ get { return m_ordering.Count < 1; }
}
/// Generate an X509Extensions object based on the current state of the generator.
/// An X509Extensions object
public X509Extensions Generate()
{
- return new X509Extensions(extOrdering, extensions);
+ return new X509Extensions(m_ordering, m_extensions);
}
internal void AddExtension(DerObjectIdentifier oid, X509Extension x509Extension)
{
- if (extensions.Contains(oid))
- {
+ if (m_extensions.ContainsKey(oid))
throw new ArgumentException("extension " + oid + " already added");
- }
- extOrdering.Add(oid);
- extensions.Add(oid, x509Extension);
+ m_ordering.Add(oid);
+ m_extensions.Add(oid, x509Extension);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Name.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Name.cs
index 7ec211f..575b211 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Name.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/X509Name.cs
@@ -1,16 +1,13 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text;
-#if SILVERLIGHT || PORTABLE || NETFX_CORE
-using System.Collections.Generic;
-#endif
-
+using BestHTTP.PlatformSupport.Text;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509
@@ -201,153 +198,140 @@ public class X509Name
* determines whether or not strings should be processed and printed
* from back to front.
*/
-// public static bool DefaultReverse = false;
public static bool DefaultReverse
{
- get { return defaultReverse[0]; }
- set { defaultReverse[0] = value; }
+ get { lock (defaultReverse) return defaultReverse[0]; }
+ set { lock (defaultReverse) defaultReverse[0] = value; }
}
private static readonly bool[] defaultReverse = { false };
-#if SILVERLIGHT || PORTABLE || NETFX_CORE
- /**
- * default look up table translating OID values into their common symbols following
- * the convention in RFC 2253 with a few extras
- */
- public static readonly IDictionary DefaultSymbols = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- /**
- * look up table translating OID values into their common symbols following the convention in RFC 2253
- */
- public static readonly IDictionary RFC2253Symbols = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- /**
- * look up table translating OID values into their common symbols following the convention in RFC 1779
- *
- */
- public static readonly IDictionary RFC1779Symbols = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- /**
- * look up table translating common symbols into their OIDS.
- */
- public static readonly IDictionary DefaultLookup = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-#else
/**
* default look up table translating OID values into their common symbols following
* the convention in RFC 2253 with a few extras
*/
- public static readonly Hashtable DefaultSymbols = new Hashtable();
+ private static readonly IDictionary DefaultSymbolsInternal =
+ new Dictionary();
+ public static readonly IDictionary DefaultSymbols =
+ CollectionUtilities.ReadOnly(DefaultSymbolsInternal);
/**
* look up table translating OID values into their common symbols following the convention in RFC 2253
*/
- public static readonly Hashtable RFC2253Symbols = new Hashtable();
+ private static readonly IDictionary RFC2253SymbolsInternal =
+ new Dictionary();
+ public static readonly IDictionary RFC2253Symbols =
+ CollectionUtilities.ReadOnly(RFC2253SymbolsInternal);
/**
* look up table translating OID values into their common symbols following the convention in RFC 1779
*
*/
- public static readonly Hashtable RFC1779Symbols = new Hashtable();
+ private static readonly IDictionary RFC1779SymbolsInternal =
+ new Dictionary();
+ public static readonly IDictionary RFC1779Symbols =
+ CollectionUtilities.ReadOnly(RFC1779SymbolsInternal);
/**
* look up table translating common symbols into their OIDS.
*/
- public static readonly Hashtable DefaultLookup = new Hashtable();
-#endif
+ private static readonly IDictionary DefaultLookupInternal =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ public static readonly IDictionary DefaultLookup =
+ CollectionUtilities.ReadOnly(DefaultLookupInternal);
static X509Name()
{
- DefaultSymbols.Add(C, "C");
- DefaultSymbols.Add(O, "O");
- DefaultSymbols.Add(T, "T");
- DefaultSymbols.Add(OU, "OU");
- DefaultSymbols.Add(CN, "CN");
- DefaultSymbols.Add(L, "L");
- DefaultSymbols.Add(ST, "ST");
- DefaultSymbols.Add(SerialNumber, "SERIALNUMBER");
- DefaultSymbols.Add(EmailAddress, "E");
- DefaultSymbols.Add(DC, "DC");
- DefaultSymbols.Add(UID, "UID");
- DefaultSymbols.Add(Street, "STREET");
- DefaultSymbols.Add(Surname, "SURNAME");
- DefaultSymbols.Add(GivenName, "GIVENNAME");
- DefaultSymbols.Add(Initials, "INITIALS");
- DefaultSymbols.Add(Generation, "GENERATION");
- DefaultSymbols.Add(UnstructuredAddress, "unstructuredAddress");
- DefaultSymbols.Add(UnstructuredName, "unstructuredName");
- DefaultSymbols.Add(UniqueIdentifier, "UniqueIdentifier");
- DefaultSymbols.Add(DnQualifier, "DN");
- DefaultSymbols.Add(Pseudonym, "Pseudonym");
- DefaultSymbols.Add(PostalAddress, "PostalAddress");
- DefaultSymbols.Add(NameAtBirth, "NameAtBirth");
- DefaultSymbols.Add(CountryOfCitizenship, "CountryOfCitizenship");
- DefaultSymbols.Add(CountryOfResidence, "CountryOfResidence");
- DefaultSymbols.Add(Gender, "Gender");
- DefaultSymbols.Add(PlaceOfBirth, "PlaceOfBirth");
- DefaultSymbols.Add(DateOfBirth, "DateOfBirth");
- DefaultSymbols.Add(PostalCode, "PostalCode");
- DefaultSymbols.Add(BusinessCategory, "BusinessCategory");
- DefaultSymbols.Add(TelephoneNumber, "TelephoneNumber");
-
- RFC2253Symbols.Add(C, "C");
- RFC2253Symbols.Add(O, "O");
- RFC2253Symbols.Add(OU, "OU");
- RFC2253Symbols.Add(CN, "CN");
- RFC2253Symbols.Add(L, "L");
- RFC2253Symbols.Add(ST, "ST");
- RFC2253Symbols.Add(Street, "STREET");
- RFC2253Symbols.Add(DC, "DC");
- RFC2253Symbols.Add(UID, "UID");
-
- RFC1779Symbols.Add(C, "C");
- RFC1779Symbols.Add(O, "O");
- RFC1779Symbols.Add(OU, "OU");
- RFC1779Symbols.Add(CN, "CN");
- RFC1779Symbols.Add(L, "L");
- RFC1779Symbols.Add(ST, "ST");
- RFC1779Symbols.Add(Street, "STREET");
-
- DefaultLookup.Add("c", C);
- DefaultLookup.Add("o", O);
- DefaultLookup.Add("t", T);
- DefaultLookup.Add("ou", OU);
- DefaultLookup.Add("cn", CN);
- DefaultLookup.Add("l", L);
- DefaultLookup.Add("st", ST);
- DefaultLookup.Add("serialnumber", SerialNumber);
- DefaultLookup.Add("street", Street);
- DefaultLookup.Add("emailaddress", E);
- DefaultLookup.Add("dc", DC);
- DefaultLookup.Add("e", E);
- DefaultLookup.Add("uid", UID);
- DefaultLookup.Add("surname", Surname);
- DefaultLookup.Add("givenname", GivenName);
- DefaultLookup.Add("initials", Initials);
- DefaultLookup.Add("generation", Generation);
- DefaultLookup.Add("unstructuredaddress", UnstructuredAddress);
- DefaultLookup.Add("unstructuredname", UnstructuredName);
- DefaultLookup.Add("uniqueidentifier", UniqueIdentifier);
- DefaultLookup.Add("dn", DnQualifier);
- DefaultLookup.Add("pseudonym", Pseudonym);
- DefaultLookup.Add("postaladdress", PostalAddress);
- DefaultLookup.Add("nameofbirth", NameAtBirth);
- DefaultLookup.Add("countryofcitizenship", CountryOfCitizenship);
- DefaultLookup.Add("countryofresidence", CountryOfResidence);
- DefaultLookup.Add("gender", Gender);
- DefaultLookup.Add("placeofbirth", PlaceOfBirth);
- DefaultLookup.Add("dateofbirth", DateOfBirth);
- DefaultLookup.Add("postalcode", PostalCode);
- DefaultLookup.Add("businesscategory", BusinessCategory);
- DefaultLookup.Add("telephonenumber", TelephoneNumber);
+ DefaultSymbolsInternal.Add(C, "C");
+ DefaultSymbolsInternal.Add(O, "O");
+ DefaultSymbolsInternal.Add(T, "T");
+ DefaultSymbolsInternal.Add(OU, "OU");
+ DefaultSymbolsInternal.Add(CN, "CN");
+ DefaultSymbolsInternal.Add(L, "L");
+ DefaultSymbolsInternal.Add(ST, "ST");
+ DefaultSymbolsInternal.Add(SerialNumber, "SERIALNUMBER");
+ DefaultSymbolsInternal.Add(EmailAddress, "E");
+ DefaultSymbolsInternal.Add(DC, "DC");
+ DefaultSymbolsInternal.Add(UID, "UID");
+ DefaultSymbolsInternal.Add(Street, "STREET");
+ DefaultSymbolsInternal.Add(Surname, "SURNAME");
+ DefaultSymbolsInternal.Add(GivenName, "GIVENNAME");
+ DefaultSymbolsInternal.Add(Initials, "INITIALS");
+ DefaultSymbolsInternal.Add(Generation, "GENERATION");
+ DefaultSymbolsInternal.Add(UnstructuredAddress, "unstructuredAddress");
+ DefaultSymbolsInternal.Add(UnstructuredName, "unstructuredName");
+ DefaultSymbolsInternal.Add(UniqueIdentifier, "UniqueIdentifier");
+ DefaultSymbolsInternal.Add(DnQualifier, "DN");
+ DefaultSymbolsInternal.Add(Pseudonym, "Pseudonym");
+ DefaultSymbolsInternal.Add(PostalAddress, "PostalAddress");
+ DefaultSymbolsInternal.Add(NameAtBirth, "NameAtBirth");
+ DefaultSymbolsInternal.Add(CountryOfCitizenship, "CountryOfCitizenship");
+ DefaultSymbolsInternal.Add(CountryOfResidence, "CountryOfResidence");
+ DefaultSymbolsInternal.Add(Gender, "Gender");
+ DefaultSymbolsInternal.Add(PlaceOfBirth, "PlaceOfBirth");
+ DefaultSymbolsInternal.Add(DateOfBirth, "DateOfBirth");
+ DefaultSymbolsInternal.Add(PostalCode, "PostalCode");
+ DefaultSymbolsInternal.Add(BusinessCategory, "BusinessCategory");
+ DefaultSymbolsInternal.Add(TelephoneNumber, "TelephoneNumber");
+
+ RFC2253SymbolsInternal.Add(C, "C");
+ RFC2253SymbolsInternal.Add(O, "O");
+ RFC2253SymbolsInternal.Add(OU, "OU");
+ RFC2253SymbolsInternal.Add(CN, "CN");
+ RFC2253SymbolsInternal.Add(L, "L");
+ RFC2253SymbolsInternal.Add(ST, "ST");
+ RFC2253SymbolsInternal.Add(Street, "STREET");
+ RFC2253SymbolsInternal.Add(DC, "DC");
+ RFC2253SymbolsInternal.Add(UID, "UID");
+
+ RFC1779SymbolsInternal.Add(C, "C");
+ RFC1779SymbolsInternal.Add(O, "O");
+ RFC1779SymbolsInternal.Add(OU, "OU");
+ RFC1779SymbolsInternal.Add(CN, "CN");
+ RFC1779SymbolsInternal.Add(L, "L");
+ RFC1779SymbolsInternal.Add(ST, "ST");
+ RFC1779SymbolsInternal.Add(Street, "STREET");
+
+ DefaultLookupInternal.Add("c", C);
+ DefaultLookupInternal.Add("o", O);
+ DefaultLookupInternal.Add("t", T);
+ DefaultLookupInternal.Add("ou", OU);
+ DefaultLookupInternal.Add("cn", CN);
+ DefaultLookupInternal.Add("l", L);
+ DefaultLookupInternal.Add("st", ST);
+ DefaultLookupInternal.Add("serialnumber", SerialNumber);
+ DefaultLookupInternal.Add("street", Street);
+ DefaultLookupInternal.Add("emailaddress", E);
+ DefaultLookupInternal.Add("dc", DC);
+ DefaultLookupInternal.Add("e", E);
+ DefaultLookupInternal.Add("uid", UID);
+ DefaultLookupInternal.Add("surname", Surname);
+ DefaultLookupInternal.Add("givenname", GivenName);
+ DefaultLookupInternal.Add("initials", Initials);
+ DefaultLookupInternal.Add("generation", Generation);
+ DefaultLookupInternal.Add("unstructuredaddress", UnstructuredAddress);
+ DefaultLookupInternal.Add("unstructuredname", UnstructuredName);
+ DefaultLookupInternal.Add("uniqueidentifier", UniqueIdentifier);
+ DefaultLookupInternal.Add("dn", DnQualifier);
+ DefaultLookupInternal.Add("pseudonym", Pseudonym);
+ DefaultLookupInternal.Add("postaladdress", PostalAddress);
+ DefaultLookupInternal.Add("nameofbirth", NameAtBirth);
+ DefaultLookupInternal.Add("countryofcitizenship", CountryOfCitizenship);
+ DefaultLookupInternal.Add("countryofresidence", CountryOfResidence);
+ DefaultLookupInternal.Add("gender", Gender);
+ DefaultLookupInternal.Add("placeofbirth", PlaceOfBirth);
+ DefaultLookupInternal.Add("dateofbirth", DateOfBirth);
+ DefaultLookupInternal.Add("postalcode", PostalCode);
+ DefaultLookupInternal.Add("businesscategory", BusinessCategory);
+ DefaultLookupInternal.Add("telephonenumber", TelephoneNumber);
}
- private readonly IList ordering = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ private readonly List ordering = new List();
private readonly X509NameEntryConverter converter;
- private IList values = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- private IList added = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- private Asn1Sequence seq;
+ private IList values = new List();
+ private IList added = new List();
+ private Asn1Sequence seq;
/**
* Return a X509Name based on the passed in tagged object.
@@ -382,8 +366,7 @@ protected X509Name()
*
* the principal will be a list of constructed sets, each containing an (OID, string) pair.
*/
- protected X509Name(
- Asn1Sequence seq)
+ protected X509Name(Asn1Sequence seq)
{
this.seq = seq;
@@ -404,7 +387,11 @@ protected X509Name(
if (derValue is IAsn1String && !(derValue is DerUniversalString))
{
string v = ((IAsn1String)derValue).GetString();
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(v, "#"))
+#if NET_STANDARD_2_1
+ if (v.StartsWith('#'))
+#else
+ if (v.StartsWith("#"))
+#endif
{
v = "\\" + v;
}
@@ -430,8 +417,8 @@ protected X509Name(
* in the order they are meant to be encoded or printed in ToString.
*/
public X509Name(
- IList ordering,
- IDictionary attributes)
+ IList ordering,
+ IDictionary attributes)
: this(ordering, attributes, new X509DefaultEntryConverter())
{
}
@@ -448,19 +435,22 @@ public X509Name(
* ASN.1 counterparts.
*/
public X509Name(
- IList ordering,
- IDictionary attributes,
+ IList ordering,
+ IDictionary attributes,
X509NameEntryConverter converter)
{
this.converter = converter;
foreach (DerObjectIdentifier oid in ordering)
{
- object attribute = attributes[oid];
- if (attribute == null)
- {
+ if (!attributes.TryGetValue(oid, out var attribute))
throw new ArgumentException("No attribute for object id - " + oid + " - passed to distinguished name");
- }
+
+ //object attribute = attributes[oid];
+ //if (attribute == null)
+ //{
+ // throw new ArgumentException("No attribute for object id - " + oid + " - passed to distinguished name");
+ //}
this.ordering.Add(oid);
this.added.Add(false);
@@ -471,9 +461,7 @@ public X509Name(
/**
* Takes two vectors one of the oids and the other of the values.
*/
- public X509Name(
- IList oids,
- IList values)
+ public X509Name(IList oids, IList values)
: this(oids, values, new X509DefaultEntryConverter())
{
}
@@ -484,17 +472,12 @@ public X509Name(
* The passed in converter will be used to convert the strings into their
* ASN.1 counterparts.
*/
- public X509Name(
- IList oids,
- IList values,
- X509NameEntryConverter converter)
+ public X509Name(IList oids, IList values, X509NameEntryConverter converter)
{
this.converter = converter;
if (oids.Count != values.Count)
- {
throw new ArgumentException("'oids' must be same length as 'values'.");
- }
for (int i = 0; i < oids.Count; i++)
{
@@ -508,9 +491,8 @@ public X509Name(
* Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or
* some such, converting it into an ordered set of name attributes.
*/
- public X509Name(
- string dirName)
- : this(DefaultReverse, (IDictionary)DefaultLookup, dirName)
+ public X509Name(string dirName)
+ : this(DefaultReverse, DefaultLookup, dirName)
{
}
@@ -520,9 +502,7 @@ public X509Name(
* string value being converted to its associated ASN.1 type using the passed
* in converter.
*/
- public X509Name(
- string dirName,
- X509NameEntryConverter converter)
+ public X509Name(string dirName, X509NameEntryConverter converter)
: this(DefaultReverse, DefaultLookup, dirName, converter)
{
}
@@ -533,10 +513,8 @@ public X509Name(
* is true, create the encoded version of the sequence starting from the
* last element in the string.
*/
- public X509Name(
- bool reverse,
- string dirName)
- : this(reverse, (IDictionary)DefaultLookup, dirName)
+ public X509Name(bool reverse, string dirName)
+ : this(reverse, DefaultLookup, dirName)
{
}
@@ -547,10 +525,7 @@ public X509Name(
* in converter. If reverse is true the ASN.1 sequence representing the DN will
* be built by starting at the end of the string, rather than the start.
*/
- public X509Name(
- bool reverse,
- string dirName,
- X509NameEntryConverter converter)
+ public X509Name(bool reverse, string dirName, X509NameEntryConverter converter)
: this(reverse, DefaultLookup, dirName, converter)
{
}
@@ -568,34 +543,23 @@ public X509Name(
* @param lookUp table of names and their oids.
* @param dirName the X.500 string to be parsed.
*/
- public X509Name(
- bool reverse,
- IDictionary lookUp,
- string dirName)
- : this(reverse, lookUp, dirName, new X509DefaultEntryConverter())
+ public X509Name(bool reverse, IDictionary lookup, string dirName)
+ : this(reverse, lookup, dirName, new X509DefaultEntryConverter())
{
}
- private DerObjectIdentifier DecodeOid(
- string name,
- IDictionary lookUp)
+ private DerObjectIdentifier DecodeOid(string name, IDictionary lookup)
{
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), "OID."))
- {
- return new DerObjectIdentifier(name.Substring(4));
- }
- else if (name[0] >= '0' && name[0] <= '9')
- {
+ if (name.StartsWith("OID.", StringComparison.OrdinalIgnoreCase))
+ return new DerObjectIdentifier(name.Substring("OID.".Length));
+
+ if (name[0] >= '0' && name[0] <= '9')
return new DerObjectIdentifier(name);
- }
- DerObjectIdentifier oid = (DerObjectIdentifier)lookUp[BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToLowerInvariant(name)];
- if (oid == null)
- {
- throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name");
- }
+ if (lookup.TryGetValue(name, out var oid))
+ return oid;
- return oid;
+ throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name");
}
/**
@@ -611,11 +575,8 @@ private DerObjectIdentifier DecodeOid(
* @param dirName the string dirName
* @param converter the converter to convert string values into their ASN.1 equivalents
*/
- public X509Name(
- bool reverse,
- IDictionary lookUp,
- string dirName,
- X509NameEntryConverter converter)
+ public X509Name(bool reverse, IDictionary lookup, string dirName,
+ X509NameEntryConverter converter)
{
this.converter = converter;
X509NameTokenizer nTok = new X509NameTokenizer(dirName);
@@ -626,13 +587,11 @@ public X509Name(
int index = token.IndexOf('=');
if (index == -1)
- {
throw new ArgumentException("badly formated directory string");
- }
string name = token.Substring(0, index);
string value = token.Substring(index + 1);
- DerObjectIdentifier oid = DecodeOid(name, lookUp);
+ DerObjectIdentifier oid = DecodeOid(name, lookup);
if (value.IndexOf('+') > 0)
{
@@ -650,7 +609,7 @@ public X509Name(
string nm = sv.Substring(0, ndx);
string vl = sv.Substring(ndx + 1);
- this.ordering.Add(DecodeOid(nm, lookUp));
+ this.ordering.Add(DecodeOid(nm, lookup));
this.values.Add(vl);
this.added.Add(true);
}
@@ -668,9 +627,9 @@ public X509Name(
// this.ordering.Reverse();
// this.values.Reverse();
// this.added.Reverse();
- IList o = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- IList v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- IList a = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var o = new List();
+ var v = new List();
+ var a = new List();
int count = 1;
for (int i = 0; i < this.ordering.Count; i++)
@@ -696,16 +655,16 @@ public X509Name(
/**
* return an IList of the oids in the name, in the order they were found.
*/
- public IList GetOidList()
+ public IList GetOidList()
{
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(ordering);
+ return new List(ordering);
}
/**
* return an IList of the values found in the name, in the order they
* were found.
*/
- public IList GetValueList()
+ public IList GetValueList()
{
return GetValueList(null);
}
@@ -714,16 +673,15 @@ public IList GetValueList()
* return an IList of the values found in the name, in the order they
* were found, with the DN label corresponding to passed in oid.
*/
- public IList GetValueList(DerObjectIdentifier oid)
+ public IList GetValueList(DerObjectIdentifier oid)
{
- IList v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var v = new List();
for (int i = 0; i != values.Count; i++)
{
if (null == oid || oid.Equals(ordering[i]))
{
string val = (string)values[i];
-
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(val, "\\#"))
+ if (val.StartsWith("\\#", StringComparison.OrdinalIgnoreCase))
{
val = val.Substring(1);
}
@@ -805,7 +763,7 @@ public bool Equivalent(
string val = (string) values[i];
string oVal = (string) other.values[i];
- if (!equivalentStrings(val, oVal))
+ if (!EquivalentStrings(val, oVal))
return false;
}
@@ -866,7 +824,7 @@ public bool Equivalent(
{
string oValue = (string)other.values[j];
- if (equivalentStrings(value, oValue))
+ if (EquivalentStrings(value, oValue))
{
indexes[j] = true;
found = true;
@@ -884,47 +842,44 @@ public bool Equivalent(
return true;
}
- private static bool equivalentStrings(
- string s1,
- string s2)
+ private static bool EquivalentStrings(string s1, string s2)
{
- string v1 = canonicalize(s1);
- string v2 = canonicalize(s2);
+ string v1 = Canonicalize(s1);
+ string v2 = Canonicalize(s2);
if (!v1.Equals(v2))
{
- v1 = stripInternalSpaces(v1);
- v2 = stripInternalSpaces(v2);
+ v1 = StripInternalSpaces(v1);
+ v2 = StripInternalSpaces(v2);
if (!v1.Equals(v2))
- {
return false;
- }
}
return true;
}
- private static string canonicalize(
- string s)
+ private static string Canonicalize(string s)
{
- string v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToLowerInvariant(s).Trim();
+ string v = s.ToLowerInvariant().Trim();
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(v, "#"))
+#if NET_STANDARD_2_1
+ if (v.StartsWith('#'))
+#else
+ if (v.StartsWith("#"))
+#endif
{
- Asn1Object obj = decodeObject(v);
-
- if (obj is IAsn1String)
+ Asn1Object obj = DecodeObject(v);
+ if (obj is IAsn1String str)
{
- v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToLowerInvariant(((IAsn1String)obj).GetString()).Trim();
+ v = str.GetString().ToLowerInvariant().Trim();
}
}
return v;
}
- private static Asn1Object decodeObject(
- string v)
+ private static Asn1Object DecodeObject(string v)
{
try
{
@@ -936,8 +891,7 @@ private static Asn1Object decodeObject(
}
}
- private static string stripInternalSpaces(
- string str)
+ private static string StripInternalSpaces(string str)
{
StringBuilder res = new StringBuilder();
@@ -961,15 +915,10 @@ private static string stripInternalSpaces(
return res.ToString();
}
- private void AppendValue(
- StringBuilder buf,
- IDictionary oidSymbols,
- DerObjectIdentifier oid,
- string val)
+ private void AppendValue(StringBuilder buf, IDictionary oidSymbols,
+ DerObjectIdentifier oid, string val)
{
- string sym = (string)oidSymbols[oid];
-
- if (sym != null)
+ if (oidSymbols.TryGetValue(oid, out var sym))
{
buf.Append(sym);
}
@@ -986,7 +935,7 @@ private void AppendValue(
int end = buf.Length;
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(val, "\\#"))
+ if (val.StartsWith("\\#", StringComparison.OrdinalIgnoreCase))
{
index += 2;
}
@@ -1022,33 +971,23 @@ private void AppendValue(
* @param reverse if true start at the end of the sequence and work back.
* @param oidSymbols look up table strings for oids.
*/
- public string ToString(
- bool reverse,
- IDictionary oidSymbols)
+ public string ToString(bool reverse, IDictionary oidSymbols)
{
-#if SILVERLIGHT || PORTABLE || NETFX_CORE
- List components = new List();
-#else
- ArrayList components = new ArrayList();
-#endif
+ var components = new List();
StringBuilder ava = null;
for (int i = 0; i < ordering.Count; i++)
{
- if ((bool) added[i])
+ if (added[i])
{
ava.Append('+');
- AppendValue(ava, oidSymbols,
- (DerObjectIdentifier)ordering[i],
- (string)values[i]);
+ AppendValue(ava, oidSymbols, ordering[i], values[i]);
}
else
{
- ava = new StringBuilder();
- AppendValue(ava, oidSymbols,
- (DerObjectIdentifier)ordering[i],
- (string)values[i]);
+ ava = StringBuilderPool.Get(0); //new StringBuilder();
+ AppendValue(ava, oidSymbols, ordering[i], values[i]);
components.Add(ava);
}
}
@@ -1058,26 +997,26 @@ public string ToString(
components.Reverse();
}
- StringBuilder buf = new StringBuilder();
+ StringBuilder buf = StringBuilderPool.Get(components.Count); //new StringBuilder();
if (components.Count > 0)
{
- buf.Append(components[0].ToString());
+ buf.Append(StringBuilderPool.ReleaseAndGrab(components[0]));
for (int i = 1; i < components.Count; ++i)
{
buf.Append(',');
- buf.Append(components[i].ToString());
+ buf.Append(StringBuilderPool.ReleaseAndGrab(components[i]));
}
}
- return buf.ToString();
+ return StringBuilderPool.ReleaseAndGrab(buf);
}
string cachedStrRepresentation = null;
public override string ToString()
{
- return cachedStrRepresentation ?? (cachedStrRepresentation = ToString(DefaultReverse, (IDictionary)DefaultSymbols));
+ return cachedStrRepresentation ?? (cachedStrRepresentation = ToString(DefaultReverse, DefaultSymbols));
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/BiometricData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/BiometricData.cs
index 5fb0dd9..de6bd1b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/BiometricData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/BiometricData.cs
@@ -37,7 +37,7 @@ public static BiometricData GetInstance(
return new BiometricData(Asn1Sequence.GetInstance(obj));
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private BiometricData(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/Iso4217CurrencyCode.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/Iso4217CurrencyCode.cs
index 66e0dfc..87e732e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/Iso4217CurrencyCode.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/Iso4217CurrencyCode.cs
@@ -47,7 +47,7 @@ public static Iso4217CurrencyCode GetInstance(
return new Iso4217CurrencyCode(alphabetic.GetString());
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public Iso4217CurrencyCode(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/MonetaryValue.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/MonetaryValue.cs
index 9ce3b11..18cffe2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/MonetaryValue.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/MonetaryValue.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -38,7 +37,7 @@ public static MonetaryValue GetInstance(
return new MonetaryValue(Asn1Sequence.GetInstance(obj));
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private MonetaryValue(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/QCStatement.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/QCStatement.cs
index 306b99c..30081c3 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/QCStatement.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/QCStatement.cs
@@ -33,7 +33,7 @@ public static QCStatement GetInstance(
return new QCStatement(Asn1Sequence.GetInstance(obj));
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
private QCStatement(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/SemanticsInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/SemanticsInformation.cs
index a3998a6..75ee42b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/SemanticsInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/SemanticsInformation.cs
@@ -1,9 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509.Qualified
@@ -41,36 +39,33 @@ public static SemanticsInformation GetInstance(
return new SemanticsInformation(Asn1Sequence.GetInstance(obj));
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
- public SemanticsInformation(
- Asn1Sequence seq)
+ public SemanticsInformation(Asn1Sequence seq)
{
if (seq.Count < 1)
- {
throw new ArgumentException("no objects in SemanticsInformation");
- }
- IEnumerator e = seq.GetEnumerator();
+ var e = seq.GetEnumerator();
e.MoveNext();
- object obj = e.Current;
- if (obj is DerObjectIdentifier)
+ var obj = e.Current;
+ if (obj is DerObjectIdentifier oid)
{
- semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
+ semanticsIdentifier = oid;
if (e.MoveNext())
{
- obj = e.Current;
+ obj = e.Current;
}
else
{
- obj = null;
+ obj = null;
}
}
- if (obj != null)
+ if (obj != null)
{
- Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj );
+ Asn1Sequence generalNameSeq = Asn1Sequence.GetInstance(obj);
nameRegistrationAuthorities = new GeneralName[generalNameSeq.Count];
for (int i= 0; i < generalNameSeq.Count; i++)
{
@@ -99,7 +94,10 @@ public SemanticsInformation(
this.nameRegistrationAuthorities = generalNames;
}
- public DerObjectIdentifier SemanticsIdentifier { get { return semanticsIdentifier; } }
+ public DerObjectIdentifier SemanticsIdentifier
+ {
+ get { return semanticsIdentifier; }
+ }
public GeneralName[] GetNameRegistrationAuthorities()
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/TypeOfBiometricData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/TypeOfBiometricData.cs
index d9f4c76..5099d90 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/TypeOfBiometricData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/qualified/TypeOfBiometricData.cs
@@ -48,7 +48,7 @@ public static TypeOfBiometricData GetInstance(
return new TypeOfBiometricData(BiometricDataOid);
}
- throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public TypeOfBiometricData(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/NameOrPseudonym.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/NameOrPseudonym.cs
index f8e46f9..1096640 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/NameOrPseudonym.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/NameOrPseudonym.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X500;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -49,7 +48,7 @@ public static NameOrPseudonym GetInstance(
return new NameOrPseudonym((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
@@ -98,7 +97,7 @@ private NameOrPseudonym(
throw new ArgumentException("Bad sequence size: " + seq.Count);
if (!(seq[0] is IAsn1String))
- throw new ArgumentException("Bad object encountered: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(seq[0]));
+ throw new ArgumentException("Bad object encountered: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(seq[0]));
surname = DirectoryString.GetInstance(seq[0]);
givenName = Asn1Sequence.GetInstance(seq[1]);
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/PersonalData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/PersonalData.cs
index 9403fad..b117195 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/PersonalData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x509/sigi/PersonalData.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X500;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
@@ -32,7 +31,7 @@ public class PersonalData
{
private readonly NameOrPseudonym nameOrPseudonym;
private readonly BigInteger nameDistinguisher;
- private readonly DerGeneralizedTime dateOfBirth;
+ private readonly Asn1GeneralizedTime dateOfBirth;
private readonly DirectoryString placeOfBirth;
private readonly string gender;
private readonly DirectoryString postalAddress;
@@ -50,7 +49,7 @@ public static PersonalData GetInstance(
return new PersonalData((Asn1Sequence) obj);
}
- throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("unknown object in factory: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
/**
@@ -71,13 +70,12 @@ public static PersonalData GetInstance(
*
* @param seq The ASN.1 sequence.
*/
- private PersonalData(
- Asn1Sequence seq)
+ private PersonalData(Asn1Sequence seq)
{
if (seq.Count < 1)
throw new ArgumentException("Bad sequence size: " + seq.Count);
- IEnumerator e = seq.GetEnumerator();
+ var e = seq.GetEnumerator();
e.MoveNext();
nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);
@@ -88,23 +86,23 @@ private PersonalData(
int tag = o.TagNo;
switch (tag)
{
- case 0:
- nameDistinguisher = DerInteger.GetInstance(o, false).Value;
- break;
- case 1:
- dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
- break;
- case 2:
- placeOfBirth = DirectoryString.GetInstance(o, true);
- break;
- case 3:
- gender = DerPrintableString.GetInstance(o, false).GetString();
- break;
- case 4:
- postalAddress = DirectoryString.GetInstance(o, true);
- break;
- default:
- throw new ArgumentException("Bad tag number: " + o.TagNo);
+ case 0:
+ nameDistinguisher = DerInteger.GetInstance(o, false).Value;
+ break;
+ case 1:
+ dateOfBirth = Asn1GeneralizedTime.GetInstance(o, false);
+ break;
+ case 2:
+ placeOfBirth = DirectoryString.GetInstance(o, true);
+ break;
+ case 3:
+ gender = DerPrintableString.GetInstance(o, false).GetString();
+ break;
+ case 4:
+ postalAddress = DirectoryString.GetInstance(o, true);
+ break;
+ default:
+ throw new ArgumentException("Bad tag number: " + o.TagNo);
}
}
}
@@ -122,7 +120,7 @@ private PersonalData(
public PersonalData(
NameOrPseudonym nameOrPseudonym,
BigInteger nameDistinguisher,
- DerGeneralizedTime dateOfBirth,
+ Asn1GeneralizedTime dateOfBirth,
DirectoryString placeOfBirth,
string gender,
DirectoryString postalAddress)
@@ -145,7 +143,7 @@ public BigInteger NameDistinguisher
get { return nameDistinguisher; }
}
- public DerGeneralizedTime DateOfBirth
+ public Asn1GeneralizedTime DateOfBirth
{
get { return dateOfBirth; }
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHDomainParameters.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHDomainParameters.cs
index 732a6dd..6b4c1a0 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHDomainParameters.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHDomainParameters.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -26,7 +26,7 @@ public static DHDomainParameters GetInstance(object obj)
if (obj is Asn1Sequence)
return new DHDomainParameters((Asn1Sequence)obj);
- throw new ArgumentException("Invalid DHDomainParameters: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("Invalid DHDomainParameters: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public DHDomainParameters(DerInteger p, DerInteger g, DerInteger q, DerInteger j,
@@ -51,7 +51,7 @@ private DHDomainParameters(Asn1Sequence seq)
if (seq.Count < 3 || seq.Count > 5)
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
- IEnumerator e = seq.GetEnumerator();
+ var e = seq.GetEnumerator();
this.p = DerInteger.GetInstance(GetNext(e));
this.g = DerInteger.GetInstance(GetNext(e));
this.q = DerInteger.GetInstance(GetNext(e));
@@ -70,7 +70,7 @@ private DHDomainParameters(Asn1Sequence seq)
}
}
- private static Asn1Encodable GetNext(IEnumerator e)
+ private static Asn1Encodable GetNext(IEnumerator e)
{
return e.MoveNext() ? (Asn1Encodable)e.Current : null;
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHPublicKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHPublicKey.cs
index 3009c80..852baa1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHPublicKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHPublicKey.cs
@@ -24,7 +24,7 @@ public static DHPublicKey GetInstance(object obj)
if (obj is DerInteger)
return new DHPublicKey((DerInteger)obj);
- throw new ArgumentException("Invalid DHPublicKey: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("Invalid DHPublicKey: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public DHPublicKey(DerInteger y)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHValidationParms.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHValidationParms.cs
index aa897ea..a787f39 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHValidationParms.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/DHValidationParms.cs
@@ -25,7 +25,7 @@ public static DHValidationParms GetInstance(object obj)
if (obj is Asn1Sequence)
return new DHValidationParms((Asn1Sequence)obj);
- throw new ArgumentException("Invalid DHValidationParms: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
+ throw new ArgumentException("Invalid DHValidationParms: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
}
public DHValidationParms(DerBitString seed, DerInteger pgenCounter)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/ECNamedCurveTable.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/ECNamedCurveTable.cs
index 90a4e8b..9a33f70 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/ECNamedCurveTable.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/ECNamedCurveTable.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Anssi;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
@@ -9,23 +9,14 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Sec;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
{
- /**
- * A general class that reads all X9.62 style EC curve tables.
- */
+ /// A unified elliptic curve registry of the various standard-specific registries.
public class ECNamedCurveTable
{
- /**
- * return a X9ECParameters object representing the passed in named
- * curve. The routine returns null if the curve is not present.
- *
- * @param name the name of the curve requested
- * @return an X9ECParameters object or null if the curve is not available.
- */
+ /// Look up the for the curve with the given name.
+ /// The name of the curve.
public static X9ECParameters GetByName(string name)
{
X9ECParameters ecP = X962NamedCurves.GetByName(name);
@@ -47,7 +38,7 @@ public static X9ECParameters GetByName(string name)
}
if (ecP == null)
{
- ecP = ECGost3410NamedCurves.GetByNameX9(name);
+ ecP = ECGost3410NamedCurves.GetByName(name);
}
if (ecP == null)
{
@@ -56,6 +47,112 @@ public static X9ECParameters GetByName(string name)
return ecP;
}
+ /// Look up an for the curve with the given name.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of
+ /// the full .
+ ///
+ /// The name of the curve.
+ public static X9ECParametersHolder GetByNameLazy(string name)
+ {
+ X9ECParametersHolder holder = X962NamedCurves.GetByNameLazy(name);
+ if (null == holder)
+ {
+ holder = SecNamedCurves.GetByNameLazy(name);
+ }
+ if (null == holder)
+ {
+ holder = NistNamedCurves.GetByNameLazy(name);
+ }
+ if (null == holder)
+ {
+ holder = TeleTrusTNamedCurves.GetByNameLazy(name);
+ }
+ if (null == holder)
+ {
+ holder = AnssiNamedCurves.GetByNameLazy(name);
+ }
+ if (null == holder)
+ {
+ holder = ECGost3410NamedCurves.GetByNameLazy(name);
+ }
+ if (null == holder)
+ {
+ holder = GMNamedCurves.GetByNameLazy(name);
+ }
+ return holder;
+ }
+
+ /// Look up the for the curve with the given
+ /// OID.
+ /// The OID for the curve.
+ public static X9ECParameters GetByOid(DerObjectIdentifier oid)
+ {
+ X9ECParameters ecP = X962NamedCurves.GetByOid(oid);
+ if (ecP == null)
+ {
+ ecP = SecNamedCurves.GetByOid(oid);
+ }
+
+ // NOTE: All the NIST curves are currently from SEC, so no point in redundant OID lookup
+
+ if (ecP == null)
+ {
+ ecP = TeleTrusTNamedCurves.GetByOid(oid);
+ }
+ if (ecP == null)
+ {
+ ecP = AnssiNamedCurves.GetByOid(oid);
+ }
+ if (ecP == null)
+ {
+ ecP = ECGost3410NamedCurves.GetByOid(oid);
+ }
+ if (ecP == null)
+ {
+ ecP = GMNamedCurves.GetByOid(oid);
+ }
+ return ecP;
+ }
+
+ /// Look up an for the curve with the given
+ /// OID.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of
+ /// the full .
+ ///
+ /// The OID for the curve.
+ public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
+ {
+ X9ECParametersHolder holder = X962NamedCurves.GetByOidLazy(oid);
+ if (null == holder)
+ {
+ holder = SecNamedCurves.GetByOidLazy(oid);
+ }
+
+ // NOTE: All the NIST curves are currently from SEC, so no point in redundant OID lookup
+
+ if (null == holder)
+ {
+ holder = TeleTrusTNamedCurves.GetByOidLazy(oid);
+ }
+ if (null == holder)
+ {
+ holder = AnssiNamedCurves.GetByOidLazy(oid);
+ }
+ if (null == holder)
+ {
+ holder = ECGost3410NamedCurves.GetByOidLazy(oid);
+ }
+ if (null == holder)
+ {
+ holder = GMNamedCurves.GetByOidLazy(oid);
+ }
+ return holder;
+ }
+
+ /// Look up the name of the curve with the given OID.
+ /// The OID for the curve.
public static string GetName(DerObjectIdentifier oid)
{
string name = X962NamedCurves.GetName(oid);
@@ -86,12 +183,8 @@ public static string GetName(DerObjectIdentifier oid)
return name;
}
- /**
- * return the object identifier signified by the passed in name. Null
- * if there is no object identifier associated with name.
- *
- * @return the object identifier associated with name, if present.
- */
+ /// Look up the OID of the curve with the given name.
+ /// The name of the curve.
public static DerObjectIdentifier GetOid(string name)
{
DerObjectIdentifier oid = X962NamedCurves.GetOid(name);
@@ -122,60 +215,20 @@ public static DerObjectIdentifier GetOid(string name)
return oid;
}
- /**
- * return a X9ECParameters object representing the passed in named
- * curve.
- *
- * @param oid the object id of the curve requested
- * @return an X9ECParameters object or null if the curve is not available.
- */
- public static X9ECParameters GetByOid(DerObjectIdentifier oid)
- {
- X9ECParameters ecP = X962NamedCurves.GetByOid(oid);
- if (ecP == null)
- {
- ecP = SecNamedCurves.GetByOid(oid);
- }
-
- // NOTE: All the NIST curves are currently from SEC, so no point in redundant OID lookup
-
- if (ecP == null)
- {
- ecP = TeleTrusTNamedCurves.GetByOid(oid);
- }
- if (ecP == null)
- {
- ecP = AnssiNamedCurves.GetByOid(oid);
- }
- if (ecP == null)
- {
- ecP = ECGost3410NamedCurves.GetByOidX9(oid);
- }
- if (ecP == null)
- {
- ecP = GMNamedCurves.GetByOid(oid);
- }
- return ecP;
- }
-
- /**
- * return an enumeration of the names of the available curves.
- *
- * @return an enumeration of the names of the available curves.
- */
- public static IEnumerable Names
+ /// Enumerate the available curve names in all the registries.
+ public static IEnumerable Names
{
get
{
- IList v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- CollectionUtilities.AddRange(v, X962NamedCurves.Names);
- CollectionUtilities.AddRange(v, SecNamedCurves.Names);
- CollectionUtilities.AddRange(v, NistNamedCurves.Names);
- CollectionUtilities.AddRange(v, TeleTrusTNamedCurves.Names);
- CollectionUtilities.AddRange(v, AnssiNamedCurves.Names);
- CollectionUtilities.AddRange(v, ECGost3410NamedCurves.Names);
- CollectionUtilities.AddRange(v, GMNamedCurves.Names);
- return v;
+ var result = new List();
+ result.AddRange(X962NamedCurves.Names);
+ result.AddRange(SecNamedCurves.Names);
+ result.AddRange(NistNamedCurves.Names);
+ result.AddRange(TeleTrusTNamedCurves.Names);
+ result.AddRange(AnssiNamedCurves.Names);
+ result.AddRange(ECGost3410NamedCurves.Names);
+ result.AddRange(GMNamedCurves.Names);
+ return result;
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/KeySpecificInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/KeySpecificInfo.cs
index 2b47a58..e732e19 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/KeySpecificInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/KeySpecificInfo.cs
@@ -1,7 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System.Collections;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
{
/**
@@ -22,10 +20,9 @@ public KeySpecificInfo(
this.counter = counter;
}
- public KeySpecificInfo(
- Asn1Sequence seq)
+ public KeySpecificInfo(Asn1Sequence seq)
{
- IEnumerator e = seq.GetEnumerator();
+ var e = seq.GetEnumerator();
e.MoveNext();
algorithm = (DerObjectIdentifier)e.Current;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/OtherInfo.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/OtherInfo.cs
index fafb6b5..54ab5be 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/OtherInfo.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/OtherInfo.cs
@@ -1,7 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System.Collections;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
{
/**
@@ -25,25 +23,24 @@ public OtherInfo(
this.suppPubInfo = suppPubInfo;
}
- public OtherInfo(
- Asn1Sequence seq)
+ public OtherInfo(Asn1Sequence seq)
{
- IEnumerator e = seq.GetEnumerator();
+ var e = seq.GetEnumerator();
e.MoveNext();
- keyInfo = new KeySpecificInfo((Asn1Sequence) e.Current);
+ keyInfo = new KeySpecificInfo((Asn1Sequence)e.Current);
while (e.MoveNext())
{
- DerTaggedObject o = (DerTaggedObject) e.Current;
+ Asn1TaggedObject o = (Asn1TaggedObject)e.Current;
if (o.TagNo == 0)
{
- partyAInfo = (Asn1OctetString) o.GetObject();
+ partyAInfo = (Asn1OctetString)o.GetObject();
}
else if ((int) o.TagNo == 2)
{
- suppPubInfo = (Asn1OctetString) o.GetObject();
+ suppPubInfo = (Asn1OctetString)o.GetObject();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962NamedCurves.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962NamedCurves.cs
index 11087ee..1e6f15c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962NamedCurves.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962NamedCurves.cs
@@ -1,26 +1,19 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Encoders;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
{
- /**
- * table of the current named curves defined in X.962 EC-DSA.
- */
- public sealed class X962NamedCurves
+ /// Elliptic curve registry for the curves defined in X.962 EC-DSA.
+ public static class X962NamedCurves
{
- private X962NamedCurves()
- {
- }
-
private static X9ECPoint ConfigureBasepoint(ECCurve curve, string encoding)
{
X9ECPoint G = new X9ECPoint(curve, Hex.DecodeStrict(encoding));
@@ -45,21 +38,27 @@ private Prime192v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime192v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("ffffffffffffffffffffffff99def836146bc9b1b4d22831");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"),
FromHex("fffffffffffffffffffffffffffffffefffffffffffffffc"),
FromHex("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("3045AE6FC8422f64ED579528D38120EAE12196D5");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("3045AE6FC8422f64ED579528D38120EAE12196D5"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -70,21 +69,27 @@ private Prime192v2Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime192v2Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("fffffffffffffffffffffffe5fb1a724dc80418648d8dd31");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"),
FromHex("fffffffffffffffffffffffffffffffefffffffffffffffc"),
FromHex("cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("31a92ee2029fd10d901b113e990710f0d21ac6b6");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"03eea2bae7e1497842f2de7769cfe9c989c072ad696f48034a");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("31a92ee2029fd10d901b113e990710f0d21ac6b6"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -95,21 +100,27 @@ private Prime192v3Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime192v3Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("ffffffffffffffffffffffff7a62d031c83f4294f640ec13");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"),
FromHex("fffffffffffffffffffffffffffffffefffffffffffffffc"),
FromHex("22123dc2395a05caa7423daeccc94760a7d462256bd56916"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("c469684435deb378c4b65ca9591e2a5763059a2e");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"027d29778100c65a1da1783716588dce2b8b4aee8e228f1896");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("c469684435deb378c4b65ca9591e2a5763059a2e"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -120,21 +131,27 @@ private Prime239v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime239v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("7fffffffffffffffffffffff7fffff9e5e9a9f5d9071fbd1522688909d0b");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
FromHex("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc"),
FromHex("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("e43bb460f0b80cc0c0b075798e948060f8321b7d");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("e43bb460f0b80cc0c0b075798e948060f8321b7d"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -145,21 +162,27 @@ private Prime239v2Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime239v2Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("7fffffffffffffffffffffff800000cfa7e8594377d414c03821bc582063");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
FromHex("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc"),
FromHex("617fab6832576cbbfed50d99f0249c3fee58b94ba0038c7ae84c8c832f2c"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("e8b4011604095303ca3b8099982be09fcb9ae616");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0238af09d98727705120c921bb5e9e26296a3cdcf2f35757a0eafd87b830e7");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("e8b4011604095303ca3b8099982be09fcb9ae616"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -170,21 +193,27 @@ private Prime239v3Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime239v3Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("7fffffffffffffffffffffff7fffff975deb41b3a6057c3c432146526551");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
FromHex("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc"),
FromHex("255705fa2a306654b1f4cb03d6a750a30c250102d4988717d9ba15ab6d3e"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("7d7374168ffe3471b60a857686a19475d3bfa2ff");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"036768ae8e18bb92cfcf005c949aa2c6d94853d0e660bbf854b1c9505fe95a");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("7d7374168ffe3471b60a857686a19475d3bfa2ff"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -195,27 +224,30 @@ private Prime256v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new Prime256v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
BigInteger h = BigInteger.One;
- ECCurve curve = ConfigureCurve(new FpCurve(
+ return ConfigureCurve(new FpCurve(
new BigInteger("115792089210356248762697446949407573530086143415290314195533631308867097853951"),
FromHex("ffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),
FromHex("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),
- n, h));
+ n, h, true));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("c49d360886e704936a6678e1139d26b7819f7e90");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("c49d360886e704936a6678e1139d26b7819f7e90"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
- /*
- * F2m Curves
- */
internal class C2pnb163v1Holder
: X9ECParametersHolder
{
@@ -223,22 +255,28 @@ private C2pnb163v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb163v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0400000000000000000001E60FC8821CC74DAEAFC1");
BigInteger h = BigInteger.Two;
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
163,
1, 2, 8,
FromHex("072546B5435234A422E0789675F432C89435DE5242"),
FromHex("00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9"),
n, h));
+ }
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("D2C0FB15760860DEF1EEF4D696E6768756151754");
+ ECCurve curve = Curve;
+
X9ECPoint G = ConfigureBasepoint(curve,
"0307AF69989546103D79329FCC3D74880F33BBE803CB");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("D2C0FB15760860DEF1EEF4D696E6768756151754"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -249,22 +287,28 @@ private C2pnb163v2Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb163v2Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7");
BigInteger h = BigInteger.Two;
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
163,
1, 2, 8,
FromHex("0108B39E77C4B108BED981ED0E890E117C511CF072"),
FromHex("0667ACEB38AF4E488C407433FFAE4F1C811638DF20"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"030024266E4EB5106D0A964D92C4860E2671DB9B6CC5");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -275,22 +319,28 @@ private C2pnb163v3Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb163v3Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309");
BigInteger h = BigInteger.Two;
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
163,
1, 2, 8,
FromHex("07A526C63D3E25A256A007699F5447E32AE456B50E"),
FromHex("03F7061798EB99E238FD6F1BF95B48FEEB4854252B"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0202F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -301,22 +351,28 @@ private C2pnb176w1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb176w1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("010092537397ECA4F6145799D62B0A19CE06FE26AD");
BigInteger h = BigInteger.ValueOf(0xFF6E);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
176,
1, 2, 43,
FromHex("E4E6DB2995065C407D9D39B8D0967B96704BA8E9C90B"),
FromHex("5DDA470ABE6414DE8EC133AE28E9BBD7FCEC0AE0FFF2"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"038D16C2866798B600F9F08BB4A8E860F3298CE04A5798");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -327,22 +383,28 @@ private C2tnb191v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb191v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("40000000000000000000000004A20E90C39067C893BBB9A5");
BigInteger h = BigInteger.Two;
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
191,
9,
FromHex("2866537B676752636A68F56554E12640276B649EF7526267"),
FromHex("2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = Hex.DecodeStrict("4E13CA542744D696E67687561517552F279A8C84");
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0236B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D");
- return new X9ECParameters(curve, G, n, h, Hex.DecodeStrict("4E13CA542744D696E67687561517552F279A8C84"));
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -353,22 +415,28 @@ private C2tnb191v2Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb191v2Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("20000000000000000000000050508CB89F652824E06B8173");
BigInteger h = BigInteger.ValueOf(4);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
191,
9,
FromHex("401028774D7777C7B7666D1366EA432071274F89FF01E718"),
FromHex("0620048D28BCBD03B6249C99182B7C8CD19700C362C46A01"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"023809B2B7CC1B28CC5A87926AAD83FD28789E81E2C9E3BF10");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -379,22 +447,28 @@ private C2tnb191v3Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb191v3Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("155555555555555555555555610C0B196812BFB6288A3EA3");
BigInteger h = BigInteger.ValueOf(6);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
191,
9,
FromHex("6C01074756099122221056911C77D77E77A777E7E7E77FCB"),
FromHex("71FE1AF926CF847989EFEF8DB459F66394D90F32AD3F15E8"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"03375D4CE24FDE434489DE8746E71786015009E66E38A926DD");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -405,22 +479,28 @@ private C2pnb208w1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb208w1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D");
BigInteger h = BigInteger.ValueOf(0xFE48);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
208,
1, 2, 83,
BigInteger.Zero,
FromHex("C8619ED45A62E6212E1160349E2BFA844439FAFC2A3FD1638F9E"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0289FDFBE4ABE193DF9559ECF07AC0CE78554E2784EB8C1ED1A57A");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -431,22 +511,28 @@ private C2tnb239v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb239v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447");
BigInteger h = BigInteger.ValueOf(4);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
239,
36,
FromHex("32010857077C5431123A46B808906756F543423E8D27877578125778AC76"),
FromHex("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0257927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -457,22 +543,28 @@ private C2tnb239v2Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb239v2Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("1555555555555555555555555555553C6F2885259C31E3FCDF154624522D");
BigInteger h = BigInteger.ValueOf(6);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
239,
36,
FromHex("4230017757A767FAE42398569B746325D45313AF0766266479B75654E65F"),
FromHex("5037EA654196CFF0CD82B2C14A2FCF2E3FF8775285B545722F03EACDB74B"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0228F9D04E900069C8DC47A08534FE76D2B900B7D7EF31F5709F200C4CA205");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -483,22 +575,28 @@ private C2tnb239v3Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb239v3Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF");
BigInteger h = BigInteger.ValueOf(10);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
239,
36,
FromHex("01238774666A67766D6676F778E676B66999176666E687666D8766C66A9F"),
FromHex("6A941977BA9F6A435199ACFC51067ED587F519C5ECB541B8E44111DE1D40"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"0370F6E9D04D289C4E89913CE3530BFDE903977D42B146D539BF1BDE4E9C92");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -509,22 +607,28 @@ private C2pnb272w1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb272w1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521");
BigInteger h = BigInteger.ValueOf(0xFF06);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
272,
1, 3, 56,
FromHex("91A091F03B5FBA4AB2CCF49C4EDD220FB028712D42BE752B2C40094DBACDB586FB20"),
FromHex("7167EFC92BB2E3CE7C8AAAFF34E12A9C557003D7C73A6FAF003F99F6CC8482E540F7"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"026108BABB2CEEBCF787058A056CBE0CFE622D7723A289E08A07AE13EF0D10D171DD8D");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -535,22 +639,28 @@ private C2pnb304w1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb304w1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164443051D");
BigInteger h = BigInteger.ValueOf(0xFE2E);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
304,
1, 2, 11,
FromHex("FD0D693149A118F651E6DCE6802085377E5F882D1B510B44160074C1288078365A0396C8E681"),
FromHex("BDDB97E555A50A908E43B01C798EA5DAA6788F1EA2794EFCF57166B8C14039601E55827340BE"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"02197B07845E9BE2D96ADB0F5F3C7F2CFFBD7A3EB8B6FEC35C7FD67F26DDF6285A644F740A2614");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -561,22 +671,28 @@ private C2tnb359v1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb359v1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB964FE7719E74F490758D3B");
BigInteger h = BigInteger.ValueOf(0x4C);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
359,
68,
FromHex("5667676A654B20754F356EA92017D946567C46675556F19556A04616B567D223A5E05656FB549016A96656A557"),
FromHex("2472E2D0197C49363F1FE7F5B6DB075D52B6947D135D8CA445805D39BC345626089687742B6329E70680231988"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"033C258EF3047767E7EDE0F1FDAA79DAEE3841366A132E163ACED4ED2401DF9C6BDCDE98E8E707C07A2239B1B097");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -587,22 +703,28 @@ private C2pnb368w1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2pnb368w1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E909AE40A6F131E9CFCE5BD967");
BigInteger h = BigInteger.ValueOf(0xFF70);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
368,
1, 2, 85,
FromHex("E0D2EE25095206F5E2A4F9ED229F1F256E79A0E2B455970D8D0D865BD94778C576D62F0AB7519CCD2A1A906AE30D"),
FromHex("FC1217D4320A90452C760A58EDCD30C8DD069B3C34453837A34ED50CB54917E1C2112D84D164F444F8F74786046A"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"021085E2755381DCCCE3C1557AFA10C2F0C0C2825646C5B34A394CBCFA8BC16B22E7E789E927BE216F02E1FB136A5F");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
@@ -613,36 +735,41 @@ private C2tnb431r1Holder() {}
internal static readonly X9ECParametersHolder Instance = new C2tnb431r1Holder();
- protected override X9ECParameters CreateParameters()
+ protected override ECCurve CreateCurve()
{
BigInteger n = FromHex("0340340340340340340340340340340340340340340340340340340323C313FAB50589703B5EC68D3587FEC60D161CC149C1AD4A91");
BigInteger h = BigInteger.ValueOf(0x2760);
- ECCurve curve = ConfigureCurve(new F2mCurve(
+ return ConfigureCurve(new F2mCurve(
431,
120,
FromHex("1A827EF00DD6FC0E234CAF046C6A5D8A85395B236CC4AD2CF32A0CADBDC9DDF620B0EB9906D0957F6C6FEACD615468DF104DE296CD8F"),
FromHex("10D9B4A3D9047D8B154359ABFB1B7F5485B04CEB868237DDC9DEDA982A679A5A919B626D4E50A8DD731B107A9962381FB5D807BF2618"),
n, h));
+ }
+
+ protected override X9ECParameters CreateParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = Curve;
X9ECPoint G = ConfigureBasepoint(curve,
"02120FC05D3C67A99DE161D2F4092622FECA701BE4F50F4758714E8A87BBF2A658EF8C21E7C5EFE965361F6C2999C0C247B0DBD70CE6B7");
- return new X9ECParameters(curve, G, n, h);
+ return new X9ECParameters(curve, G, curve.Order, curve.Cofactor, S);
}
}
+ private static readonly Dictionary objIds =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private static readonly Dictionary curves =
+ new Dictionary();
+ private static readonly Dictionary names =
+ new Dictionary();
- private static readonly IDictionary objIds = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary curves = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary names = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- private static void DefineCurve(
- string name,
- DerObjectIdentifier oid,
- X9ECParametersHolder holder)
+ private static void DefineCurve(string name, DerObjectIdentifier oid, X9ECParametersHolder holder)
{
- objIds.Add(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), oid);
+ objIds.Add(name, oid);
names.Add(oid, name);
curves.Add(oid, holder);
}
@@ -674,54 +801,64 @@ static X962NamedCurves()
DefineCurve("c2tnb431r1", X9ObjectIdentifiers.C2Tnb431r1, C2tnb431r1Holder.Instance);
}
- public static X9ECParameters GetByName(
- string name)
+ /// Look up the for the curve with the given name.
+ /// The name of the curve.
+ public static X9ECParameters GetByName(string name)
{
DerObjectIdentifier oid = GetOid(name);
return oid == null ? null : GetByOid(oid);
}
- /**
- * return the X9ECParameters object for the named curve represented by
- * the passed in object identifier. Null if the curve isn't present.
- *
- * @param oid an object identifier representing a named curve, if present.
- */
- public static X9ECParameters GetByOid(
- DerObjectIdentifier oid)
+ /// Look up an for the curve with the given name.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of the
+ /// full .
+ ///
+ /// The name of the curve.
+ public static X9ECParametersHolder GetByNameLazy(string name)
+ {
+ DerObjectIdentifier oid = GetOid(name);
+ return oid == null ? null : GetByOidLazy(oid);
+ }
+
+ /// Look up the for the curve with the given
+ /// OID.
+ /// The OID for the curve.
+ public static X9ECParameters GetByOid(DerObjectIdentifier oid)
+ {
+ return GetByOidLazy(oid)?.Parameters;
+ }
+
+ /// Look up an for the curve with the given
+ /// OID.
+ ///
+ /// Allows accessing the curve without necessarily triggering the creation of the
+ /// full .
+ ///
+ /// The OID for the curve.
+ public static X9ECParametersHolder GetByOidLazy(DerObjectIdentifier oid)
{
- X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
- return holder == null ? null : holder.Parameters;
+ return CollectionUtilities.GetValueOrNull(curves, oid);
}
- /**
- * return the object identifier signified by the passed in name. Null
- * if there is no object identifier associated with name.
- *
- * @return the object identifier associated with name, if present.
- */
- public static DerObjectIdentifier GetOid(
- string name)
+ /// Look up the name of the curve with the given OID.
+ /// The OID for the curve.
+ public static string GetName(DerObjectIdentifier oid)
{
- return (DerObjectIdentifier)objIds[BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name)];
+ return CollectionUtilities.GetValueOrNull(names, oid);
}
- /**
- * return the named curve name represented by the given object identifier.
- */
- public static string GetName(
- DerObjectIdentifier oid)
+ /// Look up the OID of the curve with the given name.
+ /// The name of the curve.
+ public static DerObjectIdentifier GetOid(string name)
{
- return (string)names[oid];
+ return CollectionUtilities.GetValueOrNull(objIds, name);
}
- /**
- * returns an enumeration containing the name strings for curves
- * contained in this structure.
- */
- public static IEnumerable Names
+ /// Enumerate the available curve names in this registry.
+ public static IEnumerable Names
{
- get { return new EnumerableProxy(names.Values); }
+ get { return CollectionUtilities.Proxy(objIds.Keys); }
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962Parameters.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962Parameters.cs
index d2652bc..782af7c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962Parameters.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X962Parameters.cs
@@ -57,9 +57,7 @@ public X962Parameters(
this._params = obj;
}
-
- public X962Parameters(
- Asn1Object obj)
+ private X962Parameters(Asn1Object obj)
{
this._params = obj;
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9Curve.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9Curve.cs
index ff9f21c..78f4384 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9Curve.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9Curve.cs
@@ -49,14 +49,6 @@ public X9Curve(
}
}
-
- public X9Curve(
- X9FieldID fieldID,
- Asn1Sequence seq)
- : this(fieldID, null, null, seq)
- {
- }
-
public X9Curve(
X9FieldID fieldID,
BigInteger order,
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParameters.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParameters.cs
index 21c40a9..77a74b0 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParameters.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParameters.cs
@@ -22,7 +22,7 @@ public class X9ECParameters
private BigInteger h;
private byte[] seed;
- public static X9ECParameters GetInstance(Object obj)
+ public static X9ECParameters GetInstance(object obj)
{
if (obj is X9ECParameters)
return (X9ECParameters)obj;
@@ -69,9 +69,9 @@ public X9ECParameters(
}
public X9ECParameters(
- ECCurve curve,
- ECPoint g,
- BigInteger n)
+ ECCurve curve,
+ X9ECPoint g,
+ BigInteger n)
: this(curve, g, n, null, null)
{
}
@@ -85,25 +85,6 @@ public X9ECParameters(
{
}
- public X9ECParameters(
- ECCurve curve,
- ECPoint g,
- BigInteger n,
- BigInteger h)
- : this(curve, g, n, h, null)
- {
- }
-
- public X9ECParameters(
- ECCurve curve,
- ECPoint g,
- BigInteger n,
- BigInteger h,
- byte[] seed)
- : this(curve, new X9ECPoint(g), n, h, seed)
- {
- }
-
public X9ECParameters(
ECCurve curve,
X9ECPoint g,
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParametersHolder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParametersHolder.cs
index 5dba6b5..09eccd8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParametersHolder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECParametersHolder.cs
@@ -1,28 +1,52 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
+
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9
{
public abstract class X9ECParametersHolder
{
- private X9ECParameters parameters;
+ private ECCurve m_curve;
+ private X9ECParameters m_parameters;
+
+ public ECCurve Curve
+ {
+ get
+ {
+ lock (this)
+ {
+ if (m_curve == null)
+ {
+ m_curve = CreateCurve();
+ }
- public X9ECParameters Parameters
+ return m_curve;
+ }
+ }
+ }
+
+ public X9ECParameters Parameters
{
get
{
lock (this)
{
- if (parameters == null)
+ if (m_parameters == null)
{
- parameters = CreateParameters();
+ m_parameters = CreateParameters();
}
- return parameters;
+ return m_parameters;
}
}
}
- protected abstract X9ECParameters CreateParameters();
+ protected virtual ECCurve CreateCurve()
+ {
+ return CreateParameters().Curve;
+ }
+
+ protected abstract X9ECParameters CreateParameters();
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECPoint.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECPoint.cs
index 7ccb21c..b33eba2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECPoint.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ECPoint.cs
@@ -17,11 +17,6 @@ public class X9ECPoint
private ECCurve c;
private ECPoint p;
- public X9ECPoint(ECPoint p)
- : this(p, false)
- {
- }
-
public X9ECPoint(ECPoint p, bool compressed)
{
this.p = p.Normalize();
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9FieldElement.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9FieldElement.cs
index 7a11e73..84d8e90 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9FieldElement.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9FieldElement.cs
@@ -21,25 +21,6 @@ public X9FieldElement(
this.f = f;
}
-
- public X9FieldElement(
- BigInteger p,
- Asn1OctetString s)
- : this(new FpFieldElement(p, new BigInteger(1, s.GetOctets())))
- {
- }
-
-
- public X9FieldElement(
- int m,
- int k1,
- int k2,
- int k3,
- Asn1OctetString s)
- : this(new F2mFieldElement(m, k1, k2, k3, new BigInteger(1, s.GetOctets())))
- {
- }
-
public ECFieldElement Value
{
get { return f; }
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ObjectIdentifiers.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ObjectIdentifiers.cs
index deb98fd..3a4aa54 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ObjectIdentifiers.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/asn1/x9/X9ObjectIdentifiers.cs
@@ -13,9 +13,7 @@ public abstract class X9ObjectIdentifiers
// us(840) ansi-x962(10045) }
//
- internal const string AnsiX962 = "1.2.840.10045";
-
- public static readonly DerObjectIdentifier ansi_X9_62 = new DerObjectIdentifier(AnsiX962);
+ public static readonly DerObjectIdentifier ansi_X9_62 = new DerObjectIdentifier("1.2.840.10045");
public static readonly DerObjectIdentifier IdFieldType = ansi_X9_62.Branch("1");
@@ -26,14 +24,10 @@ public abstract class X9ObjectIdentifiers
public static readonly DerObjectIdentifier TPBasis = CharacteristicTwoField.Branch("3.2");
public static readonly DerObjectIdentifier PPBasis = CharacteristicTwoField.Branch("3.3");
-
- public const string IdECSigType = AnsiX962 + ".4";
public static readonly DerObjectIdentifier id_ecSigType = ansi_X9_62.Branch("4");
public static readonly DerObjectIdentifier ECDsaWithSha1 = id_ecSigType.Branch("1");
-
- public const string IdPublicKeyType = AnsiX962 + ".2";
public static readonly DerObjectIdentifier id_publicKeyType = ansi_X9_62.Branch("2");
public static readonly DerObjectIdentifier IdECPublicKey = id_publicKeyType.Branch("1");
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredInputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredInputStream.cs
index 364d25a..10dba57 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredInputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredInputStream.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -116,7 +116,7 @@ private static int Decode(int in0, int in1, int in2, int in3, int[] result)
bool newLineFound = false;
bool clearText = false;
bool restart = false;
- IList headerList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ IList headerList = new List();
int lastC = 0;
bool isEndOfStream;
@@ -160,7 +160,7 @@ private bool ParseHeaders()
int last = 0;
bool headerFound = false;
- headerList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ headerList = new List();
//
// if restart we already have a header
@@ -313,6 +313,46 @@ private int ReadIgnoreSpace()
return c;
}
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ Streams.ValidateBufferArguments(buffer, offset, count);
+
+ /*
+ * TODO Currently can't return partial data when exception thrown (breaking test case), so we don't inherit
+ * the base class implementation. Probably the reason is that throws don't mark this instance as 'failed'.
+ */
+ int pos = 0;
+ while (pos < count)
+ {
+ int b = ReadByte();
+ if (b < 0)
+ break;
+
+ buffer[offset + pos++] = (byte)b;
+ }
+ return pos;
+ }
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override int Read(Span buffer)
+ {
+ /*
+ * TODO Currently can't return partial data when exception thrown (breaking test case), so we don't inherit
+ * the base class implementation. Probably the reason is that throws don't mark this instance as 'failed'.
+ */
+ int pos = 0;
+ while (pos < buffer.Length)
+ {
+ int b = ReadByte();
+ if (b < 0)
+ break;
+
+ buffer[pos++] = (byte)b;
+ }
+ return pos;
+ }
+#endif
+
public override int ReadByte()
{
if (start)
@@ -465,68 +505,14 @@ public override int ReadByte()
return c;
}
- /**
- * Reads up to len bytes of data from the input stream into
- * an array of bytes. An attempt is made to read as many as
- * len bytes, but a smaller number may be read.
- * The number of bytes actually read is returned as an integer.
- *
- * The first byte read is stored into element b[off], the
- * next one into b[off+1], and so on. The number of bytes read
- * is, at most, equal to len.
- *
- * NOTE: We need to override the custom behavior of Java's {@link InputStream#read(byte[], int, int)},
- * as the upstream method silently swallows {@link IOException IOExceptions}.
- * This would cause CRC checksum errors to go unnoticed.
- *
- * @see Related BC bug report
- * @param b byte array
- * @param off offset at which we start writing data to the array
- * @param len number of bytes we write into the array
- * @return total number of bytes read into the buffer
- *
- * @throws IOException if an exception happens AT ANY POINT
- */
- public override int Read(byte[] b, int off, int len)
- {
- CheckIndexSize(b.Length, off, len);
-
- int pos = 0;
- while (pos < len)
- {
- int c = ReadByte();
- if (c < 0)
- break;
-
- b[off + pos++] = (byte)c;
- }
- return pos;
- }
-
- private void CheckIndexSize(int size, int off, int len)
- {
- if (off < 0 || len < 0)
- throw new IndexOutOfRangeException("Offset and length cannot be negative.");
- if (off > size - len)
- throw new IndexOutOfRangeException("Invalid offset and length.");
- }
-
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(input);
+ input.Dispose();
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(input);
- base.Close();
- }
-#endif
/**
* Change how the stream should react if it encounters missing CRC checksum.
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredOutputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredOutputStream.cs
index c9de885..f0fa0bc 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredOutputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ArmoredOutputStream.cs
@@ -1,17 +1,13 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
-using System.Text;
-
-#if PORTABLE || NETFX_CORE
-using System.Linq;
-#endif
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
@@ -99,32 +95,40 @@ private static void Encode(
private string type;
- private static readonly string nl = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.NewLine;
+ private static readonly string NewLine = Environment.NewLine;
private static readonly string headerStart = "-----BEGIN PGP ";
private static readonly string headerTail = "-----";
private static readonly string footerStart = "-----END PGP ";
private static readonly string footerTail = "-----";
- private static readonly string Version = "BCPG C# v" + HTTPManager.UserAgent;
+ private static string CreateVersion()
+ {
+ var assembly = Assembly.GetExecutingAssembly();
+ var title = assembly.GetCustomAttribute().Title;
+ var version = assembly.GetCustomAttribute().InformationalVersion;
+ return title + " v" + version;
+ }
+
+ private static readonly string Version = CreateVersion();
- private readonly IDictionary headers;
+ private readonly IDictionary> m_headers;
public ArmoredOutputStream(Stream outStream)
{
this.outStream = outStream;
- this.headers = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(1);
+ this.m_headers = new Dictionary>(1);
SetHeader(HeaderVersion, Version);
}
- public ArmoredOutputStream(Stream outStream, IDictionary headers)
+ public ArmoredOutputStream(Stream outStream, IDictionary headers)
: this(outStream)
{
- foreach (string header in headers.Keys)
+ foreach (var header in headers)
{
- IList headerList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
- headerList.Add(headers[header]);
+ var headerList = new List(1);
+ headerList.Add(header.Value);
- this.headers[header] = headerList;
+ m_headers[header.Key] = headerList;
}
}
@@ -138,22 +142,21 @@ public void SetHeader(string name, string val)
{
if (val == null)
{
- this.headers.Remove(name);
+ this.m_headers.Remove(name);
+ return;
+ }
+
+ if (m_headers.TryGetValue(name, out var valueList))
+ {
+ valueList.Clear();
}
else
{
- IList valueList = (IList)headers[name];
- if (valueList == null)
- {
- valueList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
- this.headers[name] = valueList;
- }
- else
- {
- valueList.Clear();
- }
- valueList.Add(val);
+ valueList = new List(1);
+ m_headers[name] = valueList;
}
+
+ valueList.Add(val);
}
/**
@@ -168,12 +171,12 @@ public void AddHeader(string name, string val)
if (val == null || name == null)
return;
- IList valueList = (IList)headers[name];
- if (valueList == null)
+ if (!m_headers.TryGetValue(name, out var valueList))
{
- valueList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
- this.headers[name] = valueList;
+ valueList = new List(1);
+ m_headers[name] = valueList;
}
+
valueList.Add(val);
}
@@ -182,13 +185,13 @@ public void AddHeader(string name, string val)
*/
public void ResetHeaders()
{
- IList versions = (IList)headers[HeaderVersion];
+ var versions = CollectionUtilities.GetValueOrNull(m_headers, HeaderVersion);
- headers.Clear();
+ m_headers.Clear();
if (versions != null)
{
- headers[HeaderVersion] = versions;
+ m_headers[HeaderVersion] = versions;
}
}
@@ -228,8 +231,8 @@ public void BeginClearText(
throw new IOException("unknown hash algorithm tag in beginClearText: " + hashAlgorithm);
}
- DoWrite("-----BEGIN PGP SIGNED MESSAGE-----" + nl);
- DoWrite("Hash: " + hash + nl + nl);
+ DoWrite("-----BEGIN PGP SIGNED MESSAGE-----" + NewLine);
+ DoWrite("Hash: " + hash + NewLine + NewLine);
clearText = true;
newLine = true;
@@ -241,45 +244,44 @@ public void EndClearText()
clearText = false;
}
- public override void WriteByte(
- byte b)
+ public override void WriteByte(byte value)
{
if (clearText)
{
- outStream.WriteByte(b);
+ outStream.WriteByte(value);
if (newLine)
{
- if (!(b == '\n' && lastb == '\r'))
+ if (!(value == '\n' && lastb == '\r'))
{
newLine = false;
}
- if (b == '-')
+ if (value == '-')
{
outStream.WriteByte((byte)' ');
outStream.WriteByte((byte)'-'); // dash escape
}
}
- if (b == '\r' || (b == '\n' && lastb != '\r'))
+ if (value == '\r' || (value == '\n' && lastb != '\r'))
{
newLine = true;
}
- lastb = b;
+ lastb = value;
return;
}
if (start)
{
- bool newPacket = (b & 0x40) != 0;
+ bool newPacket = (value & 0x40) != 0;
int tag;
if (newPacket)
{
- tag = b & 0x3f;
+ tag = value & 0x3f;
}
else
{
- tag = (b & 0x3f) >> 2;
+ tag = (value & 0x3f) >> 2;
}
switch ((PacketTag)tag)
@@ -298,30 +300,26 @@ public override void WriteByte(
break;
}
- DoWrite(headerStart + type + headerTail + nl);
+ DoWrite(headerStart + type + headerTail + NewLine);
+ if (m_headers.TryGetValue(HeaderVersion, out var versionHeaders))
{
- IList versionHeaders = (IList)headers[HeaderVersion];
- if (versionHeaders != null)
- {
- WriteHeaderEntry(HeaderVersion, versionHeaders[0].ToString());
- }
+ WriteHeaderEntry(HeaderVersion, versionHeaders[0]);
}
- foreach (DictionaryEntry de in headers)
+ foreach (var de in m_headers)
{
- string k = (string)de.Key;
+ string k = de.Key;
if (k != HeaderVersion)
{
- IList values = (IList)de.Value;
- foreach (string v in values)
+ foreach (string v in de.Value)
{
WriteHeaderEntry(k, v);
}
}
}
- DoWrite(nl);
+ DoWrite(NewLine);
start = false;
}
@@ -332,47 +330,32 @@ public override void WriteByte(
bufPtr = 0;
if ((++chunkCount & 0xf) == 0)
{
- DoWrite(nl);
+ DoWrite(NewLine);
}
}
- crc.Update(b);
- buf[bufPtr++] = b & 0xff;
+ crc.Update(value);
+ buf[bufPtr++] = value & 0xff;
}
/**
* Note: Close() does not close the underlying stream. So it is possible to write
* multiple objects using armoring to a single stream.
*/
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
- if (type == null)
- return;
-
- DoClose();
+ if (type != null)
+ {
+ DoClose();
- type = null;
- start = true;
+ type = null;
+ start = true;
+ }
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- if (type == null)
- return;
-
- DoClose();
-
- type = null;
- start = true;
-
- base.Close();
- }
-#endif
private void DoClose()
{
@@ -381,7 +364,7 @@ private void DoClose()
Encode(outStream, buf, bufPtr);
}
- DoWrite(nl + '=');
+ DoWrite(NewLine + '=');
int crcV = crc.Value;
@@ -391,11 +374,11 @@ private void DoClose()
Encode(outStream, buf, 3);
- DoWrite(nl);
+ DoWrite(NewLine);
DoWrite(footerStart);
DoWrite(type);
DoWrite(footerTail);
- DoWrite(nl);
+ DoWrite(NewLine);
outStream.Flush();
}
@@ -404,7 +387,7 @@ private void WriteHeaderEntry(
string name,
string v)
{
- DoWrite(name + ": " + v + nl);
+ DoWrite(name + ": " + v + NewLine);
}
private void DoWrite(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgInputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgInputStream.cs
index 2ea4665..0bdef70 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgInputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgInputStream.cs
@@ -3,7 +3,6 @@
using System;
using System.IO;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
@@ -45,53 +44,61 @@ public override int ReadByte()
return m_in.ReadByte();
}
- public override int Read(
- byte[] buffer,
- int offset,
- int count)
+ public override int Read(byte[] buffer, int offset, int count)
{
- // Strangely, when count == 0, we should still attempt to read a byte
-// if (count == 0)
-// return 0;
-
if (!next)
return m_in.Read(buffer, offset, count);
- // We have next byte waiting, so return it
+ Streams.ValidateBufferArguments(buffer, offset, count);
if (nextB < 0)
- return 0; // EndOfStream
+ return 0;
- if (buffer == null)
- throw new ArgumentNullException("buffer");
+ buffer[offset] = (byte)nextB;
+ next = false;
+ return 1;
+ }
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override int Read(Span buffer)
+ {
+ if (!next)
+ return m_in.Read(buffer);
- buffer[offset] = (byte) nextB;
- next = false;
+ if (nextB < 0)
+ return 0;
- return 1;
+ buffer[0] = (byte)nextB;
+ next = false;
+ return 1;
}
+#endif
- public byte[] ReadAll()
+ public byte[] ReadAll()
{
return Streams.ReadAll(this);
}
- public void ReadFully(
- byte[] buffer,
- int off,
- int len)
+ public void ReadFully(byte[] buffer, int offset, int count)
{
- if (Streams.ReadFully(this, buffer, off, len) < len)
+ if (Streams.ReadFully(this, buffer, offset, count) < count)
throw new EndOfStreamException();
}
- public void ReadFully(
- byte[] buffer)
+ public void ReadFully(byte[] buffer)
{
ReadFully(buffer, 0, buffer.Length);
}
- /// Returns the next packet tag in the stream.
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public void ReadFully(Span buffer)
+ {
+ if (Streams.ReadFully(this, buffer) < buffer.Length)
+ throw new EndOfStreamException();
+ }
+#endif
+
+ /// Returns the next packet tag in the stream.
public PacketTag NextPacketTag()
{
if (!next)
@@ -198,11 +205,7 @@ public Packet ReadPacket()
else
{
PartialInputStream pis = new PartialInputStream(this, partial, bodyLen);
-#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE
- Stream buf = pis;
-#else
Stream buf = new BufferedStream(pis);
-#endif
objStream = new BcpgInputStream(buf);
}
@@ -265,22 +268,14 @@ public PacketTag SkipMarkerPackets()
return tag;
}
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(m_in);
+ m_in.Dispose();
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(m_in);
- base.Close();
- }
-#endif
///
/// A stream that overlays our input stream, allowing the user to only read a segment of it.
@@ -325,6 +320,8 @@ public override int ReadByte()
public override int Read(byte[] buffer, int offset, int count)
{
+ Streams.ValidateBufferArguments(buffer, offset, count);
+
do
{
if (dataLength != 0)
@@ -332,9 +329,8 @@ public override int Read(byte[] buffer, int offset, int count)
int readLen = (dataLength > count || dataLength < 0) ? count : dataLength;
int len = m_in.Read(buffer, offset, readLen);
if (len < 1)
- {
throw new EndOfStreamException("Premature end of stream in PartialInputStream");
- }
+
dataLength -= len;
return len;
}
@@ -344,6 +340,29 @@ public override int Read(byte[] buffer, int offset, int count)
return 0;
}
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override int Read(Span buffer)
+ {
+ do
+ {
+ if (dataLength != 0)
+ {
+ int count = buffer.Length;
+ int readLen = (dataLength > count || dataLength < 0) ? count : dataLength;
+ int len = m_in.Read(buffer[..readLen]);
+ if (len < 1)
+ throw new EndOfStreamException("Premature end of stream in PartialInputStream");
+
+ dataLength -= len;
+ return len;
+ }
+ }
+ while (partial && ReadPartialDataLength() >= 0);
+
+ return 0;
+ }
+#endif
+
private int ReadPartialDataLength()
{
int l = m_in.ReadByte();
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgOutputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgOutputStream.cs
index adc73ea..20b3bd6 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgOutputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/BcpgOutputStream.cs
@@ -166,7 +166,7 @@ private void WriteHeader(
if (partialBuffer != null)
{
- PartialFlush(true);
+ PartialFlushLast();
partialBuffer = null;
}
@@ -217,96 +217,143 @@ private void WriteHeader(
}
}
- private void PartialFlush(
- bool isLast)
+ private void PartialFlush()
{
- if (isLast)
+ outStr.WriteByte((byte)(0xE0 | partialPower));
+ outStr.Write(partialBuffer, 0, partialBufferLength);
+ partialOffset = 0;
+ }
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ private void PartialFlush(ref ReadOnlySpan buffer)
+ {
+ outStr.WriteByte((byte)(0xE0 | partialPower));
+ outStr.Write(buffer[..partialBufferLength]);
+ buffer = buffer[partialBufferLength..];
+ }
+#endif
+
+ private void PartialFlushLast()
+ {
+ WriteNewPacketLength(partialOffset);
+ outStr.Write(partialBuffer, 0, partialOffset);
+ partialOffset = 0;
+ }
+
+ private void PartialWrite(byte[] buffer, int offset, int count)
+ {
+ Streams.ValidateBufferArguments(buffer, offset, count);
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ PartialWrite(buffer.AsSpan(offset, count));
+#else
+ if (partialOffset == partialBufferLength)
{
- WriteNewPacketLength(partialOffset);
- outStr.Write(partialBuffer, 0, partialOffset);
+ PartialFlush();
}
- else
+
+ if (count <= (partialBufferLength - partialOffset))
{
- outStr.WriteByte((byte)(0xE0 | partialPower));
- outStr.Write(partialBuffer, 0, partialBufferLength);
+ Array.Copy(buffer, offset, partialBuffer, partialOffset, count);
+ partialOffset += count;
+ return;
}
- partialOffset = 0;
+ int diff = partialBufferLength - partialOffset;
+ Array.Copy(buffer, offset, partialBuffer, partialOffset, diff);
+ offset += diff;
+ count -= diff;
+ PartialFlush();
+ while (count > partialBufferLength)
+ {
+ Array.Copy(buffer, offset, partialBuffer, 0, partialBufferLength);
+ offset += partialBufferLength;
+ count -= partialBufferLength;
+ PartialFlush();
+ }
+ Array.Copy(buffer, offset, partialBuffer, 0, count);
+ partialOffset = count;
+#endif
}
- private void WritePartial(
- byte b)
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ private void PartialWrite(ReadOnlySpan buffer)
{
if (partialOffset == partialBufferLength)
{
- PartialFlush(false);
+ PartialFlush();
+ }
+
+ if (buffer.Length <= (partialBufferLength - partialOffset))
+ {
+ buffer.CopyTo(partialBuffer.AsSpan(partialOffset));
+ partialOffset += buffer.Length;
+ return;
}
- partialBuffer[partialOffset++] = b;
+ int diff = partialBufferLength - partialOffset;
+ buffer[..diff].CopyTo(partialBuffer.AsSpan(partialOffset));
+ buffer = buffer[diff..];
+ PartialFlush();
+ while (buffer.Length > partialBufferLength)
+ {
+ PartialFlush(ref buffer);
+ }
+ buffer.CopyTo(partialBuffer);
+ partialOffset = buffer.Length;
}
+#endif
- private void WritePartial(
- byte[] buffer,
- int off,
- int len)
+ private void PartialWriteByte(byte value)
{
if (partialOffset == partialBufferLength)
{
- PartialFlush(false);
+ PartialFlush();
}
- if (len <= (partialBufferLength - partialOffset))
+ partialBuffer[partialOffset++] = value;
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ if (partialBuffer != null)
{
- Array.Copy(buffer, off, partialBuffer, partialOffset, len);
- partialOffset += len;
+ PartialWrite(buffer, offset, count);
}
else
{
- int diff = partialBufferLength - partialOffset;
- Array.Copy(buffer, off, partialBuffer, partialOffset, diff);
- off += diff;
- len -= diff;
- PartialFlush(false);
- while (len > partialBufferLength)
- {
- Array.Copy(buffer, off, partialBuffer, 0, partialBufferLength);
- off += partialBufferLength;
- len -= partialBufferLength;
- PartialFlush(false);
- }
- Array.Copy(buffer, off, partialBuffer, 0, len);
- partialOffset += len;
+ outStr.Write(buffer, offset, count);
}
}
- public override void WriteByte(
- byte value)
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override void Write(ReadOnlySpan buffer)
{
if (partialBuffer != null)
{
- WritePartial(value);
+ PartialWrite(buffer);
}
else
{
- outStr.WriteByte(value);
+ outStr.Write(buffer);
}
}
- public override void Write(
- byte[] buffer,
- int offset,
- int count)
+#endif
+
+ public override void WriteByte(byte value)
{
if (partialBuffer != null)
{
- WritePartial(buffer, offset, count);
+ PartialWriteByte(value);
}
else
{
- outStr.Write(buffer, offset, count);
+ outStr.WriteByte(value);
}
}
- // Additional helper methods to write primitive types
- internal virtual void WriteShort(
+ // Additional helper methods to write primitive types
+ internal virtual void WriteShort(
short n)
{
this.Write(
@@ -377,32 +424,22 @@ public void Finish()
{
if (partialBuffer != null)
{
- PartialFlush(true);
+ PartialFlushLast();
Array.Clear(partialBuffer, 0, partialBuffer.Length);
partialBuffer = null;
}
}
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.Finish();
outStr.Flush();
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(outStr);
+ outStr.Dispose();
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- this.Finish();
- outStr.Flush();
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(outStr);
- base.Close();
- }
-#endif
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/Crc24.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/Crc24.cs
index 4df03e4..d13861a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/Crc24.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/Crc24.cs
@@ -29,12 +29,6 @@ public void Update(
}
}
-
- public int GetValue()
- {
- return crc;
- }
-
public int Value
{
get { return crc; }
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECDHPublicBCPGKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECDHPublicBCPGKey.cs
index 32e8fe2..4665ba1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECDHPublicBCPGKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECDHPublicBCPGKey.cs
@@ -3,6 +3,7 @@
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
@@ -16,15 +17,18 @@ public class ECDHPublicBcpgKey
private SymmetricKeyAlgorithmTag symAlgorithmId;
/// The stream to read the packet from.
- public ECDHPublicBcpgKey(
- BcpgInputStream bcpgIn)
+ public ECDHPublicBcpgKey(BcpgInputStream bcpgIn)
: base(bcpgIn)
{
int length = bcpgIn.ReadByte();
- byte[] kdfParameters = new byte[length];
- if (kdfParameters.Length != 3)
- throw new InvalidOperationException("kdf parameters size of 3 expected.");
+ if (length != 3)
+ throw new InvalidOperationException("KDF parameters size of 3 expected.");
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ Span kdfParameters = stackalloc byte[3];
+#else
+ byte[] kdfParameters = new byte[3];
+#endif
bcpgIn.ReadFully(kdfParameters);
reserved = kdfParameters[0];
@@ -50,6 +54,21 @@ public ECDHPublicBcpgKey(
VerifySymmetricKeyAlgorithm();
}
+ public ECDHPublicBcpgKey(
+ DerObjectIdentifier oid,
+ BigInteger point,
+ HashAlgorithmTag hashAlgorithm,
+ SymmetricKeyAlgorithmTag symmetricKeyAlgorithm)
+ : base(oid, point)
+ {
+ reserved = 1;
+ hashFunctionId = hashAlgorithm;
+ symAlgorithmId = symmetricKeyAlgorithm;
+
+ VerifyHashAlgorithm();
+ VerifySymmetricKeyAlgorithm();
+ }
+
public virtual byte Reserved
{
get { return reserved; }
@@ -77,7 +96,7 @@ public override void Encode(
private void VerifyHashAlgorithm()
{
- switch ((HashAlgorithmTag)hashFunctionId)
+ switch (hashFunctionId)
{
case HashAlgorithmTag.Sha256:
case HashAlgorithmTag.Sha384:
@@ -90,7 +109,7 @@ private void VerifyHashAlgorithm()
private void VerifySymmetricKeyAlgorithm()
{
- switch ((SymmetricKeyAlgorithmTag)symAlgorithmId)
+ switch (symAlgorithmId)
{
case SymmetricKeyAlgorithmTag.Aes128:
case SymmetricKeyAlgorithmTag.Aes192:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECPublicBCPGKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECPublicBCPGKey.cs
index df4db3d..326fc89 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECPublicBCPGKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECPublicBCPGKey.cs
@@ -28,7 +28,7 @@ protected ECPublicBcpgKey(
DerObjectIdentifier oid,
ECPoint point)
{
- this.point = new BigInteger(1, point.GetEncoded(false));
+ this.point = MPInteger.ToMpiBigInteger(point);
this.oid = oid;
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECSecretBCPGKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECSecretBCPGKey.cs
index 7c02611..54ed1ab 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECSecretBCPGKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/ECSecretBCPGKey.cs
@@ -2,7 +2,6 @@
#pragma warning disable
using System;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
@@ -11,18 +10,18 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
public class ECSecretBcpgKey
: BcpgObject, IBcpgKey
{
- internal MPInteger x;
+ internal readonly MPInteger m_x;
public ECSecretBcpgKey(
BcpgInputStream bcpgIn)
{
- this.x = new MPInteger(bcpgIn);
+ m_x = new MPInteger(bcpgIn);
}
public ECSecretBcpgKey(
BigInteger x)
{
- this.x = new MPInteger(x);
+ m_x = new MPInteger(x);
}
/// The format, as a string, always "PGP".
@@ -47,12 +46,12 @@ public override byte[] GetEncoded()
public override void Encode(
BcpgOutputStream bcpgOut)
{
- bcpgOut.WriteObject(x);
+ bcpgOut.WriteObject(m_x);
}
public virtual BigInteger X
{
- get { return x.Value; }
+ get { return m_x.Value; }
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs
new file mode 100644
index 0000000..89e0a42
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs
@@ -0,0 +1,29 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
+{
+ public sealed class EdDsaPublicBcpgKey
+ : ECPublicBcpgKey
+ {
+ internal EdDsaPublicBcpgKey(BcpgInputStream bcpgIn)
+ : base(bcpgIn)
+ {
+ }
+
+ public EdDsaPublicBcpgKey(DerObjectIdentifier oid, ECPoint point)
+ : base(oid, point)
+ {
+ }
+
+ public EdDsaPublicBcpgKey(DerObjectIdentifier oid, BigInteger encodedPoint)
+ : base(oid, encodedPoint)
+ {
+ }
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs.meta
new file mode 100644
index 0000000..0977360
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdDsaPublicBcpgKey.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 886e996d31601394ba4c3f2d691c6d68
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs
new file mode 100644
index 0000000..e8e102b
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs
@@ -0,0 +1,47 @@
+#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
+#pragma warning disable
+using System;
+
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
+
+namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
+{
+ public sealed class EdSecretBcpgKey
+ : BcpgObject, IBcpgKey
+ {
+ internal readonly MPInteger m_x;
+
+ public EdSecretBcpgKey(BcpgInputStream bcpgIn)
+ {
+ m_x = new MPInteger(bcpgIn);
+ }
+
+ public EdSecretBcpgKey(BigInteger x)
+ {
+ m_x = new MPInteger(x);
+ }
+
+ public string Format => "PGP";
+
+ public override byte[] GetEncoded()
+ {
+ try
+ {
+ return base.GetEncoded();
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ public override void Encode(BcpgOutputStream bcpgOut)
+ {
+ bcpgOut.WriteObject(m_x);
+ }
+
+ public BigInteger X => m_x.Value;
+ }
+}
+#pragma warning restore
+#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs.meta b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs.meta
new file mode 100644
index 0000000..e9eb583
--- /dev/null
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/EdSecretBcpgKey.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f1b967203f5d100409763ad04d4f89e3
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/MPInteger.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/MPInteger.cs
index 0ab860f..5a33ed1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/MPInteger.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/MPInteger.cs
@@ -1,62 +1,69 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// A multiple precision integer
- public class MPInteger
+ public sealed class MPInteger
: BcpgObject
{
- private readonly BigInteger val;
+ private readonly BigInteger m_val;
- public MPInteger(
- BcpgInputStream bcpgIn)
+ public MPInteger(BcpgInputStream bcpgIn)
{
if (bcpgIn == null)
- throw new ArgumentNullException("bcpgIn");
+ throw new ArgumentNullException(nameof(bcpgIn));
- int length = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
- byte[] bytes = new byte[(length + 7) / 8];
+ int lengthInBits = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
+ int lengthInBytes = (lengthInBits + 7) / 8;
- bcpgIn.ReadFully(bytes);
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ Span bytes = lengthInBytes <= 512
+ ? stackalloc byte[lengthInBytes]
+ : new byte[lengthInBytes];
+#else
+ byte[] bytes = new byte[lengthInBytes];
+#endif
- this.val = new BigInteger(1, bytes);
+ bcpgIn.ReadFully(bytes);
+ m_val = new BigInteger(1, bytes);
}
- public MPInteger(
- BigInteger val)
+ public MPInteger(BigInteger val)
{
if (val == null)
- throw new ArgumentNullException("val");
+ throw new ArgumentNullException(nameof(val));
if (val.SignValue < 0)
- throw new ArgumentException("Values must be positive", "val");
+ throw new ArgumentException("Values must be positive", nameof(val));
- this.val = val;
+ m_val = val;
}
- public BigInteger Value
+ public BigInteger Value => m_val;
+
+ public override void Encode(BcpgOutputStream bcpgOut)
{
- get { return val; }
+ bcpgOut.WriteShort((short)m_val.BitLength);
+ bcpgOut.Write(m_val.ToByteArrayUnsigned());
}
- public override void Encode(
- BcpgOutputStream bcpgOut)
+ internal static BigInteger ToMpiBigInteger(ECPoint point)
{
- bcpgOut.WriteShort((short) val.BitLength);
- bcpgOut.Write(val.ToByteArrayUnsigned());
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ int encodedLength = point.GetEncodedLength(false);
+ Span encoding = encodedLength <= 512
+ ? stackalloc byte[encodedLength]
+ : new byte[encodedLength];
+ point.EncodeTo(false, encoding);
+#else
+ byte[] encoding = point.GetEncoded(false);
+#endif
+ return new BigInteger(1, encoding);
}
-
- internal static void Encode(
- BcpgOutputStream bcpgOut,
- BigInteger val)
- {
- bcpgOut.WriteShort((short) val.BitLength);
- bcpgOut.Write(val.ToByteArrayUnsigned());
- }
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/OnePassSignaturePacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/OnePassSignaturePacket.cs
index 853ba8f..03dfa4f 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/OnePassSignaturePacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/OnePassSignaturePacket.cs
@@ -73,21 +73,15 @@ public long KeyId
get { return keyId; }
}
- public override void Encode(
- BcpgOutputStream bcpgOut)
+ public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
- BcpgOutputStream pOut = new BcpgOutputStream(bOut);
-
- pOut.Write(
- (byte) version,
- (byte) sigType,
- (byte) hashAlgorithm,
- (byte) keyAlgorithm);
-
- pOut.WriteLong(keyId);
-
- pOut.WriteByte((byte) nested);
+ using (var pOut = new BcpgOutputStream(bOut))
+ {
+ pOut.Write((byte)version, (byte)sigType, (byte)hashAlgorithm, (byte)keyAlgorithm);
+ pOut.WriteLong(keyId);
+ pOut.WriteByte((byte)nested);
+ }
bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyAlgorithmTags.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyAlgorithmTags.cs
index fc7b307..07d96f8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyAlgorithmTags.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyAlgorithmTags.cs
@@ -12,8 +12,6 @@ public enum PublicKeyAlgorithmTag
RsaSign = 3, // RSA Sign-Only
ElGamalEncrypt = 16, // Elgamal (Encrypt-Only), see [ELGAMAL]
Dsa = 17, // DSA (Digital Signature Standard)
-
- EC = 18, // Reserved for Elliptic Curve
ECDH = 18, // Reserved for Elliptic Curve (actual algorithm name)
ECDsa = 19, // Reserved for ECDSA
ElGamalGeneral = 20, // Elgamal (Encrypt or Sign)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyEncSessionPacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyEncSessionPacket.cs
index d488508..e58c158 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyEncSessionPacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyEncSessionPacket.cs
@@ -92,26 +92,22 @@ public byte[][] GetEncSessionKey()
return data;
}
- public override void Encode(
- BcpgOutputStream bcpgOut)
+ public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
- BcpgOutputStream pOut = new BcpgOutputStream(bOut);
-
- pOut.WriteByte((byte) version);
-
- pOut.WriteLong(keyId);
-
- pOut.WriteByte((byte)algorithm);
-
- for (int i = 0; i < data.Length; ++i)
- {
- pOut.Write(data[i]);
- }
-
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(pOut);
+ using (var pOut = new BcpgOutputStream(bOut))
+ {
+ pOut.WriteByte((byte)version);
+ pOut.WriteLong(keyId);
+ pOut.WriteByte((byte)algorithm);
+
+ for (int i = 0; i < data.Length; ++i)
+ {
+ pOut.Write(data[i]);
+ }
+ }
- bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession , bOut.ToArray(), true);
+ bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyPacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyPacket.cs
index b53a90b..18c731a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyPacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/PublicKeyPacket.cs
@@ -30,30 +30,33 @@ internal PublicKeyPacket(
validDays = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
}
- algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
+ algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
- switch ((PublicKeyAlgorithmTag) algorithm)
+ switch (algorithm)
{
- case PublicKeyAlgorithmTag.RsaEncrypt:
- case PublicKeyAlgorithmTag.RsaGeneral:
- case PublicKeyAlgorithmTag.RsaSign:
- key = new RsaPublicBcpgKey(bcpgIn);
- break;
- case PublicKeyAlgorithmTag.Dsa:
- key = new DsaPublicBcpgKey(bcpgIn);
- break;
- case PublicKeyAlgorithmTag.ElGamalEncrypt:
- case PublicKeyAlgorithmTag.ElGamalGeneral:
- key = new ElGamalPublicBcpgKey(bcpgIn);
- break;
- case PublicKeyAlgorithmTag.ECDH:
- key = new ECDHPublicBcpgKey(bcpgIn);
- break;
- case PublicKeyAlgorithmTag.ECDsa:
- key = new ECDsaPublicBcpgKey(bcpgIn);
- break;
- default:
- throw new IOException("unknown PGP public key algorithm encountered");
+ case PublicKeyAlgorithmTag.RsaEncrypt:
+ case PublicKeyAlgorithmTag.RsaGeneral:
+ case PublicKeyAlgorithmTag.RsaSign:
+ key = new RsaPublicBcpgKey(bcpgIn);
+ break;
+ case PublicKeyAlgorithmTag.Dsa:
+ key = new DsaPublicBcpgKey(bcpgIn);
+ break;
+ case PublicKeyAlgorithmTag.ElGamalEncrypt:
+ case PublicKeyAlgorithmTag.ElGamalGeneral:
+ key = new ElGamalPublicBcpgKey(bcpgIn);
+ break;
+ case PublicKeyAlgorithmTag.ECDH:
+ key = new ECDHPublicBcpgKey(bcpgIn);
+ break;
+ case PublicKeyAlgorithmTag.ECDsa:
+ key = new ECDsaPublicBcpgKey(bcpgIn);
+ break;
+ case PublicKeyAlgorithmTag.EdDsa:
+ key = new EdDsaPublicBcpgKey(bcpgIn);
+ break;
+ default:
+ throw new IOException("unknown PGP public key algorithm encountered");
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/S2k.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/S2k.cs
index 018620f..9099a94 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/S2k.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/S2k.cs
@@ -103,12 +103,6 @@ public virtual byte[] GetIV()
return Arrays.Clone(iv);
}
-
- public long GetIterationCount()
- {
- return IterationCount;
- }
-
/// The iteration count
public virtual long IterationCount
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignaturePacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignaturePacket.cs
index 91c2946..48dfc96 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignaturePacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignaturePacket.cs
@@ -1,11 +1,10 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
@@ -13,7 +12,7 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// Generic signature packet.
public class SignaturePacket
- : ContainedPacket //, PublicKeyAlgorithmTag
+ : ContainedPacket
{
private int version;
private int signatureType;
@@ -70,29 +69,26 @@ internal SignaturePacket(
SignatureSubpacketsParser sIn = new SignatureSubpacketsParser(
new MemoryStream(hashed, false));
- IList v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var v = new List();
+
SignatureSubpacket sub;
while ((sub = sIn.ReadPacket()) != null)
{
v.Add(sub);
}
- hashedData = new SignatureSubpacket[v.Count];
+ hashedData = v.ToArray();
- for (int i = 0; i != hashedData.Length; i++)
+ foreach (var p in hashedData)
{
- SignatureSubpacket p = (SignatureSubpacket)v[i];
- if (p is IssuerKeyId)
+ if (p is IssuerKeyId issuerKeyId)
{
- keyId = ((IssuerKeyId)p).KeyId;
+ keyId = issuerKeyId.KeyId;
}
- else if (p is SignatureCreationTime)
+ else if (p is SignatureCreationTime sigCreationTime)
{
- creationTime = DateTimeUtilities.DateTimeToUnixMs(
- ((SignatureCreationTime)p).GetTime());
+ creationTime = DateTimeUtilities.DateTimeToUnixMs(sigCreationTime.GetTime());
}
-
- hashedData[i] = p;
}
int unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
@@ -109,17 +105,14 @@ internal SignaturePacket(
v.Add(sub);
}
- unhashedData = new SignatureSubpacket[v.Count];
+ unhashedData = v.ToArray();
- for (int i = 0; i != unhashedData.Length; i++)
+ foreach (var p in unhashedData)
{
- SignatureSubpacket p = (SignatureSubpacket)v[i];
- if (p is IssuerKeyId)
+ if (p is IssuerKeyId issuerKeyId)
{
- keyId = ((IssuerKeyId)p).KeyId;
+ keyId = issuerKeyId.KeyId;
}
-
- unhashedData[i] = p;
}
}
else
@@ -137,41 +130,38 @@ internal SignaturePacket(
case PublicKeyAlgorithmTag.RsaGeneral:
case PublicKeyAlgorithmTag.RsaSign:
MPInteger v = new MPInteger(bcpgIn);
- signature = new MPInteger[]{ v };
+ signature = new MPInteger[1]{ v };
break;
case PublicKeyAlgorithmTag.Dsa:
MPInteger r = new MPInteger(bcpgIn);
MPInteger s = new MPInteger(bcpgIn);
- signature = new MPInteger[]{ r, s };
+ signature = new MPInteger[2]{ r, s };
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt: // yep, this really does happen sometimes.
case PublicKeyAlgorithmTag.ElGamalGeneral:
MPInteger p = new MPInteger(bcpgIn);
MPInteger g = new MPInteger(bcpgIn);
MPInteger y = new MPInteger(bcpgIn);
- signature = new MPInteger[]{ p, g, y };
+ signature = new MPInteger[3]{ p, g, y };
break;
case PublicKeyAlgorithmTag.ECDsa:
+ case PublicKeyAlgorithmTag.EdDsa:
MPInteger ecR = new MPInteger(bcpgIn);
MPInteger ecS = new MPInteger(bcpgIn);
- signature = new MPInteger[]{ ecR, ecS };
+ signature = new MPInteger[2]{ ecR, ecS };
break;
default:
- if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
- {
- signature = null;
- MemoryStream bOut = new MemoryStream();
- int ch;
- while ((ch = bcpgIn.ReadByte()) >= 0)
- {
- bOut.WriteByte((byte) ch);
- }
- signatureEncoding = bOut.ToArray();
- }
- else
+ if (keyAlgorithm < PublicKeyAlgorithmTag.Experimental_1 || keyAlgorithm > PublicKeyAlgorithmTag.Experimental_11)
+ throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
+
+ signature = null;
+ MemoryStream bOut = new MemoryStream();
+ int ch;
+ while ((ch = bcpgIn.ReadByte()) >= 0)
{
- throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
+ bOut.WriteByte((byte) ch);
}
+ signatureEncoding = bOut.ToArray();
break;
}
}
@@ -246,7 +236,7 @@ public SignaturePacket(
if (hashedData != null)
{
- setCreationTime();
+ SetCreationTime();
}
}
@@ -277,56 +267,53 @@ public long KeyId
*/
public byte[] GetSignatureTrailer()
{
- byte[] trailer = null;
-
if (version == 3)
{
- trailer = new byte[5];
-
- long time = creationTime / 1000L;
+ long time = creationTime / 1000L;
+ byte[] trailer = new byte[5];
trailer[0] = (byte)signatureType;
trailer[1] = (byte)(time >> 24);
trailer[2] = (byte)(time >> 16);
- trailer[3] = (byte)(time >> 8);
- trailer[4] = (byte)(time);
+ trailer[3] = (byte)(time >> 8);
+ trailer[4] = (byte)(time );
+ return trailer;
}
- else
- {
- MemoryStream sOut = new MemoryStream();
-
- sOut.WriteByte((byte)this.Version);
- sOut.WriteByte((byte)this.SignatureType);
- sOut.WriteByte((byte)this.KeyAlgorithm);
- sOut.WriteByte((byte)this.HashAlgorithm);
- MemoryStream hOut = new MemoryStream();
- SignatureSubpacket[] hashed = this.GetHashedSubPackets();
+ MemoryStream sOut = new MemoryStream();
- for (int i = 0; i != hashed.Length; i++)
- {
- hashed[i].Encode(hOut);
- }
+ sOut.WriteByte((byte)Version);
+ sOut.WriteByte((byte)SignatureType);
+ sOut.WriteByte((byte)KeyAlgorithm);
+ sOut.WriteByte((byte)HashAlgorithm);
- byte[] data = hOut.ToArray();
+ // Mark position an reserve two bytes for length
+ long lengthPosition = sOut.Position;
+ sOut.WriteByte(0x00);
+ sOut.WriteByte(0x00);
- sOut.WriteByte((byte)(data.Length >> 8));
- sOut.WriteByte((byte)data.Length);
- sOut.Write(data, 0, data.Length);
+ SignatureSubpacket[] hashed = GetHashedSubPackets();
+ for (int i = 0; i != hashed.Length; i++)
+ {
+ hashed[i].Encode(sOut);
+ }
- byte[] hData = sOut.ToArray();
+ ushort dataLength = Convert.ToUInt16(sOut.Position - lengthPosition - 2);
+ uint hDataLength = Convert.ToUInt32(sOut.Position);
- sOut.WriteByte((byte)this.Version);
- sOut.WriteByte((byte)0xff);
- sOut.WriteByte((byte)(hData.Length>> 24));
- sOut.WriteByte((byte)(hData.Length >> 16));
- sOut.WriteByte((byte)(hData.Length >> 8));
- sOut.WriteByte((byte)(hData.Length));
+ sOut.WriteByte((byte)Version);
+ sOut.WriteByte(0xff);
+ sOut.WriteByte((byte)(hDataLength >> 24));
+ sOut.WriteByte((byte)(hDataLength >> 16));
+ sOut.WriteByte((byte)(hDataLength >> 8));
+ sOut.WriteByte((byte)(hDataLength ));
- trailer = sOut.ToArray();
- }
+ // Reset position and fill in length
+ sOut.Position = lengthPosition;
+ sOut.WriteByte((byte)(dataLength >> 8));
+ sOut.WriteByte((byte)(dataLength ));
- return trailer;
+ return sOut.ToArray();
}
public PublicKeyAlgorithmTag KeyAlgorithm
@@ -393,55 +380,44 @@ public long CreationTime
get { return creationTime; }
}
- public override void Encode(
- BcpgOutputStream bcpgOut)
+ public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
- BcpgOutputStream pOut = new BcpgOutputStream(bOut);
-
- pOut.WriteByte((byte) version);
-
- if (version == 3 || version == 2)
+ using (var pOut = new BcpgOutputStream(bOut))
{
- pOut.Write(
- 5, // the length of the next block
- (byte) signatureType);
-
- pOut.WriteInt((int)(creationTime / 1000L));
+ pOut.WriteByte((byte)version);
- pOut.WriteLong(keyId);
-
- pOut.Write(
- (byte) keyAlgorithm,
- (byte) hashAlgorithm);
- }
- else if (version == 4)
- {
- pOut.Write(
- (byte) signatureType,
- (byte) keyAlgorithm,
- (byte) hashAlgorithm);
+ if (version == 3 || version == 2)
+ {
+ byte nextBlockLength = 5;
+ pOut.Write(nextBlockLength, (byte)signatureType);
+ pOut.WriteInt((int)(creationTime / 1000L));
+ pOut.WriteLong(keyId);
+ pOut.Write((byte)keyAlgorithm, (byte)hashAlgorithm);
+ }
+ else if (version == 4)
+ {
+ pOut.Write((byte)signatureType, (byte)keyAlgorithm, (byte)hashAlgorithm);
+ EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));
+ EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
+ }
+ else
+ {
+ throw new IOException("unknown version: " + version);
+ }
- EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));
+ pOut.Write(fingerprint);
- EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
- }
- else
- {
- throw new IOException("unknown version: " + version);
+ if (signature != null)
+ {
+ pOut.WriteObjects(signature);
+ }
+ else
+ {
+ pOut.Write(signatureEncoding);
+ }
}
- pOut.Write(fingerprint);
-
- if (signature != null)
- {
- pOut.WriteObjects(signature);
- }
- else
- {
- pOut.Write(signatureEncoding);
- }
-
bcpgOut.WritePacket(PacketTag.Signature, bOut.ToArray(), true);
}
@@ -466,18 +442,18 @@ private static byte[] GetEncodedSubpackets(
return sOut.ToArray();
}
- private void setCreationTime()
+ private void SetCreationTime()
{
foreach (SignatureSubpacket p in hashedData)
{
- if (p is SignatureCreationTime)
+ if (p is SignatureCreationTime signatureCreationTime)
{
- creationTime = DateTimeUtilities.DateTimeToUnixMs(
- ((SignatureCreationTime)p).GetTime());
+ creationTime = DateTimeUtilities.DateTimeToUnixMs(signatureCreationTime.GetTime());
break;
}
}
}
+
public static SignaturePacket FromByteArray(byte[] data)
{
BcpgInputStream input = BcpgInputStream.Wrap(new MemoryStream(data));
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignatureSubpacketsReader.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignatureSubpacketsReader.cs
index 3870683..6cb09bf 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignatureSubpacketsReader.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SignatureSubpacketsReader.cs
@@ -92,33 +92,37 @@ public SignatureSubpacket ReadPacket()
switch (type)
{
- case SignatureSubpacketTag.CreationTime:
- return new SignatureCreationTime(isCritical, isLongLength, data);
- case SignatureSubpacketTag.KeyExpireTime:
- return new KeyExpirationTime(isCritical, isLongLength, data);
- case SignatureSubpacketTag.ExpireTime:
- return new SignatureExpirationTime(isCritical, isLongLength, data);
- case SignatureSubpacketTag.Revocable:
- return new Revocable(isCritical, isLongLength, data);
- case SignatureSubpacketTag.Exportable:
- return new Exportable(isCritical, isLongLength, data);
- case SignatureSubpacketTag.IssuerKeyId:
- return new IssuerKeyId(isCritical, isLongLength, data);
- case SignatureSubpacketTag.TrustSig:
- return new TrustSignature(isCritical, isLongLength, data);
- case SignatureSubpacketTag.PreferredCompressionAlgorithms:
- case SignatureSubpacketTag.PreferredHashAlgorithms:
- case SignatureSubpacketTag.PreferredSymmetricAlgorithms:
- return new PreferredAlgorithms(type, isCritical, isLongLength, data);
- case SignatureSubpacketTag.KeyFlags:
- return new KeyFlags(isCritical, isLongLength, data);
- case SignatureSubpacketTag.PrimaryUserId:
- return new PrimaryUserId(isCritical, isLongLength, data);
- case SignatureSubpacketTag.SignerUserId:
- return new SignerUserId(isCritical, isLongLength, data);
- case SignatureSubpacketTag.NotationData:
- return new NotationData(isCritical, isLongLength, data);
- }
+ case SignatureSubpacketTag.CreationTime:
+ return new SignatureCreationTime(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.KeyExpireTime:
+ return new KeyExpirationTime(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.ExpireTime:
+ return new SignatureExpirationTime(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.Revocable:
+ return new Revocable(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.Exportable:
+ return new Exportable(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.IssuerKeyId:
+ return new IssuerKeyId(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.TrustSig:
+ return new TrustSignature(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.PreferredCompressionAlgorithms:
+ case SignatureSubpacketTag.PreferredHashAlgorithms:
+ case SignatureSubpacketTag.PreferredSymmetricAlgorithms:
+ return new PreferredAlgorithms(type, isCritical, isLongLength, data);
+ case SignatureSubpacketTag.KeyFlags:
+ return new KeyFlags(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.PrimaryUserId:
+ return new PrimaryUserId(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.SignerUserId:
+ return new SignerUserId(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.NotationData:
+ return new NotationData(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.RevocationReason:
+ return new RevocationReason(isCritical, isLongLength, data);
+ case SignatureSubpacketTag.RevocationKey:
+ return new RevocationKey(isCritical, isLongLength, data);
+ }
return new SignatureSubpacket(type, isCritical, isLongLength, data);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SymmetricKeyEncSessionPacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SymmetricKeyEncSessionPacket.cs
index 26d81e3..23507a8 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SymmetricKeyEncSessionPacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/SymmetricKeyEncSessionPacket.cs
@@ -70,21 +70,18 @@ public int Version
get { return version; }
}
- public override void Encode(
- BcpgOutputStream bcpgOut)
+ public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
- BcpgOutputStream pOut = new BcpgOutputStream(bOut);
+ using (var pOut = new BcpgOutputStream(bOut))
+ {
+ pOut.Write((byte)version, (byte)encAlgorithm);
+ pOut.WriteObject(s2k);
- pOut.Write(
- (byte) version,
- (byte) encAlgorithm);
-
- pOut.WriteObject(s2k);
-
- if (secKeyData != null && secKeyData.Length > 0)
- {
- pOut.Write(secKeyData);
+ if (secKeyData != null && secKeyData.Length > 0)
+ {
+ pOut.Write(secKeyData);
+ }
}
bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, bOut.ToArray(), true);
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UnsupportedPacketVersionException.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UnsupportedPacketVersionException.cs
index dabd02a..385deb1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UnsupportedPacketVersionException.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UnsupportedPacketVersionException.cs
@@ -1,16 +1,33 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
+ [Serializable]
public class UnsupportedPacketVersionException
: Exception
{
- public UnsupportedPacketVersionException(string msg)
- : base(msg)
- {
- }
+ public UnsupportedPacketVersionException()
+ : base()
+ {
+ }
+
+ public UnsupportedPacketVersionException(string message)
+ : base(message)
+ {
+ }
+
+ public UnsupportedPacketVersionException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ protected UnsupportedPacketVersionException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UserAttributePacket.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UserAttributePacket.cs
index b98334a..5517578 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UserAttributePacket.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/UserAttributePacket.cs
@@ -1,11 +1,8 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
@@ -22,18 +19,13 @@ public UserAttributePacket(
UserAttributeSubpacketsParser sIn = new UserAttributeSubpacketsParser(bcpgIn);
UserAttributeSubpacket sub;
- IList v = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var v = new List();
while ((sub = sIn.ReadPacket()) != null)
{
v.Add(sub);
}
- subpackets = new UserAttributeSubpacket[v.Count];
-
- for (int i = 0; i != subpackets.Length; i++)
- {
- subpackets[i] = (UserAttributeSubpacket)v[i];
- }
+ subpackets = v.ToArray();
}
public UserAttributePacket(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Exportable.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Exportable.cs
index 25d7252..e617f35 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Exportable.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Exportable.cs
@@ -12,17 +12,7 @@ public class Exportable
{
private static byte[] BooleanToByteArray(bool val)
{
- byte[] data = new byte[1];
-
- if (val)
- {
- data[0] = 1;
- return data;
- }
- else
- {
- return data;
- }
+ return new byte[1]{ Convert.ToByte(val) };
}
public Exportable(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Features.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Features.cs
index 3c445c5..eea3ef2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Features.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Features.cs
@@ -21,31 +21,25 @@ public class Features
fingerprint format */
public static readonly byte FEATURE_VERSION_5_PUBLIC_KEY = 0x04;
- private static byte[] featureToByteArray(byte feature)
+ private static byte[] FeatureToByteArray(byte feature)
{
- byte[] data = new byte[1];
- data[0] = feature;
- return data;
+ return new byte[1]{ feature };
}
public Features(
bool critical,
bool isLongLength,
- byte[] data): base(SignatureSubpacketTag.Features, critical, isLongLength, data)
+ byte[] data)
+ : base(SignatureSubpacketTag.Features, critical, isLongLength, data)
{
-
}
-
- public Features(bool critical, byte features): this(critical, false, featureToByteArray(features))
+ public Features(bool critical, byte features): this(critical, false, FeatureToByteArray(features))
{
-
}
-
- public Features(bool critical, int features): this(critical, false, featureToByteArray((byte)features))
+ public Features(bool critical, int features): this(critical, false, FeatureToByteArray((byte)features))
{
-
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/IssuerKeyId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/IssuerKeyId.cs
index d5181dd..981e526 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/IssuerKeyId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/IssuerKeyId.cs
@@ -1,8 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
-
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
{
@@ -12,21 +10,9 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class IssuerKeyId
: SignatureSubpacket
{
- protected static byte[] KeyIdToBytes(
- long keyId)
+ protected static byte[] KeyIdToBytes(long keyId)
{
- byte[] data = new byte[8];
-
- data[0] = (byte)(keyId >> 56);
- data[1] = (byte)(keyId >> 48);
- data[2] = (byte)(keyId >> 40);
- data[3] = (byte)(keyId >> 32);
- data[4] = (byte)(keyId >> 24);
- data[5] = (byte)(keyId >> 16);
- data[6] = (byte)(keyId >> 8);
- data[7] = (byte)keyId;
-
- return data;
+ return Pack.UInt64_To_BE((ulong)keyId);
}
public IssuerKeyId(
@@ -44,22 +30,7 @@ public IssuerKeyId(
{
}
- public long KeyId
- {
- get
- {
- long keyId = ((long)(data[0] & 0xff) << 56)
- | ((long)(data[1] & 0xff) << 48)
- | ((long)(data[2] & 0xff) << 40)
- | ((long)(data[3] & 0xff) << 32)
- | ((long)(data[4] & 0xff) << 24)
- | ((long)(data[5] & 0xff) << 16)
- | ((long)(data[6] & 0xff) << 8)
- | ((long)data[7] & 0xff);
-
- return keyId;
- }
- }
+ public long KeyId => (long)Pack.BE_To_UInt64(data);
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/KeyExpirationTime.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/KeyExpirationTime.cs
index dee992c..bbc115e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/KeyExpirationTime.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/KeyExpirationTime.cs
@@ -1,6 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
{
@@ -10,17 +10,9 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class KeyExpirationTime
: SignatureSubpacket
{
- protected static byte[] TimeToBytes(
- long t)
+ protected static byte[] TimeToBytes(long t)
{
- byte[] data = new byte[4];
-
- data[0] = (byte)(t >> 24);
- data[1] = (byte)(t >> 16);
- data[2] = (byte)(t >> 8);
- data[3] = (byte)t;
-
- return data;
+ return Pack.UInt32_To_BE((uint)t);
}
public KeyExpirationTime(
@@ -43,16 +35,7 @@ public KeyExpirationTime(
*
* @return second count for key validity.
*/
- public long Time
- {
- get
- {
- long time = ((long)(data[0] & 0xff) << 24) | ((long)(data[1] & 0xff) << 16)
- | ((long)(data[2] & 0xff) << 8) | ((long)data[3] & 0xff);
-
- return time;
- }
- }
+ public long Time => (long)Pack.BE_To_UInt32(data);
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/NotationData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/NotationData.cs
index d6df673..0604d62 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/NotationData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/NotationData.cs
@@ -81,7 +81,7 @@ private static byte[] CreateData(
public bool IsHumanReadable
{
- get { return data[0] == (byte)0x80; }
+ get { return data[0] == 0x80; }
}
public string GetNotationName()
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/PrimaryUserId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/PrimaryUserId.cs
index 8bd63ca..fed076d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/PrimaryUserId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/PrimaryUserId.cs
@@ -10,20 +10,9 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class PrimaryUserId
: SignatureSubpacket
{
- private static byte[] BooleanToByteArray(
- bool val)
+ private static byte[] BooleanToByteArray(bool val)
{
- byte[] data = new byte[1];
-
- if (val)
- {
- data[0] = 1;
- return data;
- }
- else
- {
- return data;
- }
+ return new byte[1]{ Convert.ToByte(val) };
}
public PrimaryUserId(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Revocable.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Revocable.cs
index 9b0b992..7914cb6 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Revocable.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/Revocable.cs
@@ -10,20 +10,9 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class Revocable
: SignatureSubpacket
{
- private static byte[] BooleanToByteArray(
- bool value)
+ private static byte[] BooleanToByteArray(bool value)
{
- byte[] data = new byte[1];
-
- if (value)
- {
- data[0] = 1;
- return data;
- }
- else
- {
- return data;
- }
+ return new byte[1]{ Convert.ToByte(value) };
}
public Revocable(
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/RevocationReason.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/RevocationReason.cs
index 6f0d5ef..72aa4ae 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/RevocationReason.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/RevocationReason.cs
@@ -48,9 +48,7 @@ public virtual string GetRevocationDescription()
{
byte[] data = GetData();
if (data.Length == 1)
- {
return string.Empty;
- }
byte[] description = new byte[data.Length - 1];
Array.Copy(data, 1, description, 0, description.Length);
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureCreationTime.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureCreationTime.cs
index 0ca5639..b3a62eb 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureCreationTime.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureCreationTime.cs
@@ -2,6 +2,7 @@
#pragma warning disable
using System;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
@@ -12,41 +13,25 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class SignatureCreationTime
: SignatureSubpacket
{
- protected static byte[] TimeToBytes(
- DateTime time)
+ protected static byte[] TimeToBytes(DateTime time)
{
long t = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
- byte[] data = new byte[4];
- data[0] = (byte)(t >> 24);
- data[1] = (byte)(t >> 16);
- data[2] = (byte)(t >> 8);
- data[3] = (byte)t;
- return data;
+ return Pack.UInt32_To_BE((uint)t);
}
- public SignatureCreationTime(
- bool critical,
- bool isLongLength,
- byte[] data)
+ public SignatureCreationTime(bool critical, bool isLongLength, byte[] data)
: base(SignatureSubpacketTag.CreationTime, critical, isLongLength, data)
{
}
- public SignatureCreationTime(
- bool critical,
- DateTime date)
+ public SignatureCreationTime(bool critical, DateTime date)
: base(SignatureSubpacketTag.CreationTime, critical, false, TimeToBytes(date))
{
}
public DateTime GetTime()
{
- long time = (long)(
- ((uint)data[0] << 24)
- | ((uint)data[1] << 16)
- | ((uint)data[2] << 8)
- | ((uint)data[3])
- );
+ uint time = Pack.BE_To_UInt32(data, 0);
return DateTimeUtilities.UnixMsToDateTime(time * 1000L);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureExpirationTime.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureExpirationTime.cs
index 32c6cbd..b7fc8ad 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureExpirationTime.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignatureExpirationTime.cs
@@ -1,6 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
{
@@ -10,28 +10,17 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
public class SignatureExpirationTime
: SignatureSubpacket
{
- protected static byte[] TimeToBytes(
- long t)
+ protected static byte[] TimeToBytes(long t)
{
- byte[] data = new byte[4];
- data[0] = (byte)(t >> 24);
- data[1] = (byte)(t >> 16);
- data[2] = (byte)(t >> 8);
- data[3] = (byte)t;
- return data;
+ return Pack.UInt32_To_BE((uint)t);
}
- public SignatureExpirationTime(
- bool critical,
- bool isLongLength,
- byte[] data)
+ public SignatureExpirationTime(bool critical, bool isLongLength, byte[] data)
: base(SignatureSubpacketTag.ExpireTime, critical, isLongLength, data)
{
}
- public SignatureExpirationTime(
- bool critical,
- long seconds)
+ public SignatureExpirationTime(bool critical, long seconds)
: base(SignatureSubpacketTag.ExpireTime, critical, false, TimeToBytes(seconds))
{
}
@@ -39,16 +28,7 @@ public SignatureExpirationTime(
/**
* return time in seconds before signature expires after creation time.
*/
- public long Time
- {
- get
- {
- long time = ((long)(data[0] & 0xff) << 24) | ((long)(data[1] & 0xff) << 16)
- | ((long)(data[2] & 0xff) << 8) | ((long)data[3] & 0xff);
-
- return time;
- }
- }
+ public long Time => Pack.BE_To_UInt32(data, 0);
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignerUserId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignerUserId.cs
index e9008b7..45c68c1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignerUserId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/bcpg/sig/SignerUserId.cs
@@ -1,9 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
-
-
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
{
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContent.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContent.cs
index f04ca47..61b12f0 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContent.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContent.cs
@@ -9,33 +9,33 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
public class CertificateConfirmationContent
{
- private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
- private readonly CertConfirmContent content;
+ private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgFinder;
+ private readonly CertConfirmContent m_content;
public CertificateConfirmationContent(CertConfirmContent content)
{
- this.content = content;
+ this.m_content = content;
}
public CertificateConfirmationContent(CertConfirmContent content,
DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
{
- this.content = content;
- this.digestAlgFinder = digestAlgFinder;
+ this.m_content = content;
+ this.m_digestAlgFinder = digestAlgFinder;
}
public CertConfirmContent ToAsn1Structure()
{
- return content;
+ return m_content;
}
public CertificateStatus[] GetStatusMessages()
{
- CertStatus[] statusArray = content.ToCertStatusArray();
+ CertStatus[] statusArray = m_content.ToCertStatusArray();
CertificateStatus[] ret = new CertificateStatus[statusArray.Length];
for (int i = 0; i != ret.Length; i++)
{
- ret[i] = new CertificateStatus(digestAlgFinder, statusArray[i]);
+ ret[i] = new CertificateStatus(m_digestAlgFinder, statusArray[i]);
}
return ret;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContentBuilder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContentBuilder.cs
index dc154ea..706adff 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContentBuilder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateConfirmationContentBuilder.cs
@@ -1,27 +1,25 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
- public class CertificateConfirmationContentBuilder
+ public sealed class CertificateConfirmationContentBuilder
{
- private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
+ private static readonly DefaultSignatureAlgorithmIdentifierFinder SigAlgFinder =
+ new DefaultSignatureAlgorithmIdentifierFinder();
- private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
- private readonly IList acceptedCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- private readonly IList acceptedReqIds = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgFinder;
+ private readonly IList m_acceptedCerts = new List();
+ private readonly IList m_acceptedReqIDs = new List();
public CertificateConfirmationContentBuilder()
: this(new DefaultDigestAlgorithmIdentifierFinder())
@@ -30,39 +28,40 @@ public CertificateConfirmationContentBuilder()
public CertificateConfirmationContentBuilder(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
{
- this.digestAlgFinder = digestAlgFinder;
+ this.m_digestAlgFinder = digestAlgFinder;
}
public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder,
BigInteger certReqId)
{
- acceptedCerts.Add(certHolder);
- acceptedReqIds.Add(certReqId);
+ m_acceptedCerts.Add(certHolder);
+ m_acceptedReqIDs.Add(certReqId);
return this;
}
public CertificateConfirmationContent Build()
{
Asn1EncodableVector v = new Asn1EncodableVector();
- for (int i = 0; i != acceptedCerts.Count; i++)
+ for (int i = 0; i != m_acceptedCerts.Count; i++)
{
- X509Certificate cert = (X509Certificate)acceptedCerts[i];
- BigInteger reqId = (BigInteger)acceptedReqIds[i];
+ X509Certificate cert = m_acceptedCerts[i];
+ BigInteger reqID = m_acceptedReqIDs[i];
+ AlgorithmIdentifier algorithmIdentifier = SigAlgFinder.Find(cert.SigAlgName);
+ if (null == algorithmIdentifier)
+ throw new CmpException("cannot find algorithm identifier for signature name");
- AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName);
-
- AlgorithmIdentifier digAlg = digestAlgFinder.find(algorithmIdentifier);
+ AlgorithmIdentifier digAlg = m_digestAlgFinder.Find(algorithmIdentifier);
if (null == digAlg)
throw new CmpException("cannot find algorithm for digest from signature");
byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
- v.Add(new CertStatus(digest, reqId));
+ v.Add(new CertStatus(digest, reqID));
}
return new CertificateConfirmationContent(CertConfirmContent.GetInstance(new DerSequence(v)),
- digestAlgFinder);
+ m_digestAlgFinder);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateStatus.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateStatus.cs
index 4bf4066..921f407 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateStatus.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CertificateStatus.cs
@@ -26,19 +26,13 @@ public CertificateStatus(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder,
this.certStatus = certStatus;
}
- public PkiStatusInfo PkiStatusInfo
- {
- get { return certStatus.StatusInfo; }
- }
+ public virtual PkiStatusInfo StatusInfo => certStatus.StatusInfo;
- public BigInteger CertRequestId
- {
- get { return certStatus.CertReqID.Value; }
- }
+ public virtual BigInteger CertRequestID => certStatus.CertReqID.Value;
- public bool IsVerified(X509Certificate cert)
+ public virtual bool IsVerified(X509Certificate cert)
{
- AlgorithmIdentifier digAlg = digestAlgFinder.find(sigAlgFinder.Find(cert.SigAlgName));
+ AlgorithmIdentifier digAlg = digestAlgFinder.Find(sigAlgFinder.Find(cert.SigAlgName));
if (null == digAlg)
throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CmpException.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CmpException.cs
index 816a37f..e31b76d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CmpException.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/CmpException.cs
@@ -1,13 +1,16 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
+ [Serializable]
public class CmpException
: Exception
{
public CmpException()
+ : base()
{
}
@@ -20,6 +23,11 @@ public CmpException(string message, Exception innerException)
: base(message, innerException)
{
}
+
+ protected CmpException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/GeneralPkiMessage.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/GeneralPkiMessage.cs
index fa10db9..71062fe 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/GeneralPkiMessage.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/GeneralPkiMessage.cs
@@ -1,7 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
@@ -9,7 +7,7 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
public class GeneralPkiMessage
{
- private readonly PkiMessage pkiMessage;
+ private readonly PkiMessage m_pkiMessage;
private static PkiMessage ParseBytes(byte[] encoding)
{
@@ -22,7 +20,7 @@ private static PkiMessage ParseBytes(byte[] encoding)
/// PKI message.
public GeneralPkiMessage(PkiMessage pkiMessage)
{
- this.pkiMessage = pkiMessage;
+ this.m_pkiMessage = pkiMessage;
}
///
@@ -34,29 +32,17 @@ public GeneralPkiMessage(byte[] encoding)
{
}
- public PkiHeader Header
- {
- get { return pkiMessage.Header; }
- }
+ public virtual PkiHeader Header => m_pkiMessage.Header;
- public PkiBody Body
- {
- get { return pkiMessage.Body; }
- }
+ public virtual PkiBody Body => m_pkiMessage.Body;
///
/// Return true if this message has protection bits on it. A return value of true
/// indicates the message can be used to construct a ProtectedPKIMessage.
///
- public bool HasProtection
- {
- get { return pkiMessage.Protection != null; }
- }
+ public virtual bool HasProtection => m_pkiMessage.Protection != null;
- public PkiMessage ToAsn1Structure()
- {
- return pkiMessage;
- }
+ public virtual PkiMessage ToAsn1Structure() => m_pkiMessage;
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessage.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessage.cs
index 6b79d88..96a8091 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessage.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessage.cs
@@ -17,7 +17,7 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
///
public class ProtectedPkiMessage
{
- private readonly PkiMessage pkiMessage;
+ private readonly PkiMessage m_pkiMessage;
///
/// Wrap a general message.
@@ -27,11 +27,12 @@ public class ProtectedPkiMessage
public ProtectedPkiMessage(GeneralPkiMessage pkiMessage)
{
if (!pkiMessage.HasProtection)
- throw new ArgumentException("pki message not protected");
+ throw new ArgumentException("GeneralPkiMessage not protected");
- this.pkiMessage = pkiMessage.ToAsn1Structure();
+ this.m_pkiMessage = pkiMessage.ToAsn1Structure();
}
+ // TODO[cmp] Make internal? (Has test that uses it)
///
/// Wrap a PKI message.
///
@@ -40,63 +41,49 @@ public ProtectedPkiMessage(GeneralPkiMessage pkiMessage)
public ProtectedPkiMessage(PkiMessage pkiMessage)
{
if (null == pkiMessage.Header.ProtectionAlg)
- throw new ArgumentException("pki message not protected");
+ throw new ArgumentException("PkiMessage not protected");
- this.pkiMessage = pkiMessage;
+ this.m_pkiMessage = pkiMessage;
}
- ///
- /// Message header
- ///
- public PkiHeader Header
- {
- get { return pkiMessage.Header; }
- }
+ /// Message header
+ public virtual PkiHeader Header => m_pkiMessage.Header;
- ///
- /// Message Body
- ///
- public PkiBody Body
- {
- get { return pkiMessage.Body; }
- }
+ /// Message body
+ public virtual PkiBody Body => m_pkiMessage.Body;
///
/// Return the underlying ASN.1 structure contained in this object.
///
- /// PKI Message structure
- public PkiMessage ToAsn1Message()
- {
- return pkiMessage;
- }
+ /// PkiMessage structure
+ public virtual PkiMessage ToAsn1Message() => m_pkiMessage;
///
/// Determine whether the message is protected by a password based MAC. Use verify(PKMACBuilder, char[])
/// to verify the message if this method returns true.
///
/// true if protection MAC PBE based, false otherwise.
- public bool HasPasswordBasedMacProtected
+ public virtual bool HasPasswordBasedMacProtected
{
- get { return Header.ProtectionAlg.Algorithm.Equals(CmpObjectIdentifiers.passwordBasedMac); }
+ get { return CmpObjectIdentifiers.passwordBasedMac.Equals(Header.ProtectionAlg.Algorithm); }
}
///
/// Return the extra certificates associated with this message.
///
/// an array of extra certificates, zero length if none present.
- public X509Certificate[] GetCertificates()
+ public virtual X509Certificate[] GetCertificates()
{
- CmpCertificate[] certs = pkiMessage.GetExtraCerts();
+ CmpCertificate[] certs = m_pkiMessage.GetExtraCerts();
if (null == certs)
return new X509Certificate[0];
- X509Certificate[] res = new X509Certificate[certs.Length];
+ X509Certificate[] result = new X509Certificate[certs.Length];
for (int t = 0; t < certs.Length; t++)
{
- res[t] = new X509Certificate(X509CertificateStructure.GetInstance(certs[t].GetEncoded()));
+ result[t] = new X509Certificate(certs[t].X509v3PKCert);
}
-
- return res;
+ return result;
}
///
@@ -104,27 +91,13 @@ public X509Certificate[] GetCertificates()
///
/// a factory of signature verifiers.
/// true if the provider is able to create a verifier that validates the signature, false otherwise.
- public bool Verify(IVerifierFactory verifierFactory)
+ public virtual bool Verify(IVerifierFactory verifierFactory)
{
- IStreamCalculator streamCalculator = verifierFactory.CreateCalculator();
+ IStreamCalculator streamCalculator = verifierFactory.CreateCalculator();
- IVerifier result = (IVerifier)Process(streamCalculator);
+ IVerifier result = Process(streamCalculator);
- return result.IsVerified(pkiMessage.Protection.GetBytes());
- }
-
- private object Process(IStreamCalculator streamCalculator)
- {
- Asn1EncodableVector avec = new Asn1EncodableVector();
- avec.Add(pkiMessage.Header);
- avec.Add(pkiMessage.Body);
- byte[] enc = new DerSequence(avec).GetDerEncoded();
-
- streamCalculator.Stream.Write(enc, 0, enc.Length);
- streamCalculator.Stream.Flush();
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(streamCalculator.Stream);
-
- return streamCalculator.GetResult();
+ return result.IsVerified(m_pkiMessage.Protection.GetBytes());
}
///
@@ -134,18 +107,33 @@ private object Process(IStreamCalculator streamCalculator)
/// the MAC password
/// true if the passed in password and MAC builder verify the message, false otherwise.
/// if algorithm not MAC based, or an exception is thrown verifying the MAC.
- public bool Verify(PKMacBuilder pkMacBuilder, char[] password)
+ public virtual bool Verify(PKMacBuilder pkMacBuilder, char[] password)
{
- if (!CmpObjectIdentifiers.passwordBasedMac.Equals(pkiMessage.Header.ProtectionAlg.Algorithm))
+ if (!CmpObjectIdentifiers.passwordBasedMac.Equals(m_pkiMessage.Header.ProtectionAlg.Algorithm))
throw new InvalidOperationException("protection algorithm is not mac based");
- PbmParameter parameter = PbmParameter.GetInstance(pkiMessage.Header.ProtectionAlg.Parameters);
+ PbmParameter parameter = PbmParameter.GetInstance(m_pkiMessage.Header.ProtectionAlg.Parameters);
pkMacBuilder.SetParameters(parameter);
- IBlockResult result = (IBlockResult)Process(pkMacBuilder.Build(password).CreateCalculator());
+ IBlockResult result = Process(pkMacBuilder.Build(password).CreateCalculator());
+
+ return Arrays.ConstantTimeAreEqual(result.Collect(), m_pkiMessage.Protection.GetBytes());
+ }
+
+ private TResult Process(IStreamCalculator streamCalculator)
+ {
+ Asn1EncodableVector avec = new Asn1EncodableVector();
+ avec.Add(m_pkiMessage.Header);
+ avec.Add(m_pkiMessage.Body);
+ byte[] enc = new DerSequence(avec).GetDerEncoded();
- return Arrays.ConstantTimeAreEqual(result.Collect(), this.pkiMessage.Protection.GetBytes());
+ using (var stream = streamCalculator.Stream)
+ {
+ stream.Write(enc, 0, enc.Length);
+ }
+
+ return streamCalculator.GetResult();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessageBuilder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessageBuilder.cs
index 2d67fb6..db86f1e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessageBuilder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/ProtectedPkiMessageBuilder.cs
@@ -1,24 +1,23 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
- public class ProtectedPkiMessageBuilder
+ public sealed class ProtectedPkiMessageBuilder
{
- private PkiHeaderBuilder hdrBuilBuilder;
+ private readonly PkiHeaderBuilder m_hdrBuilder;
private PkiBody body;
- private IList generalInfos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- private IList extraCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ private readonly List generalInfos = new List();
+ private readonly List extraCerts = new List();
public ProtectedPkiMessageBuilder(GeneralName sender, GeneralName recipient)
: this(PkiHeader.CMP_2000, sender, recipient)
@@ -27,18 +26,18 @@ public ProtectedPkiMessageBuilder(GeneralName sender, GeneralName recipient)
public ProtectedPkiMessageBuilder(int pvno, GeneralName sender, GeneralName recipient)
{
- hdrBuilBuilder = new PkiHeaderBuilder(pvno, sender, recipient);
+ m_hdrBuilder = new PkiHeaderBuilder(pvno, sender, recipient);
}
public ProtectedPkiMessageBuilder SetTransactionId(byte[] tid)
{
- hdrBuilBuilder.SetTransactionID(tid);
+ m_hdrBuilder.SetTransactionID(tid);
return this;
}
public ProtectedPkiMessageBuilder SetFreeText(PkiFreeText freeText)
{
- hdrBuilBuilder.SetFreeText(freeText);
+ m_hdrBuilder.SetFreeText(freeText);
return this;
}
@@ -48,33 +47,39 @@ public ProtectedPkiMessageBuilder AddGeneralInfo(InfoTypeAndValue genInfo)
return this;
}
- public ProtectedPkiMessageBuilder SetMessageTime(DerGeneralizedTime generalizedTime)
+ public ProtectedPkiMessageBuilder SetMessageTime(DateTime time)
{
- hdrBuilBuilder.SetMessageTime(generalizedTime);
+ m_hdrBuilder.SetMessageTime(new Asn1GeneralizedTime(time));
+ return this;
+ }
+
+ public ProtectedPkiMessageBuilder SetMessageTime(Asn1GeneralizedTime generalizedTime)
+ {
+ m_hdrBuilder.SetMessageTime(generalizedTime);
return this;
}
public ProtectedPkiMessageBuilder SetRecipKID(byte[] id)
{
- hdrBuilBuilder.SetRecipKID(id);
+ m_hdrBuilder.SetRecipKID(id);
return this;
}
public ProtectedPkiMessageBuilder SetRecipNonce(byte[] nonce)
{
- hdrBuilBuilder.SetRecipNonce(nonce);
+ m_hdrBuilder.SetRecipNonce(nonce);
return this;
}
public ProtectedPkiMessageBuilder SetSenderKID(byte[] id)
{
- hdrBuilBuilder.SetSenderKID(id);
+ m_hdrBuilder.SetSenderKID(id);
return this;
}
public ProtectedPkiMessageBuilder SetSenderNonce(byte[] nonce)
{
- hdrBuilBuilder.SetSenderNonce(nonce);
+ m_hdrBuilder.SetSenderNonce(nonce);
return this;
}
@@ -95,86 +100,60 @@ public ProtectedPkiMessage Build(ISignatureFactory signatureFactory)
if (null == body)
throw new InvalidOperationException("body must be set before building");
- IStreamCalculator calculator = signatureFactory.CreateCalculator();
+ IStreamCalculator calculator = signatureFactory.CreateCalculator();
- if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier))
- {
+ if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
- }
- FinalizeHeader((AlgorithmIdentifier)signatureFactory.AlgorithmDetails);
- PkiHeader header = hdrBuilBuilder.Build();
+ FinalizeHeader(algorithmDetails);
+ PkiHeader header = m_hdrBuilder.Build();
DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
return FinalizeMessage(header, protection);
}
- public ProtectedPkiMessage Build(IMacFactory factory)
+ public ProtectedPkiMessage Build(IMacFactory macFactory)
{
if (null == body)
throw new InvalidOperationException("body must be set before building");
- IStreamCalculator calculator = factory.CreateCalculator();
- FinalizeHeader((AlgorithmIdentifier)factory.AlgorithmDetails);
- PkiHeader header = hdrBuilBuilder.Build();
+ IStreamCalculator calculator = macFactory.CreateCalculator();
+
+ if (!(macFactory.AlgorithmDetails is AlgorithmIdentifier algorithmDetails))
+ throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier");
+
+ FinalizeHeader(algorithmDetails);
+ PkiHeader header = m_hdrBuilder.Build();
DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body));
return FinalizeMessage(header, protection);
}
private void FinalizeHeader(AlgorithmIdentifier algorithmIdentifier)
{
- hdrBuilBuilder.SetProtectionAlg(algorithmIdentifier);
+ m_hdrBuilder.SetProtectionAlg(algorithmIdentifier);
if (generalInfos.Count > 0)
{
- InfoTypeAndValue[] genInfos = new InfoTypeAndValue[generalInfos.Count];
- for (int t = 0; t < genInfos.Length; t++)
- {
- genInfos[t] = (InfoTypeAndValue)generalInfos[t];
- }
-
- hdrBuilBuilder.SetGeneralInfo(genInfos);
+ m_hdrBuilder.SetGeneralInfo(generalInfos.ToArray());
}
}
private ProtectedPkiMessage FinalizeMessage(PkiHeader header, DerBitString protection)
{
- if (extraCerts.Count > 0)
+ if (extraCerts.Count < 1)
+ return new ProtectedPkiMessage(new PkiMessage(header, body, protection));
+
+ CmpCertificate[] cmpCertificates = new CmpCertificate[extraCerts.Count];
+ for (int i = 0; i < cmpCertificates.Length; i++)
{
- CmpCertificate[] cmpCertificates = new CmpCertificate[extraCerts.Count];
- for (int i = 0; i < cmpCertificates.Length; i++)
- {
- byte[] cert = ((X509Certificate)extraCerts[i]).GetEncoded();
- cmpCertificates[i] = CmpCertificate.GetInstance((Asn1Sequence.FromByteArray(cert)));
- }
-
- return new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates));
+ cmpCertificates[i] = new CmpCertificate(extraCerts[i].CertificateStructure);
}
- return new ProtectedPkiMessage(new PkiMessage(header, body, protection));
+ return new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates));
}
- private byte[] CalculateSignature(IStreamCalculator signer, PkiHeader header, PkiBody body)
+ private byte[] CalculateSignature(IStreamCalculator signer, PkiHeader header, PkiBody body)
{
- Asn1EncodableVector avec = new Asn1EncodableVector();
- avec.Add(header);
- avec.Add(body);
- byte[] encoded = new DerSequence(avec).GetEncoded();
- signer.Stream.Write(encoded, 0, encoded.Length);
- object result = signer.GetResult();
-
- if (result is DefaultSignatureResult)
- {
- return ((DefaultSignatureResult)result).Collect();
- }
- else if (result is IBlockResult)
- {
- return ((IBlockResult)result).Collect();
- }
- else if (result is byte[])
- {
- return (byte[])result;
- }
-
- throw new InvalidOperationException("result is not byte[] or DefaultSignatureResult");
+ new DerSequence(header, body).EncodeTo(signer.Stream);
+ return signer.GetResult().Collect();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetails.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetails.cs
index 97a5e00..690558b 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetails.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetails.cs
@@ -1,41 +1,27 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
- public class RevocationDetails
+ public struct RevocationDetails
{
- private readonly RevDetails revDetails;
+ private readonly RevDetails m_revDetails;
public RevocationDetails(RevDetails revDetails)
{
- this.revDetails = revDetails;
+ m_revDetails = revDetails;
}
- public X509Name Subject
- {
- get { return revDetails.CertDetails.Subject; }
- }
+ public X509Name Subject => m_revDetails.CertDetails.Subject;
- public X509Name Issuer
- {
- get { return revDetails.CertDetails.Issuer; }
- }
+ public X509Name Issuer => m_revDetails.CertDetails.Issuer;
- public BigInteger SerialNumber
- {
- get { return revDetails.CertDetails.SerialNumber.Value; }
- }
+ public BigInteger SerialNumber => m_revDetails.CertDetails.SerialNumber.Value;
- public RevDetails ToASN1Structure()
- {
- return revDetails;
- }
+ public RevDetails ToASN1Structure() => m_revDetails;
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetailsBuilder.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetailsBuilder.cs
index 9affc19..618a00c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetailsBuilder.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cmp/RevocationDetailsBuilder.cs
@@ -1,7 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
@@ -10,15 +8,15 @@
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cmp
{
- public class RevocationDetailsBuilder
+ public sealed class RevocationDetailsBuilder
{
- private readonly CertTemplateBuilder _templateBuilder = new CertTemplateBuilder();
+ private readonly CertTemplateBuilder m_templateBuilder = new CertTemplateBuilder();
public RevocationDetailsBuilder SetPublicKey(SubjectPublicKeyInfo publicKey)
{
if (publicKey != null)
{
- _templateBuilder.SetPublicKey(publicKey);
+ m_templateBuilder.SetPublicKey(publicKey);
}
return this;
@@ -28,7 +26,7 @@ public RevocationDetailsBuilder SetIssuer(X509Name issuer)
{
if (issuer != null)
{
- _templateBuilder.SetIssuer(issuer);
+ m_templateBuilder.SetIssuer(issuer);
}
return this;
@@ -38,7 +36,7 @@ public RevocationDetailsBuilder SetSerialNumber(BigInteger serialNumber)
{
if (serialNumber != null)
{
- _templateBuilder.SetSerialNumber(new DerInteger(serialNumber));
+ m_templateBuilder.SetSerialNumber(new DerInteger(serialNumber));
}
return this;
@@ -48,7 +46,7 @@ public RevocationDetailsBuilder SetSubject(X509Name subject)
{
if (subject != null)
{
- _templateBuilder.SetSubject(subject);
+ m_templateBuilder.SetSubject(subject);
}
return this;
@@ -56,7 +54,7 @@ public RevocationDetailsBuilder SetSubject(X509Name subject)
public RevocationDetails Build()
{
- return new RevocationDetails(new RevDetails(_templateBuilder.Build()));
+ return new RevocationDetails(new RevDetails(m_templateBuilder.Build()));
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerationException.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerationException.cs
index 2aae9bd..9918f74 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerationException.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerationException.cs
@@ -1,31 +1,33 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
-#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE)
[Serializable]
-#endif
public class CmsAttributeTableGenerationException
: CmsException
{
- public CmsAttributeTableGenerationException()
- {
- }
+ public CmsAttributeTableGenerationException()
+ : base()
+ {
+ }
+
+ public CmsAttributeTableGenerationException(string message)
+ : base(message)
+ {
+ }
- public CmsAttributeTableGenerationException(
- string name)
- : base(name)
- {
- }
+ public CmsAttributeTableGenerationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
- public CmsAttributeTableGenerationException(
- string name,
- Exception e)
- : base(name, e)
- {
- }
+ protected CmsAttributeTableGenerationException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerator.cs
index 5513236..888bee5 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAttributeTableGenerator.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
@@ -22,7 +21,7 @@ public enum CmsAttributeTableParameter
public interface CmsAttributeTableGenerator
{
- AttributeTable GetAttributes(IDictionary parameters);
+ AttributeTable GetAttributes(IDictionary parameters);
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthEnvelopedData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthEnvelopedData.cs
index a6830c9..97b4127 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthEnvelopedData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthEnvelopedData.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedData.cs
index 873d974..3e0baca 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedData.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataGenerator.cs
index 4cb7d54..0890322 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataGenerator.cs
@@ -7,7 +7,6 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
@@ -32,20 +31,14 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class CmsAuthenticatedDataGenerator
: CmsAuthenticatedGenerator
{
- /**
- * base constructor
- */
public CmsAuthenticatedDataGenerator()
{
}
- /**
- * constructor allowing specific source of randomness
- * @param rand instance of SecureRandom to use
- */
- public CmsAuthenticatedDataGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Constructor allowing specific source of randomness
+ /// Instance of SecureRandom to use.
+ public CmsAuthenticatedDataGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -71,9 +64,7 @@ private CmsAuthenticatedData Generate(
Asn1Encodable asn1Params = GenerateAsn1Parameters(macOid, encKeyBytes);
- ICipherParameters cipherParameters;
- macAlgId = GetAlgorithmIdentifier(
- macOid, encKey, asn1Params, out cipherParameters);
+ macAlgId = GetAlgorithmIdentifier(macOid, encKey, asn1Params, out var cipherParameters);
IMac mac = MacUtilities.GetMac(macOid);
// TODO Confirm no ParametersWithRandom needed
@@ -81,12 +72,11 @@ private CmsAuthenticatedData Generate(
// mac.Init(cipherParameters);
mac.Init(encKey);
- MemoryStream bOut = new MemoryStream();
- Stream mOut = new TeeOutputStream(bOut, new MacSink(mac));
-
- content.Write(mOut);
-
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(mOut);
+ var bOut = new MemoryStream();
+ using (var mOut = new TeeOutputStream(bOut, new MacSink(mac)))
+ {
+ content.Write(mOut);
+ }
encContent = new BerOctetString(bOut.ToArray());
@@ -106,13 +96,13 @@ private CmsAuthenticatedData Generate(
throw new CmsException("exception decoding algorithm parameters.", e);
}
- Asn1EncodableVector recipientInfos = new Asn1EncodableVector();
+ var recipientInfos = new Asn1EncodableVector();
foreach (RecipientInfoGenerator rig in recipientInfoGenerators)
{
try
{
- recipientInfos.Add(rig.Generate(encKey, rand));
+ recipientInfos.Add(rig.Generate(encKey, m_random));
}
catch (InvalidKeyException e)
{
@@ -124,11 +114,11 @@ private CmsAuthenticatedData Generate(
}
}
- ContentInfo eci = new ContentInfo(CmsObjectIdentifiers.Data, encContent);
-
- ContentInfo contentInfo = new ContentInfo(
- CmsObjectIdentifiers.AuthenticatedData,
- new AuthenticatedData(null, new DerSet(recipientInfos), macAlgId, null, eci, null, macResult, null));
+ var eci = new ContentInfo(CmsObjectIdentifiers.Data, encContent);
+
+ var contentInfo = new ContentInfo(
+ CmsObjectIdentifiers.AuthenticatedData,
+ new AuthenticatedData(null, new DerSet(recipientInfos), macAlgId, null, eci, null, macResult, null));
return new CmsAuthenticatedData(contentInfo);
}
@@ -145,7 +135,7 @@ public CmsAuthenticatedData Generate(
// FIXME Will this work for macs?
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keyGen.DefaultStrength));
+ keyGen.Init(new KeyGenerationParameters(m_random, keyGen.DefaultStrength));
return Generate(content, encryptionOid, keyGen);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataParser.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataParser.cs
index 6198e34..f2e4ad1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataParser.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataParser.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataStreamGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataStreamGenerator.cs
index df89098..16eb120 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataStreamGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -44,20 +44,14 @@ public class CmsAuthenticatedDataStreamGenerator
private int _bufferSize;
private bool _berEncodeRecipientSet;
- /**
- * base constructor
- */
public CmsAuthenticatedDataStreamGenerator()
{
}
- /**
- * constructor allowing specific source of randomness
- * @param rand instance of SecureRandom to use
- */
- public CmsAuthenticatedDataStreamGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Constructor allowing specific source of randomness
+ /// Instance of SecureRandom to use.
+ public CmsAuthenticatedDataStreamGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -107,7 +101,7 @@ private Stream Open(
{
try
{
- recipientInfos.Add(rig.Generate(encKey, rand));
+ recipientInfos.Add(rig.Generate(encKey, m_random));
}
catch (InvalidKeyException e)
{
@@ -197,7 +191,7 @@ public Stream Open(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keyGen.DefaultStrength));
+ keyGen.Init(new KeyGenerationParameters(m_random, keyGen.DefaultStrength));
return Open(outStr, encryptionOid, keyGen);
}
@@ -212,7 +206,7 @@ public Stream Open(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keySize));
+ keyGen.Init(new KeyGenerationParameters(m_random, keySize));
return Open(outStr, encryptionOid, keyGen);
}
@@ -240,26 +234,28 @@ public CmsAuthenticatedDataOutputStream(
this.eiGen = eiGen;
}
- public override void WriteByte(
- byte b)
- {
- macStream.WriteByte(b);
- }
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ macStream.Write(buffer, offset, count);
+ }
- public override void Write(
- byte[] bytes,
- int off,
- int len)
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override void Write(ReadOnlySpan buffer)
+ {
+ macStream.Write(buffer);
+ }
+#endif
+
+ public override void WriteByte(byte value)
{
- macStream.Write(bytes, off, len);
+ macStream.WriteByte(value);
}
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(macStream);
+ macStream.Dispose();
// TODO Parent context(s) should really be be closed explicitly
@@ -275,25 +271,6 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(macStream);
-
- // TODO Parent context(s) should really be be closed explicitly
-
- eiGen.Close();
-
- // [TODO] auth attributes go here
- byte[] macOctets = MacUtilities.DoFinal(mac);
- authGen.AddObject(new DerOctetString(macOctets));
- // [TODO] unauth attributes go here
-
- authGen.Close();
- cGen.Close();
- base.Close();
- }
-#endif
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedGenerator.cs
index e8a8e3a..2815e0d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSAuthenticatedGenerator.cs
@@ -16,21 +16,14 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class CmsAuthenticatedGenerator
: CmsEnvelopedGenerator
{
- /**
- * base constructor
- */
public CmsAuthenticatedGenerator()
{
}
- /**
- * constructor allowing specific source of randomness
- *
- * @param rand instance of SecureRandom to use
- */
- public CmsAuthenticatedGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Constructor allowing specific source of randomness
+ /// Instance of SecureRandom to use.
+ public CmsAuthenticatedGenerator(SecureRandom random)
+ : base(random)
{
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedData.cs
index c97ad66..9e6696c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedData.cs
@@ -1,12 +1,11 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO.Compression;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -47,7 +46,7 @@ public byte[] GetContent()
ContentInfo content = comData.EncapContentInfo;
Asn1OctetString bytes = (Asn1OctetString) content.Content;
- ZInputStream zIn = new ZInputStream(bytes.GetOctetStream());
+ Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
try
{
@@ -59,7 +58,7 @@ public byte[] GetContent()
}
finally
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(zIn);
+ zIn.Dispose();
}
}
@@ -78,8 +77,7 @@ public byte[] GetContent(int limit)
ContentInfo content = comData.EncapContentInfo;
Asn1OctetString bytes = (Asn1OctetString)content.Content;
-
- ZInputStream zIn = new ZInputStream(new MemoryStream(bytes.GetOctets(), false));
+ Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
try
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataGenerator.cs
index 0ed4a4f..47cd011 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataGenerator.cs
@@ -1,14 +1,12 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -25,32 +23,34 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
*/
public class CmsCompressedDataGenerator
{
- public const string ZLib = "1.2.840.113549.1.9.16.3.8";
+ public static readonly string ZLib = CmsObjectIdentifiers.ZlibCompress.Id;
- public CmsCompressedDataGenerator()
+ public CmsCompressedDataGenerator()
{
}
/**
* Generate an object that contains an CMS Compressed Data
*/
- public CmsCompressedData Generate(
- CmsProcessable content,
- string compressionOid)
+ public CmsCompressedData Generate(CmsProcessable content, string compressionOid)
{
+ if (ZLib != compressionOid)
+ throw new ArgumentException("Unsupported compression algorithm: " + compressionOid,
+ nameof(compressionOid));
+
AlgorithmIdentifier comAlgId;
Asn1OctetString comOcts;
try
{
MemoryStream bOut = new MemoryStream();
- ZOutputStream zOut = new ZOutputStream(bOut, JZlib.Z_DEFAULT_COMPRESSION);
-
- content.Write(zOut);
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(zOut);
+ using (var zOut = Utilities.IO.Compression.ZLib.CompressOutput(bOut, -1))
+ {
+ content.Write(zOut);
+ }
- comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid));
+ comAlgId = new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress);
comOcts = new BerOctetString(bOut.ToArray());
}
catch (IOException e)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataParser.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataParser.cs
index a44d910..280fda9 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataParser.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataParser.cs
@@ -1,12 +1,11 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO.Compression;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -47,8 +46,9 @@ public CmsTypedStream GetContent()
ContentInfoParser content = comData.GetEncapContentInfo();
Asn1OctetStringParser bytes = (Asn1OctetStringParser)content.GetContent(Asn1Tags.OctetString);
+ Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
- return new CmsTypedStream(content.ContentType.ToString(), new ZInputStream(bytes.GetOctetStream()));
+ return new CmsTypedStream(content.ContentType.ToString(), zIn);
}
catch (IOException e)
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataStreamGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataStreamGenerator.cs
index d55df66..f223591 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataStreamGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSCompressedDataStreamGenerator.cs
@@ -6,9 +6,9 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Zlib;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -29,10 +29,10 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
*/
public class CmsCompressedDataStreamGenerator
{
- public const string ZLib = "1.2.840.113549.1.9.16.3.8";
+ public static readonly string ZLib = CmsObjectIdentifiers.ZlibCompress.Id;
+
+ private int _bufferSize;
- private int _bufferSize;
-
/**
* base constructor
*/
@@ -45,24 +45,27 @@ public CmsCompressedDataStreamGenerator()
*
* @param bufferSize length of octet strings to buffer the data.
*/
- public void SetBufferSize(
- int bufferSize)
+ public void SetBufferSize(int bufferSize)
{
_bufferSize = bufferSize;
}
- public Stream Open(
- Stream outStream,
- string compressionOID)
+ public Stream Open(Stream outStream)
+ {
+ return Open(outStream, CmsObjectIdentifiers.Data.Id, ZLib);
+ }
+
+ public Stream Open(Stream outStream, string compressionOid)
{
- return Open(outStream, CmsObjectIdentifiers.Data.Id, compressionOID);
+ return Open(outStream, CmsObjectIdentifiers.Data.Id, compressionOid);
}
- public Stream Open(
- Stream outStream,
- string contentOID,
- string compressionOID)
+ public Stream Open(Stream outStream, string contentOid, string compressionOid)
{
+ if (ZLib != compressionOid)
+ throw new ArgumentException("Unsupported compression algorithm: " + compressionOid,
+ nameof(compressionOid));
+
BerSequenceGenerator sGen = new BerSequenceGenerator(outStream);
sGen.AddObject(CmsObjectIdentifiers.CompressedData);
@@ -77,32 +80,32 @@ public Stream Open(
cGen.AddObject(new DerInteger(0));
// CompressionAlgorithmIdentifier
- cGen.AddObject(new AlgorithmIdentifier(new DerObjectIdentifier(ZLib)));
+ cGen.AddObject(new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress));
//
// Encapsulated ContentInfo
//
BerSequenceGenerator eiGen = new BerSequenceGenerator(cGen.GetRawOutputStream());
- eiGen.AddObject(new DerObjectIdentifier(contentOID));
+ eiGen.AddObject(new DerObjectIdentifier(contentOid));
Stream octetStream = CmsUtilities.CreateBerOctetOutputStream(
eiGen.GetRawOutputStream(), 0, true, _bufferSize);
return new CmsCompressedOutputStream(
- new ZOutputStream(octetStream, JZlib.Z_DEFAULT_COMPRESSION), sGen, cGen, eiGen);
+ Utilities.IO.Compression.ZLib.CompressOutput(octetStream, -1), sGen, cGen, eiGen);
}
private class CmsCompressedOutputStream
: BaseOutputStream
{
- private ZOutputStream _out;
+ private Stream _out;
private BerSequenceGenerator _sGen;
private BerSequenceGenerator _cGen;
private BerSequenceGenerator _eiGen;
internal CmsCompressedOutputStream(
- ZOutputStream outStream,
+ Stream outStream,
BerSequenceGenerator sGen,
BerSequenceGenerator cGen,
BerSequenceGenerator eiGen)
@@ -113,26 +116,28 @@ internal CmsCompressedOutputStream(
_eiGen = eiGen;
}
- public override void WriteByte(
- byte b)
+ public override void Write(byte[] buffer, int offset, int count)
{
- _out.WriteByte(b);
+ _out.Write(buffer, offset, count);
}
- public override void Write(
- byte[] bytes,
- int off,
- int len)
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override void Write(ReadOnlySpan buffer)
+ {
+ _out.Write(buffer);
+ }
+#endif
+
+ public override void WriteByte(byte value)
{
- _out.Write(bytes, off, len);
+ _out.WriteByte(value);
}
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_out);
+ _out.Dispose();
// TODO Parent context(s) should really be be closed explicitly
@@ -142,19 +147,6 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_out);
-
- // TODO Parent context(s) should really be be closed explicitly
-
- _eiGen.Close();
- _cGen.Close();
- _sGen.Close();
- base.Close();
- }
-#endif
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSContentInfoParser.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSContentInfoParser.cs
index 3357048..4de7428 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSContentInfoParser.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSContentInfoParser.cs
@@ -44,7 +44,7 @@ protected CmsContentInfoParser(
*/
public void Close()
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(this.data);
+ data.Dispose();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedData.cs
index cf9570b..3d0d143 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedData.cs
@@ -1,14 +1,11 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataGenerator.cs
index 8ea1451..b0e69b6 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataGenerator.cs
@@ -1,24 +1,16 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -43,10 +35,9 @@ public CmsEnvelopedDataGenerator()
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- public CmsEnvelopedDataGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Instance of SecureRandom to use.
+ public CmsEnvelopedDataGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -75,14 +66,13 @@ private CmsEnvelopedData Generate(
encryptionOid, encKey, asn1Params, out cipherParameters);
IBufferedCipher cipher = CipherUtilities.GetCipher(encryptionOid);
- cipher.Init(true, new ParametersWithRandom(cipherParameters, rand));
+ cipher.Init(true, new ParametersWithRandom(cipherParameters, m_random));
MemoryStream bOut = new MemoryStream();
- CipherStream cOut = new CipherStream(bOut, null, cipher);
-
- content.Write(cOut);
-
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(cOut);
+ using (var cOut = new CipherStream(bOut, null, cipher))
+ {
+ content.Write(cOut);
+ }
encContent = new BerOctetString(bOut.ToArray());
}
@@ -106,7 +96,7 @@ private CmsEnvelopedData Generate(
{
try
{
- recipientInfos.Add(rig.Generate(encKey, rand));
+ recipientInfos.Add(rig.Generate(encKey, m_random));
}
catch (InvalidKeyException e)
{
@@ -126,7 +116,8 @@ private CmsEnvelopedData Generate(
Asn1Set unprotectedAttrSet = null;
if (unprotectedAttributeGenerator != null)
{
- Asn1.Cms.AttributeTable attrTable = unprotectedAttributeGenerator.GetAttributes(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable());
+ Asn1.Cms.AttributeTable attrTable = unprotectedAttributeGenerator.GetAttributes(
+ new Dictionary());
unprotectedAttrSet = new BerSet(attrTable.ToAsn1EncodableVector());
}
@@ -147,7 +138,7 @@ public CmsEnvelopedData Generate(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keyGen.DefaultStrength));
+ keyGen.Init(new KeyGenerationParameters(m_random, keyGen.DefaultStrength));
return Generate(content, encryptionOid, keyGen);
}
@@ -169,9 +160,12 @@ public CmsEnvelopedData Generate(CmsProcessable content, ICipherBuilderWithKey c
encKey = (KeyParameter) cipherBuilder.Key;
MemoryStream collector = new MemoryStream();
- Stream bOut = cipherBuilder.BuildCipher(collector).Stream;
- content.Write(bOut);
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(bOut);
+ var cipher = cipherBuilder.BuildCipher(collector);
+ using (var bOut = cipher.Stream)
+ {
+ content.Write(bOut);
+ }
+
encContent = new BerOctetString(collector.ToArray());
}
catch (SecurityUtilityException e)
@@ -194,7 +188,7 @@ public CmsEnvelopedData Generate(CmsProcessable content, ICipherBuilderWithKey c
{
try
{
- recipientInfos.Add(rig.Generate(encKey, rand));
+ recipientInfos.Add(rig.Generate(encKey, m_random));
}
catch (InvalidKeyException e)
{
@@ -214,7 +208,8 @@ public CmsEnvelopedData Generate(CmsProcessable content, ICipherBuilderWithKey c
Asn1Set unprotectedAttrSet = null;
if (unprotectedAttributeGenerator != null)
{
- Asn1.Cms.AttributeTable attrTable = unprotectedAttributeGenerator.GetAttributes(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable());
+ Asn1.Cms.AttributeTable attrTable = unprotectedAttributeGenerator.GetAttributes(
+ new Dictionary());
unprotectedAttrSet = new BerSet(attrTable.ToAsn1EncodableVector());
}
@@ -236,7 +231,7 @@ public CmsEnvelopedData Generate(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keySize));
+ keyGen.Init(new KeyGenerationParameters(m_random, keySize));
return Generate(content, encryptionOid, keyGen);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataParser.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataParser.cs
index 57fcc7b..a13ae5a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataParser.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataParser.cs
@@ -1,13 +1,11 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataStreamGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataStreamGenerator.cs
index 7b82027..cdc8e07 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataStreamGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -1,23 +1,18 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -53,10 +48,9 @@ public CmsEnvelopedDataStreamGenerator()
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- public CmsEnvelopedDataStreamGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Instance of SecureRandom to use.
+ public CmsEnvelopedDataStreamGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -111,7 +105,7 @@ private Stream Open(
{
try
{
- recipientInfos.Add(rig.Generate(encKey, rand));
+ recipientInfos.Add(rig.Generate(encKey, m_random));
}
catch (InvalidKeyException e)
{
@@ -169,7 +163,7 @@ private Stream Open(
eiGen.GetRawOutputStream(), 0, false, _bufferSize);
IBufferedCipher cipher = CipherUtilities.GetCipher(encAlgID.Algorithm);
- cipher.Init(true, new ParametersWithRandom(cipherParameters, rand));
+ cipher.Init(true, new ParametersWithRandom(cipherParameters, m_random));
CipherStream cOut = new CipherStream(octetOutputStream, null, cipher);
return new CmsEnvelopedDataOutputStream(this, cOut, cGen, envGen, eiGen);
@@ -198,7 +192,7 @@ public Stream Open(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keyGen.DefaultStrength));
+ keyGen.Init(new KeyGenerationParameters(m_random, keyGen.DefaultStrength));
return Open(outStream, encryptionOid, keyGen);
}
@@ -214,7 +208,7 @@ public Stream Open(
{
CipherKeyGenerator keyGen = GeneratorUtilities.GetKeyGenerator(encryptionOid);
- keyGen.Init(new KeyGenerationParameters(rand, keySize));
+ keyGen.Init(new KeyGenerationParameters(m_random, keySize));
return Open(outStream, encryptionOid, keyGen);
}
@@ -243,68 +237,48 @@ public CmsEnvelopedDataOutputStream(
_eiGen = eiGen;
}
- public override void WriteByte(
- byte b)
+ public override void Write(byte[] buffer, int offset, int count)
{
- _out.WriteByte(b);
+ _out.Write(buffer, offset, count);
}
- public override void Write(
- byte[] bytes,
- int off,
- int len)
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override void Write(ReadOnlySpan buffer)
+ {
+ _out.Write(buffer);
+ }
+#endif
+
+ public override void WriteByte(byte value)
{
- _out.Write(bytes, off, len);
+ _out.WriteByte(value);
}
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_out);
+ {
+ _out.Dispose();
// TODO Parent context(s) should really be closed explicitly
- _eiGen.Close();
+ _eiGen.Close();
if (_outer.unprotectedAttributeGenerator != null)
{
- Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable());
+ Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(
+ new Dictionary());
Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector());
_envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs));
}
- _envGen.Close();
- _cGen.Close();
+ _envGen.Close();
+ _cGen.Close();
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_out);
-
- // TODO Parent context(s) should really be closed explicitly
-
- _eiGen.Close();
-
- if (_outer.unprotectedAttributeGenerator != null)
- {
- Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable());
-
- Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector());
-
- _envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs));
- }
-
- _envGen.Close();
- _cGen.Close();
- base.Close();
- }
-#endif
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedGenerator.cs
index 4517fa3..21b55b2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedGenerator.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
@@ -15,7 +15,6 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
@@ -33,7 +32,7 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
* CMSEnvelopedData data = fact.generate(content, algorithm, "BC");
*
*/
- public class CmsEnvelopedGenerator
+ public abstract class CmsEnvelopedGenerator
{
// Note: These tables are complementary: If rc2Table[i]==j, then rc2Ekb[j]==i
internal static readonly short[] rc2Table =
@@ -102,22 +101,24 @@ public class CmsEnvelopedGenerator
public static readonly string ECDHSha1Kdf = X9ObjectIdentifiers.DHSinglePassStdDHSha1KdfScheme.Id;
public static readonly string ECMqvSha1Kdf = X9ObjectIdentifiers.MqvSinglePassSha1KdfScheme.Id;
- internal readonly IList recipientInfoGenerators = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- internal readonly SecureRandom rand;
+ internal readonly IList recipientInfoGenerators = new List();
+ internal readonly SecureRandom m_random;
internal CmsAttributeTableGenerator unprotectedAttributeGenerator = null;
- public CmsEnvelopedGenerator()
- : this(new SecureRandom())
+ protected CmsEnvelopedGenerator()
+ : this(CryptoServicesRegistrar.GetSecureRandom())
{
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- public CmsEnvelopedGenerator(
- SecureRandom rand)
+ /// Instance of SecureRandom to use.
+ protected CmsEnvelopedGenerator(SecureRandom random)
{
- this.rand = rand;
+ if (random == null)
+ throw new ArgumentNullException(nameof(random));
+
+ m_random = random;
}
public CmsAttributeTableGenerator UnprotectedAttributeGenerator
@@ -218,7 +219,7 @@ public void AddKeyAgreementRecipient(
X509Certificate recipientCert,
string cekWrapAlgorithm)
{
- IList recipientCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
+ var recipientCerts = new List(1);
recipientCerts.Add(recipientCert);
AddKeyAgreementRecipients(agreementAlgorithm, senderPrivateKey, senderPublicKey,
@@ -240,7 +241,7 @@ public void AddKeyAgreementRecipients(
string agreementAlgorithm,
AsymmetricKeyParameter senderPrivateKey,
AsymmetricKeyParameter senderPublicKey,
- ICollection recipientCerts,
+ IEnumerable recipientCerts,
string cekWrapAlgorithm)
{
if (!senderPrivateKey.IsPrivate)
@@ -256,7 +257,7 @@ public void AddKeyAgreementRecipients(
KeyAgreeRecipientInfoGenerator karig = new KeyAgreeRecipientInfoGenerator();
karig.KeyAgreementOID = new DerObjectIdentifier(agreementAlgorithm);
karig.KeyEncryptionOID = new DerObjectIdentifier(cekWrapAlgorithm);
- karig.RecipientCerts = recipientCerts;
+ karig.RecipientCerts = new List(recipientCerts);
karig.SenderKeyPair = new AsymmetricCipherKeyPair(senderPublicKey, senderPrivateKey);
recipientInfoGenerators.Add(karig);
@@ -307,7 +308,7 @@ protected internal virtual Asn1Encodable GenerateAsn1Parameters(
if (encryptionOid.Equals(RC2Cbc))
{
byte[] iv = new byte[8];
- rand.NextBytes(iv);
+ m_random.NextBytes(iv);
// TODO Is this detailed repeat of Java version really necessary?
int effKeyBits = encKeyBytes.Length * 8;
@@ -326,7 +327,7 @@ protected internal virtual Asn1Encodable GenerateAsn1Parameters(
}
else
{
- asn1Params = ParameterUtilities.GenerateParameters(encryptionOid, rand);
+ asn1Params = ParameterUtilities.GenerateParameters(encryptionOid, m_random);
}
}
catch (SecurityUtilityException)
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedHelper.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedHelper.cs
index 837667e..c95aee1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedHelper.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSEnvelopedHelper.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -11,7 +11,6 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
@@ -20,8 +19,8 @@ class CmsEnvelopedHelper
{
internal static readonly CmsEnvelopedHelper Instance = new CmsEnvelopedHelper();
- private static readonly IDictionary KeySizes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary BaseCipherNames = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private static readonly IDictionary KeySizes = new Dictionary();
+ private static readonly IDictionary BaseCipherNames = new Dictionary();
static CmsEnvelopedHelper()
{
@@ -78,35 +77,32 @@ internal IWrapper CreateWrapper(
}
}
- internal string GetRfc3211WrapperName(
- string oid)
+ internal string GetRfc3211WrapperName(string oid)
{
if (oid == null)
- throw new ArgumentNullException("oid");
+ throw new ArgumentNullException(nameof(oid));
- string alg = (string) BaseCipherNames[oid];
-
- if (alg == null)
- throw new ArgumentException("no name for " + oid, "oid");
+ if (!BaseCipherNames.TryGetValue(oid, out var alg))
+ throw new ArgumentException("no name for " + oid, nameof(oid));
return alg + "RFC3211Wrap";
}
- internal int GetKeySize(
- string oid)
+ internal int GetKeySize(string oid)
{
- if (!KeySizes.Contains(oid))
- {
+ if (oid == null)
+ throw new ArgumentNullException(nameof(oid));
+
+ if (!KeySizes.TryGetValue(oid, out var keySize))
throw new ArgumentException("no keysize for " + oid, "oid");
- }
- return (int) KeySizes[oid];
+ return keySize;
}
internal static RecipientInformationStore BuildRecipientInformationStore(
Asn1Set recipientInfos, CmsSecureReadable secureReadable)
{
- IList infos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var infos = new List();
for (int i = 0; i != recipientInfos.Count; i++)
{
RecipientInfo info = RecipientInfo.GetInstance(recipientInfos[i]);
@@ -116,25 +112,25 @@ internal static RecipientInformationStore BuildRecipientInformationStore(
return new RecipientInformationStore(infos);
}
- private static void ReadRecipientInfo(
- IList infos, RecipientInfo info, CmsSecureReadable secureReadable)
+ private static void ReadRecipientInfo(IList infos, RecipientInfo info,
+ CmsSecureReadable secureReadable)
{
Asn1Encodable recipInfo = info.Info;
- if (recipInfo is KeyTransRecipientInfo)
+ if (recipInfo is KeyTransRecipientInfo keyTransRecipientInfo)
{
- infos.Add(new KeyTransRecipientInformation((KeyTransRecipientInfo)recipInfo, secureReadable));
+ infos.Add(new KeyTransRecipientInformation(keyTransRecipientInfo, secureReadable));
}
- else if (recipInfo is KekRecipientInfo)
+ else if (recipInfo is KekRecipientInfo kekRecipientInfo)
{
- infos.Add(new KekRecipientInformation((KekRecipientInfo)recipInfo, secureReadable));
+ infos.Add(new KekRecipientInformation(kekRecipientInfo, secureReadable));
}
- else if (recipInfo is KeyAgreeRecipientInfo)
+ else if (recipInfo is KeyAgreeRecipientInfo keyAgreeRecipientInfo)
{
- KeyAgreeRecipientInformation.ReadRecipientInfo(infos, (KeyAgreeRecipientInfo)recipInfo, secureReadable);
+ KeyAgreeRecipientInformation.ReadRecipientInfo(infos, keyAgreeRecipientInfo, secureReadable);
}
- else if (recipInfo is PasswordRecipientInfo)
+ else if (recipInfo is PasswordRecipientInfo passwordRecipientInfo)
{
- infos.Add(new PasswordRecipientInformation((PasswordRecipientInfo)recipInfo, secureReadable));
+ infos.Add(new PasswordRecipientInformation(passwordRecipientInfo, secureReadable));
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSException.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSException.cs
index 72d1ded..e60631f 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSException.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSException.cs
@@ -1,29 +1,31 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
+using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
-#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE)
[Serializable]
-#endif
public class CmsException
: Exception
{
public CmsException()
+ : base()
+ {
+ }
+
+ public CmsException(string message)
+ : base(message)
{
}
- public CmsException(
- string msg)
- : base(msg)
+ public CmsException(string message, Exception innerException)
+ : base(message, innerException)
{
}
- public CmsException(
- string msg,
- Exception e)
- : base(msg, e)
+ protected CmsException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
{
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSPBEKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSPBEKey.cs
index 066ebc2..f19cc3c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSPBEKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSPBEKey.cs
@@ -21,23 +21,6 @@ public abstract class CmsPbeKey
internal readonly byte[] salt;
internal readonly int iterationCount;
-
- public CmsPbeKey(
- string password,
- byte[] salt,
- int iterationCount)
- : this(password.ToCharArray(), salt, iterationCount)
- {
- }
-
-
- public CmsPbeKey(
- string password,
- AlgorithmIdentifier keyDerivationAlgorithm)
- : this(password.ToCharArray(), keyDerivationAlgorithm)
- {
- }
-
public CmsPbeKey(
char[] password,
byte[] salt,
@@ -69,23 +52,11 @@ public CmsPbeKey(
Array.Clear(this.password, 0, this.password.Length);
}
-
- public string Password
- {
- get { return new string(password); }
- }
-
public byte[] Salt
{
get { return Arrays.Clone(salt); }
}
-
- public byte[] GetSalt()
- {
- return Salt;
- }
-
public int IterationCount
{
get { return iterationCount; }
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessable.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessable.cs
index a281503..d38ab09 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessable.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessable.cs
@@ -14,9 +14,6 @@ public interface CmsProcessable
/// This routine may be called multiple times.
///
void Write(Stream outStream);
-
- [Obsolete]
- object GetContent();
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableByteArray.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableByteArray.cs
index a86007c..8570ed7 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableByteArray.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableByteArray.cs
@@ -2,6 +2,7 @@
#pragma warning disable
using System;
using System.IO;
+
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
@@ -42,13 +43,6 @@ public virtual void Write(Stream zOut)
{
zOut.Write(bytes, 0, bytes.Length);
}
-
- /// A clone of the byte array
- [Obsolete]
- public virtual object GetContent()
- {
- return bytes.Clone();
- }
}
}
#pragma warning restore
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableFile.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableFile.cs
index e66bb22..f3a1f3d 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableFile.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableFile.cs
@@ -1,7 +1,5 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-#if !PORTABLE || NETFX_CORE || DOTNET
-using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -38,19 +36,12 @@ public virtual Stream GetInputStream()
public virtual void Write(Stream zOut)
{
- Stream inStr = _file.OpenRead();
- Streams.PipeAll(inStr, zOut, _bufSize);
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(inStr);
- }
-
- /// The file handle
- [Obsolete]
- public virtual object GetContent()
- {
- return _file;
+ using (var inStr = _file.OpenRead())
+ {
+ Streams.PipeAll(inStr, zOut, _bufSize);
+ }
}
}
}
-#endif
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableInputStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableInputStream.cs
index 702b2dd..0a8a4b3 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableInputStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSProcessableInputStream.cs
@@ -32,13 +32,7 @@ public virtual void Write(Stream output)
CheckSingleUsage();
Streams.PipeAll(input, output);
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(input);
- }
-
- [Obsolete]
- public virtual object GetContent()
- {
- return GetInputStream();
+ input.Dispose();
}
protected virtual void CheckSingleUsage()
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedData.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedData.cs
index f267b79..ab49bbb 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedData.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedData.cs
@@ -1,16 +1,13 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -45,13 +42,9 @@ public class CmsSignedData
private SignedData signedData;
private ContentInfo contentInfo;
private SignerInformationStore signerInfoStore;
- private IX509Store attrCertStore;
- private IX509Store certificateStore;
- private IX509Store crlStore;
- private IDictionary hashes;
+ private IDictionary m_hashes;
- private CmsSignedData(
- CmsSignedData c)
+ private CmsSignedData(CmsSignedData c)
{
this.signedData = c.signedData;
this.contentInfo = c.contentInfo;
@@ -59,15 +52,12 @@ private CmsSignedData(
this.signerInfoStore = c.signerInfoStore;
}
- public CmsSignedData(
- byte[] sigBlock)
+ public CmsSignedData(byte[] sigBlock)
: this(CmsUtilities.ReadContentInfo(new MemoryStream(sigBlock, false)))
{
}
- public CmsSignedData(
- CmsProcessable signedContent,
- byte[] sigBlock)
+ public CmsSignedData(CmsProcessable signedContent, byte[] sigBlock)
: this(signedContent, CmsUtilities.ReadContentInfo(new MemoryStream(sigBlock, false)))
{
}
@@ -78,9 +68,7 @@ public CmsSignedData(
* @param hashes a map of precomputed digests for content indexed by name of hash.
* @param sigBlock the signature object.
*/
- public CmsSignedData(
- IDictionary hashes,
- byte[] sigBlock)
+ public CmsSignedData(IDictionary hashes, byte[] sigBlock)
: this(hashes, CmsUtilities.ReadContentInfo(sigBlock))
{
}
@@ -91,9 +79,7 @@ public CmsSignedData(
* @param signedContent the content that was signed.
* @param sigData the signature object.
*/
- public CmsSignedData(
- CmsProcessable signedContent,
- Stream sigData)
+ public CmsSignedData(CmsProcessable signedContent, Stream sigData)
: this(signedContent, CmsUtilities.ReadContentInfo(sigData))
{
}
@@ -101,32 +87,26 @@ public CmsSignedData(
/**
* base constructor - with encapsulated content
*/
- public CmsSignedData(
- Stream sigData)
+ public CmsSignedData(Stream sigData)
: this(CmsUtilities.ReadContentInfo(sigData))
{
}
- public CmsSignedData(
- CmsProcessable signedContent,
- ContentInfo sigData)
+ public CmsSignedData(CmsProcessable signedContent, ContentInfo sigData)
{
this.signedContent = signedContent;
this.contentInfo = sigData;
this.signedData = SignedData.GetInstance(contentInfo.Content);
}
- public CmsSignedData(
- IDictionary hashes,
- ContentInfo sigData)
+ public CmsSignedData(IDictionary hashes, ContentInfo sigData)
{
- this.hashes = hashes;
+ this.m_hashes = hashes;
this.contentInfo = sigData;
this.signedData = SignedData.GetInstance(contentInfo.Content);
}
- public CmsSignedData(
- ContentInfo sigData)
+ public CmsSignedData(ContentInfo sigData)
{
this.contentInfo = sigData;
this.signedData = SignedData.GetInstance(contentInfo.Content);
@@ -152,11 +132,6 @@ public int Version
get { return signedData.Version.IntValueExact; }
}
- internal IX509Store GetCertificates()
- {
- return Helper.GetCertificates(signedData.Certificates);
- }
-
/**
* return the collection of signers that are associated with the
* signatures for the message.
@@ -165,7 +140,7 @@ public SignerInformationStore GetSignerInfos()
{
if (signerInfoStore == null)
{
- IList signerInfos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var signerInfos = new List();
Asn1Set s = signedData.SignerInfos;
foreach (object obj in s)
@@ -173,16 +148,18 @@ public SignerInformationStore GetSignerInfos()
SignerInfo info = SignerInfo.GetInstance(obj);
DerObjectIdentifier contentType = signedData.EncapContentInfo.ContentType;
- if (hashes == null)
+ if (m_hashes == null)
{
signerInfos.Add(new SignerInformation(info, contentType, signedContent, null));
}
- else
+ else if (m_hashes.TryGetValue(info.DigestAlgorithm.Algorithm.Id, out var hash))
{
- byte[] hash = (byte[])hashes[info.DigestAlgorithm.Algorithm.Id];
-
signerInfos.Add(new SignerInformation(info, contentType, null, new BaseDigestCalculator(hash)));
}
+ else
+ {
+ throw new InvalidOperationException();
+ }
}
signerInfoStore = new SignerInformationStore(signerInfos);
@@ -200,61 +177,38 @@ public SignerInformationStore GetSignerInfos()
* @exception NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetAttributeCertificates(
- string type)
+ public IStore GetAttributeCertificates()
{
- if (attrCertStore == null)
- {
- attrCertStore = Helper.CreateAttributeStore(type, signedData.Certificates);
- }
-
- return attrCertStore;
+ return Helper.GetAttributeCertificates(signedData.Certificates);
}
/**
- * return a X509Store containing the public key certificates, if any, contained
- * in this message.
+ * return a X509Store containing the public key certificates, if any, contained in this message.
*
- * @param type type of store to create
* @return a store of public key certificates
* @exception NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetCertificates(
- string type)
+ public IStore GetCertificates()
{
- if (certificateStore == null)
- {
- certificateStore = Helper.CreateCertificateStore(type, signedData.Certificates);
- }
-
- return certificateStore;
+ return Helper.GetCertificates(signedData.Certificates);
}
/**
- * return a X509Store containing CRLs, if any, contained
- * in this message.
+ * return a X509Store containing CRLs, if any, contained in this message.
*
- * @param type type of store to create
* @return a store of CRLs
* @exception NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetCrls(
- string type)
+ public IStore GetCrls()
{
- if (crlStore == null)
- {
- crlStore = Helper.CreateCrlStore(type, signedData.CRLs);
- }
-
- return crlStore;
+ return Helper.GetCrls(signedData.CRLs);
}
-
- public string SignedContentTypeOid
+ public IStore GetOtherRevInfos(DerObjectIdentifier otherRevInfoFormat)
{
- get { return signedData.EncapContentInfo.ContentType.Id; }
+ return Helper.GetOtherRevInfos(signedData.CRLs, otherRevInfoFormat);
}
///
@@ -361,7 +315,7 @@ public static CmsSignedData ReplaceSigners(
return cms;
}
- /**
+ /**
* Replace the certificate and CRL information associated with this
* CmsSignedData object with the new one passed in.
*
@@ -371,54 +325,71 @@ public static CmsSignedData ReplaceSigners(
* @return a new signed data object.
* @exception CmsException if there is an error processing the stores
*/
- public static CmsSignedData ReplaceCertificatesAndCrls(
- CmsSignedData signedData,
- IX509Store x509Certs,
- IX509Store x509Crls,
- IX509Store x509AttrCerts)
+ public static CmsSignedData ReplaceCertificatesAndCrls(CmsSignedData signedData,
+ IStore x509Certs, IStore x509Crls)
+ {
+ return ReplaceCertificatesAndRevocations(signedData, x509Certs, x509Crls, null, null);
+ }
+
+ public static CmsSignedData ReplaceCertificatesAndCrls(CmsSignedData signedData,
+ IStore x509Certs, IStore x509Crls,
+ IStore x509AttrCerts)
{
- if (x509AttrCerts != null)
- throw BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateNotImplementedException("Currently can't replace attribute certificates");
+ return ReplaceCertificatesAndRevocations(signedData, x509Certs, x509Crls, x509AttrCerts, null);
+ }
- //
- // copy
- //
- CmsSignedData cms = new CmsSignedData(signedData);
+ public static CmsSignedData ReplaceCertificatesAndRevocations(CmsSignedData signedData,
+ IStore x509Certs, IStore x509Crls,
+ IStore x509AttrCerts, IStore otherRevocationInfos)
+ {
+ //
+ // copy
+ //
+ CmsSignedData cms = new CmsSignedData(signedData);
//
// replace the certs and crls in the SignedData object
//
- Asn1Set certs = null;
- try
+ Asn1Set certSet = null;
+ Asn1Set revocationSet = null;
+
+ if (x509Certs != null || x509AttrCerts != null)
{
- Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
- CmsUtilities.GetCertificatesFromStore(x509Certs));
+ var certificates = new List();
+ if (x509Certs != null)
+ {
+ certificates.AddRange(CmsUtilities.GetCertificatesFromStore(x509Certs));
+ }
+ if (x509AttrCerts != null)
+ {
+ certificates.AddRange(CmsUtilities.GetAttributeCertificatesFromStore(x509AttrCerts));
+ }
- if (asn1Set.Count != 0)
+ Asn1Set berSet = CmsUtilities.CreateBerSetFromList(certificates);
+ if (berSet.Count > 0)
{
- certs = asn1Set;
+ certSet = berSet;
}
}
- catch (X509StoreException e)
- {
- throw new CmsException("error getting certificates from store", e);
- }
- Asn1Set crls = null;
- try
+ if (x509Crls != null || otherRevocationInfos != null)
{
- Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
- CmsUtilities.GetCrlsFromStore(x509Crls));
+ var revocations = new List();
+ if (x509Crls != null)
+ {
+ revocations.AddRange(CmsUtilities.GetCrlsFromStore(x509Crls));
+ }
+ if (otherRevocationInfos != null)
+ {
+ revocations.AddRange(CmsUtilities.GetOtherRevocationInfosFromStore(otherRevocationInfos));
+ }
- if (asn1Set.Count != 0)
+ Asn1Set berSet = CmsUtilities.CreateBerSetFromList(revocations);
+ if (berSet.Count > 0)
{
- crls = asn1Set;
+ revocationSet = berSet;
}
}
- catch (X509StoreException e)
- {
- throw new CmsException("error getting CRLs from store", e);
- }
//
// replace the CMS structure.
@@ -427,8 +398,8 @@ public static CmsSignedData ReplaceCertificatesAndCrls(
cms.signedData = new SignedData(
old.DigestAlgorithms,
old.EncapContentInfo,
- certs,
- crls,
+ certSet,
+ revocationSet,
old.SignerInfos);
//
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataGenerator.cs
index e0082e6..a9dbdaa 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataGenerator.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -40,13 +40,13 @@ public class CmsSignedDataGenerator
{
private static readonly CmsSignedHelper Helper = CmsSignedHelper.Instance;
- private readonly IList signerInfs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ private readonly IList signerInfs = new List();
private class SignerInf
{
private readonly CmsSignedGenerator outer;
- private readonly ISignatureFactory sigCalc;
+ private readonly ISignatureFactory sigCalc;
private readonly SignerIdentifier signerIdentifier;
private readonly string digestOID;
private readonly string encOID;
@@ -57,6 +57,7 @@ private class SignerInf
internal SignerInf(
CmsSignedGenerator outer,
AsymmetricKeyParameter key,
+ SecureRandom random,
SignerIdentifier signerIdentifier,
string digestOID,
string encOID,
@@ -69,7 +70,7 @@ internal SignerInf(
string signatureName = digestName + "with" + Helper.GetEncryptionAlgName(encOID);
this.outer = outer;
- this.sigCalc = new Asn1SignatureFactory(signatureName, key);
+ this.sigCalc = new Asn1SignatureFactory(signatureName, key, random);
this.signerIdentifier = signerIdentifier;
this.digestOID = digestOID;
this.encOID = encOID;
@@ -89,7 +90,8 @@ internal SignerInf(
this.outer = outer;
this.sigCalc = sigCalc;
this.signerIdentifier = signerIdentifier;
- this.digestOID = new DefaultDigestAlgorithmIdentifierFinder().find((AlgorithmIdentifier)sigCalc.AlgorithmDetails).Algorithm.Id;
+ this.digestOID = new DefaultDigestAlgorithmIdentifierFinder().Find(
+ (AlgorithmIdentifier)sigCalc.AlgorithmDetails).Algorithm.Id;
this.encOID = ((AlgorithmIdentifier)sigCalc.AlgorithmDetails).Algorithm.Id;
this.sAttr = sAttr;
this.unsAttr = unsAttr;
@@ -111,22 +113,14 @@ internal CmsAttributeTableGenerator UnsignedAttributes
get { return unsAttr; }
}
- internal SignerInfo ToSignerInfo(
- DerObjectIdentifier contentType,
- CmsProcessable content,
- SecureRandom random)
+ internal SignerInfo ToSignerInfo(DerObjectIdentifier contentType, CmsProcessable content)
{
AlgorithmIdentifier digAlgId = DigestAlgorithmID;
string digestName = Helper.GetDigestAlgName(digestOID);
string signatureName = digestName + "with" + Helper.GetEncryptionAlgName(encOID);
-
- byte[] hash;
- if (outer._digests.Contains(digestOID))
- {
- hash = (byte[])outer._digests[digestOID];
- }
- else
+
+ if (!outer.m_digests.TryGetValue(digestOID, out var hash))
{
IDigest dig = Helper.GetDigestInstance(digestName);
if (content != null)
@@ -134,55 +128,49 @@ internal SignerInfo ToSignerInfo(
content.Write(new DigestSink(dig));
}
hash = DigestUtilities.DoFinal(dig);
- outer._digests.Add(digestOID, hash.Clone());
+ outer.m_digests.Add(digestOID, (byte[])hash.Clone());
}
- IStreamCalculator calculator = sigCalc.CreateCalculator();
-
-#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE
- Stream sigStr = calculator.Stream;
-#else
- Stream sigStr = new BufferedStream(calculator.Stream);
-#endif
-
Asn1Set signedAttr = null;
- if (sAttr != null)
- {
- IDictionary parameters = outer.GetBaseParameters(contentType, digAlgId, hash);
-
-// Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(Collections.unmodifiableMap(parameters));
- Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(parameters);
- if (contentType == null) //counter signature
- {
- if (signed != null && signed[CmsAttributes.ContentType] != null)
- {
- IDictionary tmpSigned = signed.ToDictionary();
- tmpSigned.Remove(CmsAttributes.ContentType);
- signed = new Asn1.Cms.AttributeTable(tmpSigned);
- }
- }
-
- // TODO Validate proposed signed attributes
-
- signedAttr = outer.GetAttributeSet(signed);
-
- // sig must be composed from the DER encoding.
- signedAttr.EncodeTo(sigStr, Asn1Encodable.Der);
- }
- else if (content != null)
+ IStreamCalculator calculator = sigCalc.CreateCalculator();
+ using (Stream sigStr = calculator.Stream)
{
- // TODO Use raw signature of the hash value instead
- content.Write(sigStr);
- }
+ if (sAttr != null)
+ {
+ var parameters = outer.GetBaseParameters(contentType, digAlgId, hash);
+
+ //Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(Collections.unmodifiableMap(parameters));
+ Asn1.Cms.AttributeTable signed = sAttr.GetAttributes(parameters);
+
+ if (contentType == null) //counter signature
+ {
+ if (signed != null && signed[CmsAttributes.ContentType] != null)
+ {
+ signed = signed.Remove(CmsAttributes.ContentType);
+ }
+ }
+
+ // TODO Validate proposed signed attributes
+
+ signedAttr = outer.GetAttributeSet(signed);
+
+ // sig must be composed from the DER encoding.
+ signedAttr.EncodeTo(sigStr, Asn1Encodable.Der);
+ }
+ else if (content != null)
+ {
+ // TODO Use raw signature of the hash value instead
+ content.Write(sigStr);
+ }
+ }
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(sigStr);
- byte[] sigBytes = ((IBlockResult)calculator.GetResult()).Collect();
+ byte[] sigBytes = calculator.GetResult().Collect();
Asn1Set unsignedAttr = null;
if (unsAttr != null)
{
- IDictionary baseParameters = outer.GetBaseParameters(contentType, digAlgId, hash);
+ var baseParameters = outer.GetBaseParameters(contentType, digAlgId, hash);
baseParameters[CmsAttributeTableParameter.Signature] = sigBytes.Clone();
// Asn1.Cms.AttributeTable unsigned = unsAttr.GetAttributes(Collections.unmodifiableMap(baseParameters));
@@ -208,10 +196,9 @@ public CmsSignedDataGenerator()
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- public CmsSignedDataGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Instance of SecureRandom to use.
+ public CmsSignedDataGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -437,7 +424,7 @@ private void doAddSigner(
CmsAttributeTableGenerator unsignedAttrGen,
Asn1.Cms.AttributeTable baseSignedTable)
{
- signerInfs.Add(new SignerInf(this, privateKey, signerIdentifier, digestOID, encryptionOID,
+ signerInfs.Add(new SignerInf(this, privateKey, m_random, signerIdentifier, digestOID, encryptionOID,
signedAttrGen, unsignedAttrGen, baseSignedTable));
}
@@ -465,7 +452,7 @@ public CmsSignedData Generate(
Asn1EncodableVector digestAlgs = new Asn1EncodableVector();
Asn1EncodableVector signerInfos = new Asn1EncodableVector();
- _digests.Clear(); // clear the current preserved digest state
+ m_digests.Clear(); // clear the current preserved digest state
//
// add the precalculated SignerInfo objects.
@@ -492,7 +479,7 @@ public CmsSignedData Generate(
try
{
digestAlgs.Add(signer.DigestAlgorithmID);
- signerInfos.Add(signer.ToSignerInfo(contentTypeOid, content, rand));
+ signerInfos.Add(signer.ToSignerInfo(contentTypeOid, content));
}
catch (IOException e)
{
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataParser.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataParser.cs
index 2087897..9f0febf 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataParser.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataParser.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -10,12 +10,10 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -65,15 +63,12 @@ public class CmsSignedDataParser
private SignedDataParser _signedData;
private DerObjectIdentifier _signedContentType;
private CmsTypedStream _signedContent;
- private IDictionary _digests;
- private ISet _digestOids;
+ private IDictionary m_digests;
+ private HashSet _digestOids;
private SignerInformationStore _signerInfoStore;
private Asn1Set _certSet, _crlSet;
private bool _isCertCrlParsed;
- private IX509Store _attributeStore;
- private IX509Store _certificateStore;
- private IX509Store _crlStore;
public CmsSignedDataParser(
byte[] sigBlock)
@@ -112,8 +107,8 @@ public CmsSignedDataParser(
{
this._signedContent = signedContent;
this._signedData = SignedDataParser.GetInstance(this.contentInfo.GetContent(Asn1Tags.Sequence));
- this._digests = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- this._digestOids = new HashSet();
+ this.m_digests = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ this._digestOids = new HashSet();
Asn1SetParser digAlgs = _signedData.GetDigestAlgorithms();
IAsn1Convertible o;
@@ -127,9 +122,9 @@ public CmsSignedDataParser(
string digestOid = id.Algorithm.Id;
string digestName = Helper.GetDigestAlgName(digestOid);
- if (!this._digests.Contains(digestName))
+ if (!this.m_digests.ContainsKey(digestName))
{
- this._digests[digestName] = Helper.GetDigestInstance(digestName);
+ this.m_digests[digestName] = Helper.GetDigestInstance(digestName);
this._digestOids.Add(digestOid);
}
}
@@ -184,9 +179,9 @@ public int Version
get { return _signedData.Version.IntValueExact; }
}
- public ISet DigestOids
+ public ISet DigestOids
{
- get { return new HashSet(_digestOids); }
+ get { return new HashSet(_digestOids); }
}
/**
@@ -200,13 +195,12 @@ public SignerInformationStore GetSignerInfos()
{
PopulateCertCrlSets();
- IList signerInfos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- IDictionary hashes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ var signerInfos = new List();
+ var hashes = new Dictionary(StringComparer.OrdinalIgnoreCase);
- foreach (object digestKey in _digests.Keys)
+ foreach (var digest in m_digests)
{
- hashes[digestKey] = DigestUtilities.DoFinal(
- (IDigest)_digests[digestKey]);
+ hashes[digest.Key] = DigestUtilities.DoFinal(digest.Value);
}
try
@@ -217,10 +211,9 @@ public SignerInformationStore GetSignerInfos()
while ((o = s.ReadObject()) != null)
{
SignerInfo info = SignerInfo.GetInstance(o.ToAsn1Object());
- string digestName = Helper.GetDigestAlgName(
- info.DigestAlgorithm.Algorithm.Id);
+ string digestName = Helper.GetDigestAlgName(info.DigestAlgorithm.Algorithm.Id);
- byte[] hash = (byte[]) hashes[digestName];
+ byte[] hash = hashes[digestName];
signerInfos.Add(new SignerInformation(info, _signedContentType, null, new BaseDigestCalculator(hash)));
}
@@ -245,17 +238,11 @@ public SignerInformationStore GetSignerInfos()
* @exception org.bouncycastle.x509.NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetAttributeCertificates(
- string type)
+ public IStore GetAttributeCertificates()
{
- if (_attributeStore == null)
- {
- PopulateCertCrlSets();
+ PopulateCertCrlSets();
- _attributeStore = Helper.CreateAttributeStore(type, _certSet);
- }
-
- return _attributeStore;
+ return Helper.GetAttributeCertificates(_certSet);
}
/**
@@ -267,17 +254,11 @@ public IX509Store GetAttributeCertificates(
* @exception NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetCertificates(
- string type)
+ public IStore GetCertificates()
{
- if (_certificateStore == null)
- {
- PopulateCertCrlSets();
-
- _certificateStore = Helper.CreateCertificateStore(type, _certSet);
- }
+ PopulateCertCrlSets();
- return _certificateStore;
+ return Helper.GetCertificates(_certSet);
}
/**
@@ -289,20 +270,21 @@ public IX509Store GetCertificates(
* @exception NoSuchStoreException if the store type isn't available.
* @exception CmsException if a general exception prevents creation of the X509Store
*/
- public IX509Store GetCrls(
- string type)
+ public IStore GetCrls()
{
- if (_crlStore == null)
- {
- PopulateCertCrlSets();
-
- _crlStore = Helper.CreateCrlStore(type, _crlSet);
- }
+ PopulateCertCrlSets();
- return _crlStore;
+ return Helper.GetCrls(_crlSet);
}
- private void PopulateCertCrlSets()
+ public IStore GetOtherRevInfos(DerObjectIdentifier otherRevInfoFormat)
+ {
+ PopulateCertCrlSets();
+
+ return Helper.GetOtherRevInfos(_crlSet, otherRevInfoFormat);
+ }
+
+ private void PopulateCertCrlSets()
{
if (_isCertCrlParsed)
return;
@@ -339,7 +321,7 @@ public CmsTypedStream GetSignedContent()
Stream digStream = _signedContent.ContentStream;
- foreach (IDigest digest in _digests.Values)
+ foreach (var digest in m_digests.Values)
{
digStream = new DigestStream(digStream, digest, null);
}
@@ -380,13 +362,13 @@ public static Stream ReplaceSigners(
Streams.PipeAll(signedContent.ContentStream, contentOut);
}
- gen.AddAttributeCertificates(parser.GetAttributeCertificates("Collection"));
- gen.AddCertificates(parser.GetCertificates("Collection"));
- gen.AddCrls(parser.GetCrls("Collection"));
+ gen.AddAttributeCertificates(parser.GetAttributeCertificates());
+ gen.AddCertificates(parser.GetCertificates());
+ gen.AddCrls(parser.GetCrls());
// gen.AddSigners(parser.GetSignerInfos());
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(contentOut);
+ contentOut.Dispose();
return outStr;
}
@@ -403,12 +385,8 @@ public static Stream ReplaceSigners(
* @return out.
* @exception CmsException if there is an error processing the CertStore
*/
- public static Stream ReplaceCertificatesAndCrls(
- Stream original,
- IX509Store x509Certs,
- IX509Store x509Crls,
- IX509Store x509AttrCerts,
- Stream outStr)
+ public static Stream ReplaceCertificatesAndCrls(Stream original, IStore x509Certs,
+ IStore x509Crls, IStore x509AttrCerts, Stream outStr)
{
// NB: SecureRandom would be ignored since using existing signatures only
CmsSignedDataStreamGenerator gen = new CmsSignedDataStreamGenerator();
@@ -424,19 +402,22 @@ public static Stream ReplaceCertificatesAndCrls(
Streams.PipeAll(signedContent.ContentStream, contentOut);
}
-// gen.AddAttributeCertificates(parser.GetAttributeCertificates("Collection"));
-// gen.AddCertificates(parser.GetCertificates("Collection"));
-// gen.AddCrls(parser.GetCrls("Collection"));
if (x509AttrCerts != null)
+ {
gen.AddAttributeCertificates(x509AttrCerts);
+ }
if (x509Certs != null)
+ {
gen.AddCertificates(x509Certs);
+ }
if (x509Crls != null)
+ {
gen.AddCrls(x509Crls);
+ }
gen.AddSigners(parser.GetSignerInfos());
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(contentOut);
+ contentOut.Dispose();
return outStr;
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataStreamGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataStreamGenerator.cs
index 5943f29..f538bff 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataStreamGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedDataStreamGenerator.cs
@@ -1,8 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-using System.Diagnostics;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -12,9 +11,7 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
@@ -45,19 +42,22 @@ public class CmsSignedDataStreamGenerator
{
private static readonly CmsSignedHelper Helper = CmsSignedHelper.Instance;
- private readonly IList _signerInfs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- private readonly ISet _messageDigestOids = new HashSet();
- private readonly IDictionary _messageDigests = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private readonly IDictionary _messageHashes = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private bool _messageDigestsLocked;
- private int _bufferSize;
+ private readonly IList _signerInfs =
+ new List();
+ private readonly HashSet _messageDigestOids = new HashSet();
+ private readonly IDictionary m_messageDigests =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private readonly IDictionary m_messageHashes =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private bool _messageDigestsLocked;
+ private int _bufferSize;
private class DigestAndSignerInfoGeneratorHolder
{
internal readonly ISignerInfoGenerator signerInf;
internal readonly string digestOID;
- internal DigestAndSignerInfoGeneratorHolder(ISignerInfoGenerator signerInf, String digestOID)
+ internal DigestAndSignerInfoGeneratorHolder(ISignerInfoGenerator signerInf, string digestOID)
{
this.signerInf = signerInf;
this.digestOID = digestOID;
@@ -139,7 +139,7 @@ internal SignerInfoGeneratorImpl(
}
}
- _sig.Init(true, new ParametersWithRandom(key, outer.rand));
+ _sig.Init(true, new ParametersWithRandom(key, outer.m_random));
}
public SignerInfo Generate(DerObjectIdentifier contentType, AlgorithmIdentifier digestAlgorithm,
@@ -169,7 +169,7 @@ public SignerInfo Generate(DerObjectIdentifier contentType, AlgorithmIdentifier
Asn1Set signedAttr = null;
if (_sAttr != null)
{
- IDictionary parameters = outer.GetBaseParameters(contentType, digestAlgorithm, calculatedDigest);
+ var parameters = outer.GetBaseParameters(contentType, digestAlgorithm, calculatedDigest);
// Asn1.Cms.AttributeTable signed = _sAttr.GetAttributes(Collections.unmodifiableMap(parameters));
Asn1.Cms.AttributeTable signed = _sAttr.GetAttributes(parameters);
@@ -178,9 +178,7 @@ public SignerInfo Generate(DerObjectIdentifier contentType, AlgorithmIdentifier
{
if (signed != null && signed[CmsAttributes.ContentType] != null)
{
- IDictionary tmpSigned = signed.ToDictionary();
- tmpSigned.Remove(CmsAttributes.ContentType);
- signed = new Asn1.Cms.AttributeTable(tmpSigned);
+ signed = signed.Remove(CmsAttributes.ContentType);
}
}
@@ -205,8 +203,7 @@ public SignerInfo Generate(DerObjectIdentifier contentType, AlgorithmIdentifier
Asn1Set unsignedAttr = null;
if (_unsAttr != null)
{
- IDictionary parameters = outer.GetBaseParameters(
- contentType, digestAlgorithm, calculatedDigest);
+ var parameters = outer.GetBaseParameters(contentType, digestAlgorithm, calculatedDigest);
parameters[CmsAttributeTableParameter.Signature] = sigBytes.Clone();
// Asn1.Cms.AttributeTable unsigned = _unsAttr.getAttributes(Collections.unmodifiableMap(parameters));
@@ -239,10 +236,9 @@ public CmsSignedDataStreamGenerator()
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- public CmsSignedDataStreamGenerator(
- SecureRandom rand)
- : base(rand)
+ /// Instance of SecureRandom to use.
+ public CmsSignedDataStreamGenerator(SecureRandom random)
+ : base(random)
{
}
@@ -251,20 +247,20 @@ public CmsSignedDataStreamGenerator(
*
* @param bufferSize length of octet strings to buffer the data.
*/
- public void SetBufferSize(
- int bufferSize)
+ public void SetBufferSize(int bufferSize)
{
_bufferSize = bufferSize;
}
- public void AddDigests(
- params string[] digestOids)
+ public void AddDigests(params string[] digestOids)
{
- AddDigests((IEnumerable) digestOids);
+ foreach (string digestOid in digestOids)
+ {
+ ConfigureDigest(digestOid);
+ }
}
- public void AddDigests(
- IEnumerable digestOids)
+ public void AddDigests(IEnumerable digestOids)
{
foreach (string digestOid in digestOids)
{
@@ -568,14 +564,10 @@ public Stream Open(
foreach (string digestOid in _messageDigestOids)
{
- digestAlgs.Add(
- new AlgorithmIdentifier(new DerObjectIdentifier(digestOid), DerNull.Instance));
+ digestAlgs.Add(new AlgorithmIdentifier(new DerObjectIdentifier(digestOid), DerNull.Instance));
}
- {
- byte[] tmp = new DerSet(digestAlgs).GetEncoded();
- sigGen.GetRawOutputStream().Write(tmp, 0, tmp.Length);
- }
+ new DerSet(digestAlgs).EncodeTo(sigGen.GetRawOutputStream());
BerSequenceGenerator eiGen = new BerSequenceGenerator(sigGen.GetRawOutputStream());
eiGen.AddObject(contentTypeOid);
@@ -589,7 +581,7 @@ public Stream Open(
Stream teeStream = GetSafeTeeOutputStream(dataOutputStream, encapStream);
// Let all the digests see the data as it is written
- Stream digStream = AttachDigestsToOutputStream(_messageDigests.Values, teeStream);
+ Stream digStream = AttachDigestsToOutputStream(m_messageDigests.Values, teeStream);
return new CmsSignedDataOutputStream(this, digStream, signedContentType, sGen, sigGen, eiGen);
}
@@ -608,20 +600,18 @@ private void RegisterDigestOid(
}
}
- private void ConfigureDigest(
- string digestOid)
+ private void ConfigureDigest(string digestOid)
{
RegisterDigestOid(digestOid);
string digestName = Helper.GetDigestAlgName(digestOid);
- IDigest dig = (IDigest)_messageDigests[digestName];
- if (dig == null)
+
+ if (!m_messageDigests.ContainsKey(digestName))
{
if (_messageDigestsLocked)
throw new InvalidOperationException("Cannot configure new digests after the data stream is opened");
- dig = Helper.GetDigestInstance(digestName);
- _messageDigests[digestName] = dig;
+ m_messageDigests[digestName] = Helper.GetDigestInstance(digestName);
}
}
@@ -633,12 +623,13 @@ internal void Generate(
Stream dataOutputStream,
CmsProcessable content)
{
- Stream signedOut = Open(outStream, eContentType, encapsulate, dataOutputStream);
- if (content != null)
+ using (var signedOut = Open(outStream, eContentType, encapsulate, dataOutputStream))
{
- content.Write(signedOut);
- }
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(signedOut);
+ if (content != null)
+ {
+ content.Write(signedOut);
+ }
+ }
}
// RFC3852, section 5.1:
@@ -671,10 +662,8 @@ private DerInteger CalculateVersion(
{
foreach (object obj in _certs)
{
- if (obj is Asn1TaggedObject)
+ if (obj is Asn1TaggedObject tagged)
{
- Asn1TaggedObject tagged = (Asn1TaggedObject) obj;
-
if (tagged.TagNo == 1)
{
attrCertV1Found = true;
@@ -727,23 +716,20 @@ private DerInteger CalculateVersion(
return new DerInteger(1);
}
- private bool CheckForVersion3(
- IList signerInfos)
+ private bool CheckForVersion3(IList signerInfos)
{
foreach (SignerInformation si in signerInfos)
{
SignerInfo s = SignerInfo.GetInstance(si.ToSignerInfo());
if (s.Version.IntValueExact == 3)
- {
return true;
- }
}
return false;
}
- private static Stream AttachDigestsToOutputStream(ICollection digests, Stream s)
+ private static Stream AttachDigestsToOutputStream(IEnumerable digests, Stream s)
{
Stream result = s;
foreach (IDigest digest in digests)
@@ -755,9 +741,7 @@ private static Stream AttachDigestsToOutputStream(ICollection digests, Stream s)
private static Stream GetSafeOutputStream(Stream s)
{
- if (s == null)
- return new NullOutputStream();
- return s;
+ return s ?? Stream.Null;
}
private static Stream GetSafeTeeOutputStream(Stream s1, Stream s2)
@@ -797,21 +781,23 @@ public CmsSignedDataOutputStream(
_eiGen = eiGen;
}
- public override void WriteByte(
- byte b)
- {
- _out.WriteByte(b);
- }
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ _out.Write(buffer, offset, count);
+ }
- public override void Write(
- byte[] bytes,
- int off,
- int len)
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override void Write(ReadOnlySpan buffer)
{
- _out.Write(bytes, off, len);
+ _out.Write(buffer);
}
+#endif
+
+ public override void WriteByte(byte value)
+ {
+ _out.WriteByte(value);
+ }
-#if PORTABLE || NETFX_CORE
protected override void Dispose(bool disposing)
{
if (disposing)
@@ -820,23 +806,16 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}
-#else
- public override void Close()
- {
- DoClose();
- base.Close();
- }
-#endif
private void DoClose()
{
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_out);
+ _out.Dispose();
// TODO Parent context(s) should really be be closed explicitly
_eiGen.Close();
- outer._digests.Clear(); // clear the current preserved digest state
+ outer.m_digests.Clear(); // clear the current preserved digest state
if (outer._certs.Count > 0)
{
@@ -844,8 +823,8 @@ private void DoClose()
? CmsUtilities.CreateDerSetFromList(outer._certs)
: CmsUtilities.CreateBerSetFromList(outer._certs);
- WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs));
- }
+ WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs));
+ }
if (outer._crls.Count > 0)
{
@@ -853,48 +832,48 @@ private void DoClose()
? CmsUtilities.CreateDerSetFromList(outer._crls)
: CmsUtilities.CreateBerSetFromList(outer._crls);
- WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls));
- }
+ WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls));
+ }
- //
- // Calculate the digest hashes
- //
- foreach (DictionaryEntry de in outer._messageDigests)
- {
- outer._messageHashes.Add(de.Key, DigestUtilities.DoFinal((IDigest)de.Value));
- }
+ //
+ // Calculate the digest hashes
+ //
+ foreach (var de in outer.m_messageDigests)
+ {
+ outer.m_messageHashes.Add(de.Key, DigestUtilities.DoFinal(de.Value));
+ }
- // TODO If the digest OIDs for precalculated signers weren't mixed in with
- // the others, we could fill in outer._digests here, instead of SignerInfoGenerator.Generate
+ // TODO If the digest OIDs for precalculated signers weren't mixed in with
+ // the others, we could fill in outer._digests here, instead of SignerInfoGenerator.Generate
- //
- // collect all the SignerInfo objects
- //
+ //
+ // collect all the SignerInfo objects
+ //
Asn1EncodableVector signerInfos = new Asn1EncodableVector();
- //
+ //
// add the generated SignerInfo objects
//
- {
- foreach (DigestAndSignerInfoGeneratorHolder holder in outer._signerInfs)
- {
- AlgorithmIdentifier digestAlgorithm = holder.DigestAlgorithm;
+ {
+ foreach (DigestAndSignerInfoGeneratorHolder holder in outer._signerInfs)
+ {
+ AlgorithmIdentifier digestAlgorithm = holder.DigestAlgorithm;
- byte[] calculatedDigest = (byte[])outer._messageHashes[
- Helper.GetDigestAlgName(holder.digestOID)];
- outer._digests[holder.digestOID] = calculatedDigest.Clone();
+ byte[] calculatedDigest = outer.m_messageHashes[
+ Helper.GetDigestAlgName(holder.digestOID)];
+ outer.m_digests[holder.digestOID] = (byte[])calculatedDigest.Clone();
- signerInfos.Add(holder.signerInf.Generate(_contentOID, digestAlgorithm, calculatedDigest));
- }
- }
+ signerInfos.Add(holder.signerInf.Generate(_contentOID, digestAlgorithm, calculatedDigest));
+ }
+ }
- //
+ //
// add the precalculated SignerInfo objects.
//
- {
- foreach (SignerInformation signer in outer._signers)
- {
- // TODO Verify the content type and calculated digest match the precalculated SignerInfo
+ {
+ foreach (SignerInformation signer in outer._signers)
+ {
+ // TODO Verify the content type and calculated digest match the precalculated SignerInfo
// if (!signer.ContentType.Equals(_contentOID))
// {
// // TODO The precalculated content type did not match - error?
@@ -913,22 +892,19 @@ private void DoClose()
// }
// }
- signerInfos.Add(signer.ToSignerInfo());
- }
- }
+ signerInfos.Add(signer.ToSignerInfo());
+ }
+ }
- WriteToGenerator(_sigGen, new DerSet(signerInfos));
+ WriteToGenerator(_sigGen, new DerSet(signerInfos));
_sigGen.Close();
_sGen.Close();
}
- private static void WriteToGenerator(
- Asn1Generator ag,
- Asn1Encodable ae)
+ private static void WriteToGenerator(Asn1Generator ag, Asn1Encodable ae)
{
- byte[] encoded = ae.GetEncoded();
- ag.GetRawOutputStream().Write(encoded, 0, encoded.Length);
+ ae.EncodeTo(ag.GetRawOutputStream());
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedGenerator.cs
index 93bd789..b55b948 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedGenerator.cs
@@ -1,8 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-using System.IO;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.BC;
@@ -19,344 +18,336 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
public class DefaultSignatureAlgorithmIdentifierFinder
{
- private static readonly IDictionary algorithms = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly ISet noParams = new HashSet();
- private static readonly IDictionary _params = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly ISet pkcs15RsaEncryption = new HashSet();
- private static readonly IDictionary digestOids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- private static readonly IDictionary digestBuilders = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
-
- private static readonly DerObjectIdentifier ENCRYPTION_RSA = PkcsObjectIdentifiers.RsaEncryption;
- private static readonly DerObjectIdentifier ENCRYPTION_DSA = X9ObjectIdentifiers.IdDsaWithSha1;
- private static readonly DerObjectIdentifier ENCRYPTION_ECDSA = X9ObjectIdentifiers.ECDsaWithSha1;
- private static readonly DerObjectIdentifier ENCRYPTION_RSA_PSS = PkcsObjectIdentifiers.IdRsassaPss;
- private static readonly DerObjectIdentifier ENCRYPTION_GOST3410 = CryptoProObjectIdentifiers.GostR3410x94;
- private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410 = CryptoProObjectIdentifiers.GostR3410x2001;
- private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410_2012_256 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256;
- private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410_2012_512 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512;
+ private static readonly IDictionary m_algorithms =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private static readonly HashSet noParams = new HashSet();
+ private static readonly IDictionary m_params =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private static readonly HashSet pkcs15RsaEncryption = new HashSet();
+ private static readonly IDictionary m_digestOids =
+ new Dictionary();
+
+ //private static readonly DerObjectIdentifier ENCRYPTION_RSA = PkcsObjectIdentifiers.RsaEncryption;
+ //private static readonly DerObjectIdentifier ENCRYPTION_DSA = X9ObjectIdentifiers.IdDsaWithSha1;
+ //private static readonly DerObjectIdentifier ENCRYPTION_ECDSA = X9ObjectIdentifiers.ECDsaWithSha1;
+ //private static readonly DerObjectIdentifier ENCRYPTION_RSA_PSS = PkcsObjectIdentifiers.IdRsassaPss;
+ //private static readonly DerObjectIdentifier ENCRYPTION_GOST3410 = CryptoProObjectIdentifiers.GostR3410x94;
+ //private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410 = CryptoProObjectIdentifiers.GostR3410x2001;
+ //private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410_2012_256 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256;
+ //private static readonly DerObjectIdentifier ENCRYPTION_ECGOST3410_2012_512 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512;
static DefaultSignatureAlgorithmIdentifierFinder()
{
- algorithms["MD2WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
- algorithms["MD2WITHRSA"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
- algorithms["MD5WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
- algorithms["MD5WITHRSA"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
- algorithms["SHA1WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
- algorithms["SHA-1WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
- algorithms["SHA1WITHRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
- algorithms["SHA-1WITHRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
- algorithms["SHA224WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
- algorithms["SHA-224WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
- algorithms["SHA224WITHRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
- algorithms["SHA-224WITHRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
- algorithms["SHA256WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
- algorithms["SHA-256WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
- algorithms["SHA256WITHRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
- algorithms["SHA-256WITHRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
- algorithms["SHA384WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
- algorithms["SHA-384WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
- algorithms["SHA384WITHRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
- algorithms["SHA-384WITHRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
- algorithms["SHA512WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
- algorithms["SHA-512WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
- algorithms["SHA512WITHRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
- algorithms["SHA-512WITHRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
- algorithms["SHA512(224)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
- algorithms["SHA-512(224)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
- algorithms["SHA512(224)WITHRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
- algorithms["SHA-512(224)WITHRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
- algorithms["SHA512(256)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
- algorithms["SHA-512(256)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
- algorithms["SHA512(256)WITHRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
- algorithms["SHA-512(256)WITHRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
- algorithms["SHA1WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA224WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA256WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA384WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA512WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA3-224WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA3-256WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA3-384WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["SHA3-512WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
- algorithms["RIPEMD160WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
- algorithms["RIPEMD160WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
- algorithms["RIPEMD128WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
- algorithms["RIPEMD128WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
- algorithms["RIPEMD256WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
- algorithms["RIPEMD256WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
- algorithms["SHA1WITHDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
- algorithms["SHA-1WITHDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
- algorithms["DSAWITHSHA1"] = X9ObjectIdentifiers.IdDsaWithSha1;
- algorithms["SHA224WITHDSA"] = NistObjectIdentifiers.DsaWithSha224;
- algorithms["SHA256WITHDSA"] = NistObjectIdentifiers.DsaWithSha256;
- algorithms["SHA384WITHDSA"] = NistObjectIdentifiers.DsaWithSha384;
- algorithms["SHA512WITHDSA"] = NistObjectIdentifiers.DsaWithSha512;
- algorithms["SHA3-224WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_224;
- algorithms["SHA3-256WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_256;
- algorithms["SHA3-384WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_384;
- algorithms["SHA3-512WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_512;
- algorithms["SHA3-224WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_224;
- algorithms["SHA3-256WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_256;
- algorithms["SHA3-384WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_384;
- algorithms["SHA3-512WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_512;
- algorithms["SHA3-224WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
- algorithms["SHA3-256WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
- algorithms["SHA3-384WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
- algorithms["SHA3-512WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
- algorithms["SHA3-224WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
- algorithms["SHA3-256WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
- algorithms["SHA3-384WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
- algorithms["SHA3-512WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
- algorithms["SHA1WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha1;
- algorithms["ECDSAWITHSHA1"] = X9ObjectIdentifiers.ECDsaWithSha1;
- algorithms["SHA224WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha224;
- algorithms["SHA256WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha256;
- algorithms["SHA384WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha384;
- algorithms["SHA512WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha512;
-
-
- algorithms["GOST3411WITHGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
- algorithms["GOST3411WITHGOST3410-94"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
- algorithms["GOST3411WITHECGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
- algorithms["GOST3411WITHECGOST3410-2001"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
- algorithms["GOST3411WITHGOST3410-2001"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
- algorithms["GOST3411WITHECGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
- algorithms["GOST3411WITHECGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
- algorithms["GOST3411WITHGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
- algorithms["GOST3411WITHGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
- algorithms["GOST3411-2012-256WITHECGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
- algorithms["GOST3411-2012-512WITHECGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
- algorithms["GOST3411-2012-256WITHGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
- algorithms["GOST3411-2012-512WITHGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
- algorithms["SHA1WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA1;
- algorithms["SHA224WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA224;
- algorithms["SHA256WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA256;
- algorithms["SHA384WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA384;
- algorithms["SHA512WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA512;
- algorithms["RIPEMD160WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_RIPEMD160;
- algorithms["SHA1WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_1;
- algorithms["SHA224WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_224;
- algorithms["SHA256WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_256;
- algorithms["SHA384WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_384;
- algorithms["SHA512WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_512;
- algorithms["SHA3-512WITHSPHINCS256"] = BCObjectIdentifiers.sphincs256_with_SHA3_512;
- algorithms["SHA512WITHSPHINCS256"] = BCObjectIdentifiers.sphincs256_with_SHA512;
-
- algorithms["SHA256WITHSM2"] = GMObjectIdentifiers.sm2sign_with_sha256;
- algorithms["SM3WITHSM2"] = GMObjectIdentifiers.sm2sign_with_sm3;
-
- algorithms["SHA256WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHA256;
- algorithms["SHA512WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHA512;
- algorithms["SHAKE128WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHAKE128;
- algorithms["SHAKE256WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHAKE256;
-
- algorithms["SHA256WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHA256;
- algorithms["SHA512WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHA512;
- algorithms["SHAKE128WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHAKE128;
- algorithms["SHAKE256WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHAKE256;
+ m_algorithms["MD2WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
+ m_algorithms["MD2WITHRSA"] = PkcsObjectIdentifiers.MD2WithRsaEncryption;
+ m_algorithms["MD5WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
+ m_algorithms["MD5WITHRSA"] = PkcsObjectIdentifiers.MD5WithRsaEncryption;
+ m_algorithms["SHA1WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
+ m_algorithms["SHA-1WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
+ m_algorithms["SHA1WITHRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
+ m_algorithms["SHA-1WITHRSA"] = PkcsObjectIdentifiers.Sha1WithRsaEncryption;
+ m_algorithms["SHA224WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
+ m_algorithms["SHA-224WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
+ m_algorithms["SHA224WITHRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
+ m_algorithms["SHA-224WITHRSA"] = PkcsObjectIdentifiers.Sha224WithRsaEncryption;
+ m_algorithms["SHA256WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
+ m_algorithms["SHA-256WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
+ m_algorithms["SHA256WITHRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
+ m_algorithms["SHA-256WITHRSA"] = PkcsObjectIdentifiers.Sha256WithRsaEncryption;
+ m_algorithms["SHA384WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
+ m_algorithms["SHA-384WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
+ m_algorithms["SHA384WITHRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
+ m_algorithms["SHA-384WITHRSA"] = PkcsObjectIdentifiers.Sha384WithRsaEncryption;
+ m_algorithms["SHA512WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
+ m_algorithms["SHA-512WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
+ m_algorithms["SHA512WITHRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
+ m_algorithms["SHA-512WITHRSA"] = PkcsObjectIdentifiers.Sha512WithRsaEncryption;
+ m_algorithms["SHA512(224)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
+ m_algorithms["SHA-512(224)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
+ m_algorithms["SHA512(224)WITHRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
+ m_algorithms["SHA-512(224)WITHRSA"] = PkcsObjectIdentifiers.Sha512_224WithRSAEncryption;
+ m_algorithms["SHA512(256)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
+ m_algorithms["SHA-512(256)WITHRSAENCRYPTION"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
+ m_algorithms["SHA512(256)WITHRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
+ m_algorithms["SHA-512(256)WITHRSA"] = PkcsObjectIdentifiers.Sha512_256WithRSAEncryption;
+ m_algorithms["SHA1WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA224WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA256WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA384WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA512WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA3-224WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA3-256WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA3-384WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["SHA3-512WITHRSAANDMGF1"] = PkcsObjectIdentifiers.IdRsassaPss;
+ m_algorithms["RIPEMD160WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
+ m_algorithms["RIPEMD160WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160;
+ m_algorithms["RIPEMD128WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
+ m_algorithms["RIPEMD128WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128;
+ m_algorithms["RIPEMD256WITHRSAENCRYPTION"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
+ m_algorithms["RIPEMD256WITHRSA"] = TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256;
+ m_algorithms["SHA1WITHDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
+ m_algorithms["SHA-1WITHDSA"] = X9ObjectIdentifiers.IdDsaWithSha1;
+ m_algorithms["DSAWITHSHA1"] = X9ObjectIdentifiers.IdDsaWithSha1;
+ m_algorithms["SHA224WITHDSA"] = NistObjectIdentifiers.DsaWithSha224;
+ m_algorithms["SHA256WITHDSA"] = NistObjectIdentifiers.DsaWithSha256;
+ m_algorithms["SHA384WITHDSA"] = NistObjectIdentifiers.DsaWithSha384;
+ m_algorithms["SHA512WITHDSA"] = NistObjectIdentifiers.DsaWithSha512;
+ m_algorithms["SHA3-224WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_224;
+ m_algorithms["SHA3-256WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_256;
+ m_algorithms["SHA3-384WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_384;
+ m_algorithms["SHA3-512WITHDSA"] = NistObjectIdentifiers.IdDsaWithSha3_512;
+ m_algorithms["SHA3-224WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_224;
+ m_algorithms["SHA3-256WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_256;
+ m_algorithms["SHA3-384WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_384;
+ m_algorithms["SHA3-512WITHECDSA"] = NistObjectIdentifiers.IdEcdsaWithSha3_512;
+ m_algorithms["SHA3-224WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
+ m_algorithms["SHA3-256WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
+ m_algorithms["SHA3-384WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
+ m_algorithms["SHA3-512WITHRSA"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
+ m_algorithms["SHA3-224WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224;
+ m_algorithms["SHA3-256WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256;
+ m_algorithms["SHA3-384WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384;
+ m_algorithms["SHA3-512WITHRSAENCRYPTION"] = NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512;
+ m_algorithms["SHA1WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha1;
+ m_algorithms["ECDSAWITHSHA1"] = X9ObjectIdentifiers.ECDsaWithSha1;
+ m_algorithms["SHA224WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha224;
+ m_algorithms["SHA256WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha256;
+ m_algorithms["SHA384WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha384;
+ m_algorithms["SHA512WITHECDSA"] = X9ObjectIdentifiers.ECDsaWithSha512;
+
+
+ m_algorithms["GOST3411WITHGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
+ m_algorithms["GOST3411WITHGOST3410-94"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94;
+ m_algorithms["GOST3411WITHECGOST3410"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
+ m_algorithms["GOST3411WITHECGOST3410-2001"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
+ m_algorithms["GOST3411WITHGOST3410-2001"] = CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001;
+ m_algorithms["GOST3411WITHECGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
+ m_algorithms["GOST3411WITHECGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
+ m_algorithms["GOST3411-2012-256WITHECGOST3410"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
+ m_algorithms["GOST3411-2012-256WITHECGOST3410-2012-256"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256;
+ m_algorithms["GOST3411-2012-512WITHECGOST3410"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
+ m_algorithms["GOST3411-2012-512WITHECGOST3410-2012-512"] = RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512;
+ m_algorithms["SHA1WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA1;
+ m_algorithms["SHA224WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA224;
+ m_algorithms["SHA256WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA256;
+ m_algorithms["SHA384WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA384;
+ m_algorithms["SHA512WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_SHA512;
+ m_algorithms["RIPEMD160WITHPLAIN-ECDSA"] = BsiObjectIdentifiers.ecdsa_plain_RIPEMD160;
+ m_algorithms["SHA1WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_1;
+ m_algorithms["SHA224WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_224;
+ m_algorithms["SHA256WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_256;
+ m_algorithms["SHA384WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_384;
+ m_algorithms["SHA512WITHCVC-ECDSA"] = EacObjectIdentifiers.id_TA_ECDSA_SHA_512;
+ m_algorithms["SHA3-512WITHSPHINCS256"] = BCObjectIdentifiers.sphincs256_with_SHA3_512;
+ m_algorithms["SHA512WITHSPHINCS256"] = BCObjectIdentifiers.sphincs256_with_SHA512;
+
+ m_algorithms["SHA256WITHSM2"] = GMObjectIdentifiers.sm2sign_with_sha256;
+ m_algorithms["SM3WITHSM2"] = GMObjectIdentifiers.sm2sign_with_sm3;
+
+ m_algorithms["SHA256WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHA256;
+ m_algorithms["SHA512WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHA512;
+ m_algorithms["SHAKE128WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHAKE128;
+ m_algorithms["SHAKE256WITHXMSS"] = BCObjectIdentifiers.xmss_with_SHAKE256;
+
+ m_algorithms["SHA256WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHA256;
+ m_algorithms["SHA512WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHA512;
+ m_algorithms["SHAKE128WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHAKE128;
+ m_algorithms["SHAKE256WITHXMSSMT"] = BCObjectIdentifiers.xmss_mt_with_SHAKE256;
//
// According to RFC 3279, the ASN.1 encoding SHALL (id-dsa-with-sha1) or MUST (ecdsa-with-SHA*) omit the parameters field.
// The parameters field SHALL be NULL for RSA based signature algorithms.
//
- noParams.Add((object)X9ObjectIdentifiers.ECDsaWithSha1);
- noParams.Add((object)X9ObjectIdentifiers.ECDsaWithSha224);
- noParams.Add((object)X9ObjectIdentifiers.ECDsaWithSha256);
- noParams.Add((object)X9ObjectIdentifiers.ECDsaWithSha384);
- noParams.Add((object)X9ObjectIdentifiers.ECDsaWithSha512);
- noParams.Add((object)X9ObjectIdentifiers.IdDsaWithSha1);
- noParams.Add((object)NistObjectIdentifiers.DsaWithSha224);
- noParams.Add((object)NistObjectIdentifiers.DsaWithSha256);
- noParams.Add((object)NistObjectIdentifiers.DsaWithSha384);
- noParams.Add((object)NistObjectIdentifiers.DsaWithSha512);
- noParams.Add((object)NistObjectIdentifiers.IdDsaWithSha3_224);
- noParams.Add((object)NistObjectIdentifiers.IdDsaWithSha3_256);
- noParams.Add((object)NistObjectIdentifiers.IdDsaWithSha3_384);
- noParams.Add((object)NistObjectIdentifiers.IdDsaWithSha3_512);
- noParams.Add((object)NistObjectIdentifiers.IdEcdsaWithSha3_224);
- noParams.Add((object)NistObjectIdentifiers.IdEcdsaWithSha3_256);
- noParams.Add((object)NistObjectIdentifiers.IdEcdsaWithSha3_384);
- noParams.Add((object)NistObjectIdentifiers.IdEcdsaWithSha3_512);
+ noParams.Add(X9ObjectIdentifiers.ECDsaWithSha1);
+ noParams.Add(X9ObjectIdentifiers.ECDsaWithSha224);
+ noParams.Add(X9ObjectIdentifiers.ECDsaWithSha256);
+ noParams.Add(X9ObjectIdentifiers.ECDsaWithSha384);
+ noParams.Add(X9ObjectIdentifiers.ECDsaWithSha512);
+ noParams.Add(X9ObjectIdentifiers.IdDsaWithSha1);
+ noParams.Add(NistObjectIdentifiers.DsaWithSha224);
+ noParams.Add(NistObjectIdentifiers.DsaWithSha256);
+ noParams.Add(NistObjectIdentifiers.DsaWithSha384);
+ noParams.Add(NistObjectIdentifiers.DsaWithSha512);
+ noParams.Add(NistObjectIdentifiers.IdDsaWithSha3_224);
+ noParams.Add(NistObjectIdentifiers.IdDsaWithSha3_256);
+ noParams.Add(NistObjectIdentifiers.IdDsaWithSha3_384);
+ noParams.Add(NistObjectIdentifiers.IdDsaWithSha3_512);
+ noParams.Add(NistObjectIdentifiers.IdEcdsaWithSha3_224);
+ noParams.Add(NistObjectIdentifiers.IdEcdsaWithSha3_256);
+ noParams.Add(NistObjectIdentifiers.IdEcdsaWithSha3_384);
+ noParams.Add(NistObjectIdentifiers.IdEcdsaWithSha3_512);
//
// RFC 4491
//
- noParams.Add((object)CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
- noParams.Add((object)CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
- noParams.Add((object)RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256);
- noParams.Add((object)RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512);
+ noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
+ noParams.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
+ noParams.Add(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256);
+ noParams.Add(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512);
//
// SPHINCS-256
//
- noParams.Add((object)BCObjectIdentifiers.sphincs256_with_SHA512);
- noParams.Add((object)BCObjectIdentifiers.sphincs256_with_SHA3_512);
+ noParams.Add(BCObjectIdentifiers.sphincs256_with_SHA512);
+ noParams.Add(BCObjectIdentifiers.sphincs256_with_SHA3_512);
//
// XMSS
//
- noParams.Add((object)BCObjectIdentifiers.xmss_with_SHA256);
- noParams.Add((object)BCObjectIdentifiers.xmss_with_SHA512);
- noParams.Add((object)BCObjectIdentifiers.xmss_with_SHAKE128);
- noParams.Add((object)BCObjectIdentifiers.xmss_with_SHAKE256);
- noParams.Add((object)BCObjectIdentifiers.xmss_mt_with_SHA256);
- noParams.Add((object)BCObjectIdentifiers.xmss_mt_with_SHA512);
- noParams.Add((object)BCObjectIdentifiers.xmss_mt_with_SHAKE128);
- noParams.Add((object)BCObjectIdentifiers.xmss_mt_with_SHAKE256);
+ noParams.Add(BCObjectIdentifiers.xmss_with_SHA256);
+ noParams.Add(BCObjectIdentifiers.xmss_with_SHA512);
+ noParams.Add(BCObjectIdentifiers.xmss_with_SHAKE128);
+ noParams.Add(BCObjectIdentifiers.xmss_with_SHAKE256);
+ noParams.Add(BCObjectIdentifiers.xmss_mt_with_SHA256);
+ noParams.Add(BCObjectIdentifiers.xmss_mt_with_SHA512);
+ noParams.Add(BCObjectIdentifiers.xmss_mt_with_SHAKE128);
+ noParams.Add(BCObjectIdentifiers.xmss_mt_with_SHAKE256);
//
// SM2
//
- noParams.Add((object)GMObjectIdentifiers.sm2sign_with_sha256);
- noParams.Add((object)GMObjectIdentifiers.sm2sign_with_sm3);
+ noParams.Add(GMObjectIdentifiers.sm2sign_with_sha256);
+ noParams.Add(GMObjectIdentifiers.sm2sign_with_sm3);
//
// PKCS 1.5 encrypted algorithms
//
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha1WithRsaEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha224WithRsaEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha256WithRsaEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha384WithRsaEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha512WithRsaEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
- pkcs15RsaEncryption.Add((object)PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
- pkcs15RsaEncryption.Add((object)TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
- pkcs15RsaEncryption.Add((object)TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
- pkcs15RsaEncryption.Add((object)TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
- pkcs15RsaEncryption.Add((object)NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224);
- pkcs15RsaEncryption.Add((object)NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256);
- pkcs15RsaEncryption.Add((object)NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384);
- pkcs15RsaEncryption.Add((object)NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha1WithRsaEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha224WithRsaEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha256WithRsaEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha384WithRsaEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha512WithRsaEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha512_224WithRSAEncryption);
+ pkcs15RsaEncryption.Add(PkcsObjectIdentifiers.Sha512_256WithRSAEncryption);
+ pkcs15RsaEncryption.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128);
+ pkcs15RsaEncryption.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160);
+ pkcs15RsaEncryption.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256);
+ pkcs15RsaEncryption.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224);
+ pkcs15RsaEncryption.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256);
+ pkcs15RsaEncryption.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384);
+ pkcs15RsaEncryption.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512);
//
// explicit params
//
AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1, DerNull.Instance);
- _params["SHA1WITHRSAANDMGF1"] = CreatePssParams(sha1AlgId, 20);
+ m_params["SHA1WITHRSAANDMGF1"] = CreatePssParams(sha1AlgId, 20);
AlgorithmIdentifier sha224AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha224, DerNull.Instance);
- _params["SHA224WITHRSAANDMGF1"] = CreatePssParams(sha224AlgId, 28);
+ m_params["SHA224WITHRSAANDMGF1"] = CreatePssParams(sha224AlgId, 28);
AlgorithmIdentifier sha256AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha256, DerNull.Instance);
- _params["SHA256WITHRSAANDMGF1"] = CreatePssParams(sha256AlgId, 32);
+ m_params["SHA256WITHRSAANDMGF1"] = CreatePssParams(sha256AlgId, 32);
AlgorithmIdentifier sha384AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha384, DerNull.Instance);
- _params["SHA384WITHRSAANDMGF1"] = CreatePssParams(sha384AlgId, 48);
+ m_params["SHA384WITHRSAANDMGF1"] = CreatePssParams(sha384AlgId, 48);
AlgorithmIdentifier sha512AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha512, DerNull.Instance);
- _params["SHA512WITHRSAANDMGF1"] = CreatePssParams(sha512AlgId, 64);
+ m_params["SHA512WITHRSAANDMGF1"] = CreatePssParams(sha512AlgId, 64);
AlgorithmIdentifier sha3_224AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha3_224, DerNull.Instance);
- _params["SHA3-224WITHRSAANDMGF1"] = CreatePssParams(sha3_224AlgId, 28);
+ m_params["SHA3-224WITHRSAANDMGF1"] = CreatePssParams(sha3_224AlgId, 28);
AlgorithmIdentifier sha3_256AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha3_256, DerNull.Instance);
- _params["SHA3-256WITHRSAANDMGF1"] = CreatePssParams(sha3_256AlgId, 32);
+ m_params["SHA3-256WITHRSAANDMGF1"] = CreatePssParams(sha3_256AlgId, 32);
AlgorithmIdentifier sha3_384AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha3_384, DerNull.Instance);
- _params["SHA3-384WITHRSAANDMGF1"] = CreatePssParams(sha3_384AlgId, 48);
+ m_params["SHA3-384WITHRSAANDMGF1"] = CreatePssParams(sha3_384AlgId, 48);
AlgorithmIdentifier sha3_512AlgId = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha3_512, DerNull.Instance);
- _params["SHA3-512WITHRSAANDMGF1"] = CreatePssParams(sha3_512AlgId, 64);
+ m_params["SHA3-512WITHRSAANDMGF1"] = CreatePssParams(sha3_512AlgId, 64);
//
// digests
//
- digestOids[PkcsObjectIdentifiers.Sha224WithRsaEncryption] = NistObjectIdentifiers.IdSha224;
- digestOids[PkcsObjectIdentifiers.Sha256WithRsaEncryption] = NistObjectIdentifiers.IdSha256;
- digestOids[PkcsObjectIdentifiers.Sha384WithRsaEncryption] = NistObjectIdentifiers.IdSha384;
- digestOids[PkcsObjectIdentifiers.Sha512WithRsaEncryption] = NistObjectIdentifiers.IdSha512;
- digestOids[PkcsObjectIdentifiers.Sha512_224WithRSAEncryption] = NistObjectIdentifiers.IdSha512_224;
- digestOids[PkcsObjectIdentifiers.Sha512_256WithRSAEncryption] = NistObjectIdentifiers.IdSha512_256;
- digestOids[NistObjectIdentifiers.DsaWithSha224] = NistObjectIdentifiers.IdSha224;
- digestOids[NistObjectIdentifiers.DsaWithSha256] = NistObjectIdentifiers.IdSha256;
- digestOids[NistObjectIdentifiers.DsaWithSha384] = NistObjectIdentifiers.IdSha384;
- digestOids[NistObjectIdentifiers.DsaWithSha512] = NistObjectIdentifiers.IdSha512;
- digestOids[NistObjectIdentifiers.IdDsaWithSha3_224] = NistObjectIdentifiers.IdSha3_224;
- digestOids[NistObjectIdentifiers.IdDsaWithSha3_256] = NistObjectIdentifiers.IdSha3_256;
- digestOids[NistObjectIdentifiers.IdDsaWithSha3_384] = NistObjectIdentifiers.IdSha3_384;
- digestOids[NistObjectIdentifiers.IdDsaWithSha3_512] = NistObjectIdentifiers.IdSha3_512;
- digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_224] = NistObjectIdentifiers.IdSha3_224;
- digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_256] = NistObjectIdentifiers.IdSha3_256;
- digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_384] = NistObjectIdentifiers.IdSha3_384;
- digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_512] = NistObjectIdentifiers.IdSha3_512;
- digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224] = NistObjectIdentifiers.IdSha3_224;
- digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256] = NistObjectIdentifiers.IdSha3_256;
- digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384] = NistObjectIdentifiers.IdSha3_384;
- digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512] = NistObjectIdentifiers.IdSha3_512;
-
- digestOids[PkcsObjectIdentifiers.MD2WithRsaEncryption] = PkcsObjectIdentifiers.MD2;
- digestOids[PkcsObjectIdentifiers.MD4WithRsaEncryption] = PkcsObjectIdentifiers.MD4;
- digestOids[PkcsObjectIdentifiers.MD5WithRsaEncryption] = PkcsObjectIdentifiers.MD5;
- digestOids[PkcsObjectIdentifiers.Sha1WithRsaEncryption] = OiwObjectIdentifiers.IdSha1;
- digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128] = TeleTrusTObjectIdentifiers.RipeMD128;
- digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160] = TeleTrusTObjectIdentifiers.RipeMD160;
- digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256] = TeleTrusTObjectIdentifiers.RipeMD256;
- digestOids[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94] = CryptoProObjectIdentifiers.GostR3411;
- digestOids[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001] = CryptoProObjectIdentifiers.GostR3411;
- digestOids[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256;
- digestOids[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512;
-
- digestOids[GMObjectIdentifiers.sm2sign_with_sha256] = NistObjectIdentifiers.IdSha256;
- digestOids[GMObjectIdentifiers.sm2sign_with_sm3] = GMObjectIdentifiers.sm3;
+ m_digestOids[PkcsObjectIdentifiers.Sha224WithRsaEncryption] = NistObjectIdentifiers.IdSha224;
+ m_digestOids[PkcsObjectIdentifiers.Sha256WithRsaEncryption] = NistObjectIdentifiers.IdSha256;
+ m_digestOids[PkcsObjectIdentifiers.Sha384WithRsaEncryption] = NistObjectIdentifiers.IdSha384;
+ m_digestOids[PkcsObjectIdentifiers.Sha512WithRsaEncryption] = NistObjectIdentifiers.IdSha512;
+ m_digestOids[PkcsObjectIdentifiers.Sha512_224WithRSAEncryption] = NistObjectIdentifiers.IdSha512_224;
+ m_digestOids[PkcsObjectIdentifiers.Sha512_256WithRSAEncryption] = NistObjectIdentifiers.IdSha512_256;
+ m_digestOids[NistObjectIdentifiers.DsaWithSha224] = NistObjectIdentifiers.IdSha224;
+ m_digestOids[NistObjectIdentifiers.DsaWithSha256] = NistObjectIdentifiers.IdSha256;
+ m_digestOids[NistObjectIdentifiers.DsaWithSha384] = NistObjectIdentifiers.IdSha384;
+ m_digestOids[NistObjectIdentifiers.DsaWithSha512] = NistObjectIdentifiers.IdSha512;
+ m_digestOids[NistObjectIdentifiers.IdDsaWithSha3_224] = NistObjectIdentifiers.IdSha3_224;
+ m_digestOids[NistObjectIdentifiers.IdDsaWithSha3_256] = NistObjectIdentifiers.IdSha3_256;
+ m_digestOids[NistObjectIdentifiers.IdDsaWithSha3_384] = NistObjectIdentifiers.IdSha3_384;
+ m_digestOids[NistObjectIdentifiers.IdDsaWithSha3_512] = NistObjectIdentifiers.IdSha3_512;
+ m_digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_224] = NistObjectIdentifiers.IdSha3_224;
+ m_digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_256] = NistObjectIdentifiers.IdSha3_256;
+ m_digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_384] = NistObjectIdentifiers.IdSha3_384;
+ m_digestOids[NistObjectIdentifiers.IdEcdsaWithSha3_512] = NistObjectIdentifiers.IdSha3_512;
+ m_digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224] = NistObjectIdentifiers.IdSha3_224;
+ m_digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256] = NistObjectIdentifiers.IdSha3_256;
+ m_digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384] = NistObjectIdentifiers.IdSha3_384;
+ m_digestOids[NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512] = NistObjectIdentifiers.IdSha3_512;
+
+ m_digestOids[PkcsObjectIdentifiers.MD2WithRsaEncryption] = PkcsObjectIdentifiers.MD2;
+ m_digestOids[PkcsObjectIdentifiers.MD4WithRsaEncryption] = PkcsObjectIdentifiers.MD4;
+ m_digestOids[PkcsObjectIdentifiers.MD5WithRsaEncryption] = PkcsObjectIdentifiers.MD5;
+ m_digestOids[PkcsObjectIdentifiers.Sha1WithRsaEncryption] = OiwObjectIdentifiers.IdSha1;
+ m_digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128] = TeleTrusTObjectIdentifiers.RipeMD128;
+ m_digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160] = TeleTrusTObjectIdentifiers.RipeMD160;
+ m_digestOids[TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256] = TeleTrusTObjectIdentifiers.RipeMD256;
+ m_digestOids[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94] = CryptoProObjectIdentifiers.GostR3411;
+ m_digestOids[CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001] = CryptoProObjectIdentifiers.GostR3411;
+ m_digestOids[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256;
+ m_digestOids[RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512] = RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512;
+
+ m_digestOids[GMObjectIdentifiers.sm2sign_with_sha256] = NistObjectIdentifiers.IdSha256;
+ m_digestOids[GMObjectIdentifiers.sm2sign_with_sm3] = GMObjectIdentifiers.sm3;
}
private static AlgorithmIdentifier Generate(string signatureAlgorithm)
{
AlgorithmIdentifier sigAlgId;
- AlgorithmIdentifier encAlgId;
- AlgorithmIdentifier digAlgId;
+ //AlgorithmIdentifier encAlgId;
+ //AlgorithmIdentifier digAlgId;
- string algorithmName = Strings.ToUpperCase(signatureAlgorithm);
- DerObjectIdentifier sigOID = (DerObjectIdentifier)algorithms[algorithmName];
- if (sigOID == null)
- {
- throw new ArgumentException("Unknown signature type requested: " + algorithmName);
- }
+ if (!m_algorithms.TryGetValue(signatureAlgorithm, out var sigOid))
+ throw new ArgumentException("Unknown signature type requested: " + signatureAlgorithm);
- if (noParams.Contains(sigOID))
- {
- sigAlgId = new AlgorithmIdentifier(sigOID);
- }
- else if (_params.Contains(algorithmName))
+ if (noParams.Contains(sigOid))
{
- sigAlgId = new AlgorithmIdentifier(sigOID, (Asn1Encodable)_params[algorithmName]);
+ sigAlgId = new AlgorithmIdentifier(sigOid);
}
- else
+ else if (m_params.TryGetValue(signatureAlgorithm, out var explicitParameters))
{
- sigAlgId = new AlgorithmIdentifier(sigOID, DerNull.Instance);
- }
-
- if (pkcs15RsaEncryption.Contains(sigOID))
- {
- encAlgId = new AlgorithmIdentifier(PkcsObjectIdentifiers.RsaEncryption, DerNull.Instance);
+ sigAlgId = new AlgorithmIdentifier(sigOid, explicitParameters);
}
else
{
- encAlgId = sigAlgId;
+ sigAlgId = new AlgorithmIdentifier(sigOid, DerNull.Instance);
}
- if (sigAlgId.Algorithm.Equals(PkcsObjectIdentifiers.IdRsassaPss))
- {
- digAlgId = ((RsassaPssParameters)sigAlgId.Parameters).HashAlgorithm;
- }
- else
- {
- digAlgId = new AlgorithmIdentifier((DerObjectIdentifier)digestOids[sigOID], DerNull.Instance);
- }
+ //if (pkcs15RsaEncryption.Contains(sigOid))
+ //{
+ // encAlgId = new AlgorithmIdentifier(PkcsObjectIdentifiers.RsaEncryption, DerNull.Instance);
+ //}
+ //else
+ //{
+ // encAlgId = sigAlgId;
+ //}
+
+ //if (sigAlgId.Algorithm.Equals(PkcsObjectIdentifiers.IdRsassaPss))
+ //{
+ // digAlgId = ((RsassaPssParameters)sigAlgId.Parameters).HashAlgorithm;
+ //}
+ //else
+ //{
+ // digAlgId = new AlgorithmIdentifier(m_digestOids[sigOid], DerNull.Instance);
+ //}
return sigAlgId;
}
@@ -378,96 +369,98 @@ public AlgorithmIdentifier Find(string sigAlgName)
public class DefaultDigestAlgorithmIdentifierFinder
{
- private static readonly IDictionary digestOids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary digestNameToOids = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private static readonly IDictionary m_digestOids =
+ new Dictionary();
+ private static readonly IDictionary m_digestNameToOids =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
static DefaultDigestAlgorithmIdentifierFinder()
{
//
// digests
//
- digestOids.Add(OiwObjectIdentifiers.MD4WithRsaEncryption, PkcsObjectIdentifiers.MD4);
- digestOids.Add(OiwObjectIdentifiers.MD4WithRsa, PkcsObjectIdentifiers.MD4);
- digestOids.Add(OiwObjectIdentifiers.MD5WithRsa, PkcsObjectIdentifiers.MD5);
- digestOids.Add(OiwObjectIdentifiers.Sha1WithRsa, OiwObjectIdentifiers.IdSha1);
- digestOids.Add(OiwObjectIdentifiers.DsaWithSha1, OiwObjectIdentifiers.IdSha1);
-
- digestOids.Add(PkcsObjectIdentifiers.Sha224WithRsaEncryption, NistObjectIdentifiers.IdSha224);
- digestOids.Add(PkcsObjectIdentifiers.Sha256WithRsaEncryption, NistObjectIdentifiers.IdSha256);
- digestOids.Add(PkcsObjectIdentifiers.Sha384WithRsaEncryption, NistObjectIdentifiers.IdSha384);
- digestOids.Add(PkcsObjectIdentifiers.Sha512WithRsaEncryption, NistObjectIdentifiers.IdSha512);
- digestOids.Add(PkcsObjectIdentifiers.Sha512_224WithRSAEncryption, NistObjectIdentifiers.IdSha512_224);
- digestOids.Add(PkcsObjectIdentifiers.Sha512_256WithRSAEncryption, NistObjectIdentifiers.IdSha512_256);
-
- digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224, NistObjectIdentifiers.IdSha3_224);
- digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256, NistObjectIdentifiers.IdSha3_256);
- digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384, NistObjectIdentifiers.IdSha3_384);
- digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512, NistObjectIdentifiers.IdSha3_512);
-
- digestOids.Add(PkcsObjectIdentifiers.MD2WithRsaEncryption, PkcsObjectIdentifiers.MD2);
- digestOids.Add(PkcsObjectIdentifiers.MD4WithRsaEncryption, PkcsObjectIdentifiers.MD4);
- digestOids.Add(PkcsObjectIdentifiers.MD5WithRsaEncryption, PkcsObjectIdentifiers.MD5);
- digestOids.Add(PkcsObjectIdentifiers.Sha1WithRsaEncryption, OiwObjectIdentifiers.IdSha1);
-
- digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha1, OiwObjectIdentifiers.IdSha1);
- digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha224, NistObjectIdentifiers.IdSha224);
- digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha256, NistObjectIdentifiers.IdSha256);
- digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha384, NistObjectIdentifiers.IdSha384);
- digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha512, NistObjectIdentifiers.IdSha512);
- digestOids.Add(X9ObjectIdentifiers.IdDsaWithSha1, OiwObjectIdentifiers.IdSha1);
-
- digestOids.Add(NistObjectIdentifiers.DsaWithSha224, NistObjectIdentifiers.IdSha224);
- digestOids.Add(NistObjectIdentifiers.DsaWithSha256, NistObjectIdentifiers.IdSha256);
- digestOids.Add(NistObjectIdentifiers.DsaWithSha384, NistObjectIdentifiers.IdSha384);
- digestOids.Add(NistObjectIdentifiers.DsaWithSha512, NistObjectIdentifiers.IdSha512);
-
- digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128, TeleTrusTObjectIdentifiers.RipeMD128);
- digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160, TeleTrusTObjectIdentifiers.RipeMD160);
- digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256, TeleTrusTObjectIdentifiers.RipeMD256);
-
- digestOids.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94, CryptoProObjectIdentifiers.GostR3411);
- digestOids.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001, CryptoProObjectIdentifiers.GostR3411);
-
- digestNameToOids.Add("SHA-1", OiwObjectIdentifiers.IdSha1);
- digestNameToOids.Add("SHA-224", NistObjectIdentifiers.IdSha224);
- digestNameToOids.Add("SHA-256", NistObjectIdentifiers.IdSha256);
- digestNameToOids.Add("SHA-384", NistObjectIdentifiers.IdSha384);
- digestNameToOids.Add("SHA-512", NistObjectIdentifiers.IdSha512);
- digestNameToOids.Add("SHA-512/224", NistObjectIdentifiers.IdSha512_224);
- digestNameToOids.Add("SHA-512(224)", NistObjectIdentifiers.IdSha512_224);
- digestNameToOids.Add("SHA-512/256", NistObjectIdentifiers.IdSha512_256);
- digestNameToOids.Add("SHA-512(256)", NistObjectIdentifiers.IdSha512_256);
-
- digestNameToOids.Add("SHA1", OiwObjectIdentifiers.IdSha1);
- digestNameToOids.Add("SHA224", NistObjectIdentifiers.IdSha224);
- digestNameToOids.Add("SHA256", NistObjectIdentifiers.IdSha256);
- digestNameToOids.Add("SHA384", NistObjectIdentifiers.IdSha384);
- digestNameToOids.Add("SHA512", NistObjectIdentifiers.IdSha512);
- digestNameToOids.Add("SHA512/224", NistObjectIdentifiers.IdSha512_224);
- digestNameToOids.Add("SHA512(224)", NistObjectIdentifiers.IdSha512_224);
- digestNameToOids.Add("SHA512/256", NistObjectIdentifiers.IdSha512_256);
- digestNameToOids.Add("SHA512(256)", NistObjectIdentifiers.IdSha512_256);
-
- digestNameToOids.Add("SHA3-224", NistObjectIdentifiers.IdSha3_224);
- digestNameToOids.Add("SHA3-256", NistObjectIdentifiers.IdSha3_256);
- digestNameToOids.Add("SHA3-384", NistObjectIdentifiers.IdSha3_384);
- digestNameToOids.Add("SHA3-512", NistObjectIdentifiers.IdSha3_512);
-
- digestNameToOids.Add("SHAKE-128", NistObjectIdentifiers.IdShake128);
- digestNameToOids.Add("SHAKE-256", NistObjectIdentifiers.IdShake256);
-
- digestNameToOids.Add("GOST3411", CryptoProObjectIdentifiers.GostR3411);
-
- digestNameToOids.Add("MD2", PkcsObjectIdentifiers.MD2);
- digestNameToOids.Add("MD4", PkcsObjectIdentifiers.MD4);
- digestNameToOids.Add("MD5", PkcsObjectIdentifiers.MD5);
-
- digestNameToOids.Add("RIPEMD128", TeleTrusTObjectIdentifiers.RipeMD128);
- digestNameToOids.Add("RIPEMD160", TeleTrusTObjectIdentifiers.RipeMD160);
- digestNameToOids.Add("RIPEMD256", TeleTrusTObjectIdentifiers.RipeMD256);
+ m_digestOids.Add(OiwObjectIdentifiers.MD4WithRsaEncryption, PkcsObjectIdentifiers.MD4);
+ m_digestOids.Add(OiwObjectIdentifiers.MD4WithRsa, PkcsObjectIdentifiers.MD4);
+ m_digestOids.Add(OiwObjectIdentifiers.MD5WithRsa, PkcsObjectIdentifiers.MD5);
+ m_digestOids.Add(OiwObjectIdentifiers.Sha1WithRsa, OiwObjectIdentifiers.IdSha1);
+ m_digestOids.Add(OiwObjectIdentifiers.DsaWithSha1, OiwObjectIdentifiers.IdSha1);
+
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha224WithRsaEncryption, NistObjectIdentifiers.IdSha224);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha256WithRsaEncryption, NistObjectIdentifiers.IdSha256);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha384WithRsaEncryption, NistObjectIdentifiers.IdSha384);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha512WithRsaEncryption, NistObjectIdentifiers.IdSha512);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha512_224WithRSAEncryption, NistObjectIdentifiers.IdSha512_224);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha512_256WithRSAEncryption, NistObjectIdentifiers.IdSha512_256);
+
+ m_digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_224, NistObjectIdentifiers.IdSha3_224);
+ m_digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_256, NistObjectIdentifiers.IdSha3_256);
+ m_digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_384, NistObjectIdentifiers.IdSha3_384);
+ m_digestOids.Add(NistObjectIdentifiers.IdRsassaPkcs1V15WithSha3_512, NistObjectIdentifiers.IdSha3_512);
+
+ m_digestOids.Add(PkcsObjectIdentifiers.MD2WithRsaEncryption, PkcsObjectIdentifiers.MD2);
+ m_digestOids.Add(PkcsObjectIdentifiers.MD4WithRsaEncryption, PkcsObjectIdentifiers.MD4);
+ m_digestOids.Add(PkcsObjectIdentifiers.MD5WithRsaEncryption, PkcsObjectIdentifiers.MD5);
+ m_digestOids.Add(PkcsObjectIdentifiers.Sha1WithRsaEncryption, OiwObjectIdentifiers.IdSha1);
+
+ m_digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha1, OiwObjectIdentifiers.IdSha1);
+ m_digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha224, NistObjectIdentifiers.IdSha224);
+ m_digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha256, NistObjectIdentifiers.IdSha256);
+ m_digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha384, NistObjectIdentifiers.IdSha384);
+ m_digestOids.Add(X9ObjectIdentifiers.ECDsaWithSha512, NistObjectIdentifiers.IdSha512);
+ m_digestOids.Add(X9ObjectIdentifiers.IdDsaWithSha1, OiwObjectIdentifiers.IdSha1);
+
+ m_digestOids.Add(NistObjectIdentifiers.DsaWithSha224, NistObjectIdentifiers.IdSha224);
+ m_digestOids.Add(NistObjectIdentifiers.DsaWithSha256, NistObjectIdentifiers.IdSha256);
+ m_digestOids.Add(NistObjectIdentifiers.DsaWithSha384, NistObjectIdentifiers.IdSha384);
+ m_digestOids.Add(NistObjectIdentifiers.DsaWithSha512, NistObjectIdentifiers.IdSha512);
+
+ m_digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128, TeleTrusTObjectIdentifiers.RipeMD128);
+ m_digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160, TeleTrusTObjectIdentifiers.RipeMD160);
+ m_digestOids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256, TeleTrusTObjectIdentifiers.RipeMD256);
+
+ m_digestOids.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94, CryptoProObjectIdentifiers.GostR3411);
+ m_digestOids.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001, CryptoProObjectIdentifiers.GostR3411);
+
+ m_digestNameToOids.Add("SHA-1", OiwObjectIdentifiers.IdSha1);
+ m_digestNameToOids.Add("SHA-224", NistObjectIdentifiers.IdSha224);
+ m_digestNameToOids.Add("SHA-256", NistObjectIdentifiers.IdSha256);
+ m_digestNameToOids.Add("SHA-384", NistObjectIdentifiers.IdSha384);
+ m_digestNameToOids.Add("SHA-512", NistObjectIdentifiers.IdSha512);
+ m_digestNameToOids.Add("SHA-512/224", NistObjectIdentifiers.IdSha512_224);
+ m_digestNameToOids.Add("SHA-512(224)", NistObjectIdentifiers.IdSha512_224);
+ m_digestNameToOids.Add("SHA-512/256", NistObjectIdentifiers.IdSha512_256);
+ m_digestNameToOids.Add("SHA-512(256)", NistObjectIdentifiers.IdSha512_256);
+
+ m_digestNameToOids.Add("SHA1", OiwObjectIdentifiers.IdSha1);
+ m_digestNameToOids.Add("SHA224", NistObjectIdentifiers.IdSha224);
+ m_digestNameToOids.Add("SHA256", NistObjectIdentifiers.IdSha256);
+ m_digestNameToOids.Add("SHA384", NistObjectIdentifiers.IdSha384);
+ m_digestNameToOids.Add("SHA512", NistObjectIdentifiers.IdSha512);
+ m_digestNameToOids.Add("SHA512/224", NistObjectIdentifiers.IdSha512_224);
+ m_digestNameToOids.Add("SHA512(224)", NistObjectIdentifiers.IdSha512_224);
+ m_digestNameToOids.Add("SHA512/256", NistObjectIdentifiers.IdSha512_256);
+ m_digestNameToOids.Add("SHA512(256)", NistObjectIdentifiers.IdSha512_256);
+
+ m_digestNameToOids.Add("SHA3-224", NistObjectIdentifiers.IdSha3_224);
+ m_digestNameToOids.Add("SHA3-256", NistObjectIdentifiers.IdSha3_256);
+ m_digestNameToOids.Add("SHA3-384", NistObjectIdentifiers.IdSha3_384);
+ m_digestNameToOids.Add("SHA3-512", NistObjectIdentifiers.IdSha3_512);
+
+ m_digestNameToOids.Add("SHAKE-128", NistObjectIdentifiers.IdShake128);
+ m_digestNameToOids.Add("SHAKE-256", NistObjectIdentifiers.IdShake256);
+
+ m_digestNameToOids.Add("GOST3411", CryptoProObjectIdentifiers.GostR3411);
+
+ m_digestNameToOids.Add("MD2", PkcsObjectIdentifiers.MD2);
+ m_digestNameToOids.Add("MD4", PkcsObjectIdentifiers.MD4);
+ m_digestNameToOids.Add("MD5", PkcsObjectIdentifiers.MD5);
+
+ m_digestNameToOids.Add("RIPEMD128", TeleTrusTObjectIdentifiers.RipeMD128);
+ m_digestNameToOids.Add("RIPEMD160", TeleTrusTObjectIdentifiers.RipeMD160);
+ m_digestNameToOids.Add("RIPEMD256", TeleTrusTObjectIdentifiers.RipeMD256);
}
- public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId)
+ public AlgorithmIdentifier Find(AlgorithmIdentifier sigAlgId)
{
AlgorithmIdentifier digAlgId;
@@ -477,19 +470,19 @@ public AlgorithmIdentifier find(AlgorithmIdentifier sigAlgId)
}
else
{
- digAlgId = new AlgorithmIdentifier((DerObjectIdentifier)digestOids[sigAlgId.Algorithm], DerNull.Instance);
+ digAlgId = new AlgorithmIdentifier(m_digestOids[sigAlgId.Algorithm], DerNull.Instance);
}
return digAlgId;
}
- public AlgorithmIdentifier find(string digAlgName)
+ public AlgorithmIdentifier Find(string digAlgName)
{
- return new AlgorithmIdentifier((DerObjectIdentifier)digestNameToOids[digAlgName], DerNull.Instance);
+ return new AlgorithmIdentifier(m_digestNameToOids[digAlgName], DerNull.Instance);
}
}
- public class CmsSignedGenerator
+ public abstract class CmsSignedGenerator
{
/**
* Default type for the signed data.
@@ -515,35 +508,38 @@ public class CmsSignedGenerator
public static readonly string EncryptionRsaPss = PkcsObjectIdentifiers.IdRsassaPss.Id;
public static readonly string EncryptionGost3410 = CryptoProObjectIdentifiers.GostR3410x94.Id;
public static readonly string EncryptionECGost3410 = CryptoProObjectIdentifiers.GostR3410x2001.Id;
-
- internal IList _certs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- internal IList _crls = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- internal IList _signers = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- internal IDictionary _digests = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ public static readonly string EncryptionECGost3410_2012_256 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256.Id;
+ public static readonly string EncryptionECGost3410_2012_512 = RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512.Id;
+
+ internal List _certs = new List();
+ internal List _crls = new List();
+ internal IList _signers = new List();
+ internal IDictionary m_digests =
+ new Dictionary(StringComparer.OrdinalIgnoreCase);
internal bool _useDerForCerts = false;
internal bool _useDerForCrls = false;
- protected readonly SecureRandom rand;
+ protected readonly SecureRandom m_random;
protected CmsSignedGenerator()
- : this(new SecureRandom())
+ : this(CryptoServicesRegistrar.GetSecureRandom())
{
}
/// Constructor allowing specific source of randomness
- /// Instance of SecureRandom to use.
- protected CmsSignedGenerator(
- SecureRandom rand)
+ /// Instance of SecureRandom to use.
+ protected CmsSignedGenerator(SecureRandom random)
{
- this.rand = rand;
+ if (random == null)
+ throw new ArgumentNullException(nameof(random));
+
+ m_random = random;
}
- internal protected virtual IDictionary GetBaseParameters(
- DerObjectIdentifier contentType,
- AlgorithmIdentifier digAlgId,
- byte[] hash)
+ internal protected virtual IDictionary GetBaseParameters(
+ DerObjectIdentifier contentType, AlgorithmIdentifier digAlgId, byte[] hash)
{
- IDictionary param = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ var param = new Dictionary();
if (contentType != null)
{
@@ -564,40 +560,51 @@ internal protected virtual Asn1Set GetAttributeSet(
: new DerSet(attr.ToAsn1EncodableVector());
}
- public void AddCertificates(
- IX509Store certStore)
+ public void AddAttributeCertificate(X509V2AttributeCertificate attrCert)
{
- CollectionUtilities.AddRange(_certs, CmsUtilities.GetCertificatesFromStore(certStore));
+ _certs.Add(new DerTaggedObject(false, 2, attrCert.AttributeCertificate));
}
- public void AddCrls(
- IX509Store crlStore)
+ public void AddAttributeCertificates(IStore attrCertStore)
{
- CollectionUtilities.AddRange(_crls, CmsUtilities.GetCrlsFromStore(crlStore));
+ _certs.AddRange(CmsUtilities.GetAttributeCertificatesFromStore(attrCertStore));
}
- /**
- * Add the attribute certificates contained in the passed in store to the
- * generator.
- *
- * @param store a store of Version 2 attribute certificates
- * @throws CmsException if an error occurse processing the store.
- */
- public void AddAttributeCertificates(
- IX509Store store)
+ public void AddCertificate(X509Certificate cert)
{
- try
- {
- foreach (IX509AttributeCertificate attrCert in store.GetMatches(null))
- {
- _certs.Add(new DerTaggedObject(false, 2,
- AttributeCertificate.GetInstance(Asn1Object.FromByteArray(attrCert.GetEncoded()))));
- }
- }
- catch (Exception e)
- {
- throw new CmsException("error processing attribute certs", e);
- }
+ _certs.Add(cert.CertificateStructure);
+ }
+
+ public void AddCertificates(IStore certStore)
+ {
+ _certs.AddRange(CmsUtilities.GetCertificatesFromStore(certStore));
+ }
+
+ public void AddCrl(X509Crl crl)
+ {
+ _crls.Add(crl.CertificateList);
+ }
+
+ public void AddCrls(IStore crlStore)
+ {
+ _crls.AddRange(CmsUtilities.GetCrlsFromStore(crlStore));
+ }
+
+ public void AddOtherRevocationInfo(OtherRevocationInfoFormat otherRevocationInfo)
+ {
+ CmsUtilities.ValidateOtherRevocationInfo(otherRevocationInfo);
+ _crls.Add(new DerTaggedObject(false, 1, otherRevocationInfo));
+ }
+
+ public void AddOtherRevocationInfos(IStore otherRevocationInfoStore)
+ {
+ _crls.AddRange(CmsUtilities.GetOtherRevocationInfosFromStore(otherRevocationInfoStore));
+ }
+
+ public void AddOtherRevocationInfos(DerObjectIdentifier otherRevInfoFormat,
+ IStore otherRevInfoStore)
+ {
+ _crls.AddRange(CmsUtilities.GetOtherRevocationInfosFromStore(otherRevInfoStore, otherRevInfoFormat));
}
/**
@@ -605,8 +612,7 @@ public void AddAttributeCertificates(
*
* @param signerStore store of signers
*/
- public void AddSigners(
- SignerInformationStore signerStore)
+ public void AddSigners(SignerInformationStore signerStore)
{
foreach (SignerInformation o in signerStore.GetSigners())
{
@@ -621,9 +627,9 @@ public void AddSigners(
*
* @return a map of oids (as string objects) and byte[] representing digests.
*/
- public IDictionary GetGeneratedDigests()
+ public IDictionary GetGeneratedDigests()
{
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(_digests);
+ return new Dictionary(m_digests, StringComparer.OrdinalIgnoreCase);
}
public bool UseDerForCerts
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedHelper.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedHelper.cs
index 364d7e2..0815c15 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedHelper.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSSignedHelper.cs
@@ -1,27 +1,25 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Eac;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Iana;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Esf;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Rosstandart;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.TeleTrust;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -35,18 +33,18 @@ internal class CmsSignedHelper
private static readonly string EncryptionECDsaWithSha384 = X9ObjectIdentifiers.ECDsaWithSha384.Id;
private static readonly string EncryptionECDsaWithSha512 = X9ObjectIdentifiers.ECDsaWithSha512.Id;
- private static readonly IDictionary encryptionAlgs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary digestAlgs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary digestAliases = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private static readonly IDictionary m_encryptionAlgs = new Dictionary();
+ private static readonly IDictionary m_digestAlgs = new Dictionary();
+ private static readonly IDictionary m_digestAliases = new Dictionary();
- private static readonly ISet noParams = new HashSet();
- private static readonly IDictionary ecAlgorithms = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ private static readonly HashSet noParams = new HashSet();
+ private static readonly IDictionary m_ecAlgorithms = new Dictionary();
- private static void AddEntries(DerObjectIdentifier oid, string digest, string encryption)
+ private static void AddEntries(DerObjectIdentifier oid, string digest, string encryption)
{
string alias = oid.Id;
- digestAlgs.Add(alias, digest);
- encryptionAlgs.Add(alias, encryption);
+ m_digestAlgs.Add(alias, digest);
+ m_encryptionAlgs.Add(alias, encryption);
}
static CmsSignedHelper()
@@ -89,95 +87,89 @@ static CmsSignedHelper()
AddEntries(EacObjectIdentifiers.id_TA_RSA_v1_5_SHA_256, "SHA256", "RSA");
AddEntries(EacObjectIdentifiers.id_TA_RSA_PSS_SHA_1, "SHA1", "RSAandMGF1");
AddEntries(EacObjectIdentifiers.id_TA_RSA_PSS_SHA_256, "SHA256", "RSAandMGF1");
-
- encryptionAlgs.Add(X9ObjectIdentifiers.IdDsa.Id, "DSA");
- encryptionAlgs.Add(PkcsObjectIdentifiers.RsaEncryption.Id, "RSA");
- encryptionAlgs.Add(TeleTrusTObjectIdentifiers.TeleTrusTRsaSignatureAlgorithm.Id, "RSA");
- encryptionAlgs.Add(X509ObjectIdentifiers.IdEARsa.Id, "RSA");
- encryptionAlgs.Add(CmsSignedGenerator.EncryptionRsaPss, "RSAandMGF1");
- encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x94.Id, "GOST3410");
- encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x2001.Id, "ECGOST3410");
- encryptionAlgs.Add("1.3.6.1.4.1.5849.1.6.2", "ECGOST3410");
- encryptionAlgs.Add("1.3.6.1.4.1.5849.1.1.5", "GOST3410");
-
- digestAlgs.Add(PkcsObjectIdentifiers.MD2.Id, "MD2");
- digestAlgs.Add(PkcsObjectIdentifiers.MD4.Id, "MD4");
- digestAlgs.Add(PkcsObjectIdentifiers.MD5.Id, "MD5");
- digestAlgs.Add(OiwObjectIdentifiers.IdSha1.Id, "SHA1");
- digestAlgs.Add(NistObjectIdentifiers.IdSha224.Id, "SHA224");
- digestAlgs.Add(NistObjectIdentifiers.IdSha256.Id, "SHA256");
- digestAlgs.Add(NistObjectIdentifiers.IdSha384.Id, "SHA384");
- digestAlgs.Add(NistObjectIdentifiers.IdSha512.Id, "SHA512");
- digestAlgs.Add(NistObjectIdentifiers.IdSha512_224.Id, "SHA512(224)");
- digestAlgs.Add(NistObjectIdentifiers.IdSha512_256.Id, "SHA512(256)");
- digestAlgs.Add(NistObjectIdentifiers.IdSha3_224.Id, "SHA3-224");
- digestAlgs.Add(NistObjectIdentifiers.IdSha3_256.Id, "SHA3-256");
- digestAlgs.Add(NistObjectIdentifiers.IdSha3_384.Id, "SHA3-384");
- digestAlgs.Add(NistObjectIdentifiers.IdSha3_512.Id, "SHA3-512");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD128.Id, "RIPEMD128");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD160.Id, "RIPEMD160");
- digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD256.Id, "RIPEMD256");
- digestAlgs.Add(CryptoProObjectIdentifiers.GostR3411.Id, "GOST3411");
- digestAlgs.Add("1.3.6.1.4.1.5849.1.2.1", "GOST3411");
-
- digestAliases.Add("SHA1", new string[] { "SHA-1" });
- digestAliases.Add("SHA224", new string[] { "SHA-224" });
- digestAliases.Add("SHA256", new string[] { "SHA-256" });
- digestAliases.Add("SHA384", new string[] { "SHA-384" });
- digestAliases.Add("SHA512", new string[] { "SHA-512" });
+ AddEntries(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94, "GOST3411", "GOST3410");
+ AddEntries(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001, "GOST3411", "ECGOST3410");
+ AddEntries(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_256, "GOST3411-2012-256", "ECGOST3410");
+ AddEntries(RosstandartObjectIdentifiers.id_tc26_signwithdigest_gost_3410_12_512, "GOST3411-2012-512", "ECGOST3410");
+
+ m_encryptionAlgs.Add(X9ObjectIdentifiers.IdDsa.Id, "DSA");
+ m_encryptionAlgs.Add(PkcsObjectIdentifiers.RsaEncryption.Id, "RSA");
+ m_encryptionAlgs.Add(TeleTrusTObjectIdentifiers.TeleTrusTRsaSignatureAlgorithm.Id, "RSA");
+ m_encryptionAlgs.Add(X509ObjectIdentifiers.IdEARsa.Id, "RSA");
+ m_encryptionAlgs.Add(CmsSignedGenerator.EncryptionRsaPss, "RSAandMGF1");
+ m_encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x94.Id, "GOST3410");
+ m_encryptionAlgs.Add(CryptoProObjectIdentifiers.GostR3410x2001.Id, "ECGOST3410");
+ m_encryptionAlgs.Add(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256.Id, "ECGOST3410");
+ m_encryptionAlgs.Add(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_512.Id, "ECGOST3410");
+ m_encryptionAlgs.Add("1.3.6.1.4.1.5849.1.6.2", "ECGOST3410");
+ m_encryptionAlgs.Add("1.3.6.1.4.1.5849.1.1.5", "GOST3410");
+
+ m_digestAlgs.Add(PkcsObjectIdentifiers.MD2.Id, "MD2");
+ m_digestAlgs.Add(PkcsObjectIdentifiers.MD4.Id, "MD4");
+ m_digestAlgs.Add(PkcsObjectIdentifiers.MD5.Id, "MD5");
+ m_digestAlgs.Add(OiwObjectIdentifiers.IdSha1.Id, "SHA1");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha224.Id, "SHA224");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha256.Id, "SHA256");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha384.Id, "SHA384");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha512.Id, "SHA512");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha512_224.Id, "SHA512(224)");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha512_256.Id, "SHA512(256)");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha3_224.Id, "SHA3-224");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha3_256.Id, "SHA3-256");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha3_384.Id, "SHA3-384");
+ m_digestAlgs.Add(NistObjectIdentifiers.IdSha3_512.Id, "SHA3-512");
+ m_digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD128.Id, "RIPEMD128");
+ m_digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD160.Id, "RIPEMD160");
+ m_digestAlgs.Add(TeleTrusTObjectIdentifiers.RipeMD256.Id, "RIPEMD256");
+ m_digestAlgs.Add(CryptoProObjectIdentifiers.GostR3411.Id, "GOST3411");
+ m_digestAlgs.Add("1.3.6.1.4.1.5849.1.2.1", "GOST3411");
+ m_digestAlgs.Add(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256.Id, "GOST3411-2012-256");
+ m_digestAlgs.Add(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512.Id, "GOST3411-2012-512");
+
+ m_digestAliases.Add("SHA1", new string[]{ "SHA-1" });
+ m_digestAliases.Add("SHA224", new string[]{ "SHA-224" });
+ m_digestAliases.Add("SHA256", new string[]{ "SHA-256" });
+ m_digestAliases.Add("SHA384", new string[]{ "SHA-384" });
+ m_digestAliases.Add("SHA512", new string[]{ "SHA-512" });
noParams.Add(CmsSignedGenerator.EncryptionDsa);
- // noParams.Add(EncryptionECDsa);
+ //noParams.Add(EncryptionECDsa);
noParams.Add(EncryptionECDsaWithSha1);
noParams.Add(EncryptionECDsaWithSha224);
noParams.Add(EncryptionECDsaWithSha256);
noParams.Add(EncryptionECDsaWithSha384);
noParams.Add(EncryptionECDsaWithSha512);
- ecAlgorithms.Add(CmsSignedGenerator.DigestSha1, EncryptionECDsaWithSha1);
- ecAlgorithms.Add(CmsSignedGenerator.DigestSha224, EncryptionECDsaWithSha224);
- ecAlgorithms.Add(CmsSignedGenerator.DigestSha256, EncryptionECDsaWithSha256);
- ecAlgorithms.Add(CmsSignedGenerator.DigestSha384, EncryptionECDsaWithSha384);
- ecAlgorithms.Add(CmsSignedGenerator.DigestSha512, EncryptionECDsaWithSha512);
- }
-
-
+ m_ecAlgorithms.Add(CmsSignedGenerator.DigestSha1, EncryptionECDsaWithSha1);
+ m_ecAlgorithms.Add(CmsSignedGenerator.DigestSha224, EncryptionECDsaWithSha224);
+ m_ecAlgorithms.Add(CmsSignedGenerator.DigestSha256, EncryptionECDsaWithSha256);
+ m_ecAlgorithms.Add(CmsSignedGenerator.DigestSha384, EncryptionECDsaWithSha384);
+ m_ecAlgorithms.Add(CmsSignedGenerator.DigestSha512, EncryptionECDsaWithSha512);
+ }
- /**
+ /**
* Return the digest algorithm using one of the standard JCA string
* representations rather than the algorithm identifier (if possible).
*/
- internal string GetDigestAlgName(
- string digestAlgOid)
+ internal string GetDigestAlgName(string digestAlgOid)
{
- string algName = (string)digestAlgs[digestAlgOid];
+ return m_digestAlgs.TryGetValue(digestAlgOid, out var algName) ? algName : digestAlgOid;
+ }
- if (algName != null)
+ internal AlgorithmIdentifier GetEncAlgorithmIdentifier(DerObjectIdentifier encOid,
+ Asn1Encodable sigX509Parameters)
+ {
+ if (noParams.Contains(encOid.Id))
{
- return algName;
+ return new AlgorithmIdentifier(encOid);
}
- return digestAlgOid;
- }
-
- internal AlgorithmIdentifier GetEncAlgorithmIdentifier(
- DerObjectIdentifier encOid,
- Asn1Encodable sigX509Parameters)
- {
- if (noParams.Contains(encOid.Id))
- {
- return new AlgorithmIdentifier(encOid);
- }
-
- return new AlgorithmIdentifier(encOid, sigX509Parameters);
- }
+ return new AlgorithmIdentifier(encOid, sigX509Parameters);
+ }
- internal string[] GetDigestAliases(
- string algName)
+ internal string[] GetDigestAliases(string algName)
{
- string[] aliases = (string[]) digestAliases[algName];
-
- return aliases == null ? new string[0] : (string[]) aliases.Clone();
+ return m_digestAliases.TryGetValue(algName, out var aliases) ? (string[])aliases.Clone() : new string[0];
}
/**
@@ -185,17 +177,9 @@ internal string[] GetDigestAliases(
* JCA string representations rather than the algorithm identifier (if
* possible).
*/
- internal string GetEncryptionAlgName(
- string encryptionAlgOid)
+ internal string GetEncryptionAlgName(string encryptionAlgOid)
{
- string algName = (string) encryptionAlgs[encryptionAlgOid];
-
- if (algName != null)
- {
- return algName;
- }
-
- return encryptionAlgOid;
+ return m_encryptionAlgs.TryGetValue(encryptionAlgOid, out var algName) ? algName : encryptionAlgOid;
}
internal IDigest GetDigestInstance(
@@ -224,142 +208,6 @@ internal ISigner GetSignatureInstance(
return SignerUtilities.GetSigner(algorithm);
}
- internal IX509Store CreateAttributeStore(
- string type,
- Asn1Set certSet)
- {
- IList certs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- if (certSet != null)
- {
- foreach (Asn1Encodable ae in certSet)
- {
- try
- {
- Asn1Object obj = ae.ToAsn1Object();
-
- if (obj is Asn1TaggedObject)
- {
- Asn1TaggedObject tagged = (Asn1TaggedObject)obj;
-
- if (tagged.TagNo == 2)
- {
- certs.Add(
- new X509V2AttributeCertificate(
- Asn1Sequence.GetInstance(tagged, false).GetEncoded()));
- }
- }
- }
- catch (Exception ex)
- {
- throw new CmsException("can't re-encode attribute certificate!", ex);
- }
- }
- }
-
- try
- {
- return X509StoreFactory.Create(
- "AttributeCertificate/" + type,
- new X509CollectionStoreParameters(certs));
- }
- catch (ArgumentException e)
- {
- throw new CmsException("can't setup the X509Store", e);
- }
- }
-
- internal IX509Store CreateCertificateStore(
- string type,
- Asn1Set certSet)
- {
- IList certs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- if (certSet != null)
- {
- AddCertsFromSet(certs, certSet);
- }
-
- try
- {
- return X509StoreFactory.Create(
- "Certificate/" + type,
- new X509CollectionStoreParameters(certs));
- }
- catch (ArgumentException e)
- {
- throw new CmsException("can't setup the X509Store", e);
- }
- }
-
- internal IX509Store CreateCrlStore(
- string type,
- Asn1Set crlSet)
- {
- IList crls = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- if (crlSet != null)
- {
- AddCrlsFromSet(crls, crlSet);
- }
-
- try
- {
- return X509StoreFactory.Create(
- "CRL/" + type,
- new X509CollectionStoreParameters(crls));
- }
- catch (ArgumentException e)
- {
- throw new CmsException("can't setup the X509Store", e);
- }
- }
-
- private void AddCertsFromSet(
- IList certs,
- Asn1Set certSet)
- {
- X509CertificateParser cf = new X509CertificateParser();
-
- foreach (Asn1Encodable ae in certSet)
- {
- try
- {
- Asn1Object obj = ae.ToAsn1Object();
-
- if (obj is Asn1Sequence)
- {
- // TODO Build certificate directly from sequence?
- certs.Add(cf.ReadCertificate(obj.GetEncoded()));
- }
- }
- catch (Exception ex)
- {
- throw new CmsException("can't re-encode certificate!", ex);
- }
- }
- }
-
- private void AddCrlsFromSet(
- IList crls,
- Asn1Set crlSet)
- {
- X509CrlParser cf = new X509CrlParser();
-
- foreach (Asn1Encodable ae in crlSet)
- {
- try
- {
- // TODO Build CRL directly from ae.ToAsn1Object()?
- crls.Add(cf.ReadCrl(ae.GetEncoded()));
- }
- catch (Exception ex)
- {
- throw new CmsException("can't re-encode CRL!", ex);
- }
- }
- }
-
internal AlgorithmIdentifier FixAlgID(
AlgorithmIdentifier algId)
{
@@ -375,9 +223,9 @@ internal string GetEncOid(
{
string encOID = null;
- if (key is RsaKeyParameters)
+ if (key is RsaKeyParameters rsaKeyParameters)
{
- if (!((RsaKeyParameters)key).IsPrivate)
+ if (!rsaKeyParameters.IsPrivate)
throw new ArgumentException("Expected RSA private key");
encOID = CmsSignedGenerator.EncryptionRsa;
@@ -409,22 +257,35 @@ internal string GetEncOid(
throw new ArgumentException("can't mix DSA with anything but SHA1/SHA2");
}
}
- else if (key is ECPrivateKeyParameters)
+ else if (key is ECPrivateKeyParameters ecPrivKey)
{
- ECPrivateKeyParameters ecPrivKey = (ECPrivateKeyParameters)key;
string algName = ecPrivKey.AlgorithmName;
if (algName == "ECGOST3410")
{
encOID = CmsSignedGenerator.EncryptionECGost3410;
}
- else
+ else if (ecPrivKey.Parameters is ECGost3410Parameters ecGost3410Parameters)
{
- // TODO Should we insist on algName being one of "EC" or "ECDSA", as Java does?
- encOID = (string)ecAlgorithms[digestOID];
-
- if (encOID == null)
- throw new ArgumentException("can't mix ECDSA with anything but SHA family digests");
+ var digestParamSet = ecGost3410Parameters.DigestParamSet;
+ if (digestParamSet.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_256))
+ {
+ encOID = CmsSignedGenerator.EncryptionECGost3410_2012_256;
+ }
+ else if (digestParamSet.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3411_12_512))
+ {
+ encOID = CmsSignedGenerator.EncryptionECGost3410_2012_512;
+ }
+ else
+ {
+ throw new ArgumentException("can't determine GOST3410 algorithm");
+ }
+ }
+ else
+ {
+ // TODO Should we insist on algName being one of "EC" or "ECDSA", as Java does?
+ if (!m_ecAlgorithms.TryGetValue(digestOID, out encOID))
+ throw new ArgumentException("can't mix ECDSA with anything but SHA family digests");
}
}
else if (key is Gost3410PrivateKeyParameters)
@@ -439,19 +300,83 @@ internal string GetEncOid(
return encOID;
}
- public IX509Store GetCertificates(Asn1Set certificates)
+ internal IStore GetAttributeCertificates(Asn1Set attrCertSet)
{
- IList certList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
- if (certificates != null)
- {
- foreach (Asn1Encodable enc in certificates)
- {
- certList.Add(X509CertificateStructure.GetInstance(enc));
- }
+ var contents = new List();
+ if (attrCertSet != null)
+ {
+ foreach (Asn1Encodable ae in attrCertSet)
+ {
+ if (ae != null && ae.ToAsn1Object() is Asn1TaggedObject t)
+ {
+ if (t.HasContextTag(2))
+ {
+ Asn1Sequence s = Asn1Sequence.GetInstance(t, false);
+
+ contents.Add(new X509V2AttributeCertificate(AttributeCertificate.GetInstance(s)));
+ }
+ }
+ }
}
- return new X509CollectionStore(certList);
+ return CollectionUtilities.CreateStore(contents);
}
- }
+
+ internal IStore GetCertificates(Asn1Set certSet)
+ {
+ var contents = new List();
+ if (certSet != null)
+ {
+ foreach (Asn1Encodable ae in certSet)
+ {
+ if (ae != null && ae.ToAsn1Object() is Asn1Sequence s)
+ {
+ contents.Add(new X509Certificate(X509CertificateStructure.GetInstance(s)));
+ }
+ }
+ }
+ return CollectionUtilities.CreateStore(contents);
+ }
+
+ internal IStore GetCrls(Asn1Set crlSet)
+ {
+ var contents = new List();
+ if (crlSet != null)
+ {
+ foreach (Asn1Encodable ae in crlSet)
+ {
+ if (ae != null && ae.ToAsn1Object() is Asn1Sequence s)
+ {
+ contents.Add(new X509Crl(CertificateList.GetInstance(s)));
+ }
+ }
+ }
+ return CollectionUtilities.CreateStore(contents);
+ }
+
+ internal IStore GetOtherRevInfos(Asn1Set crlSet, DerObjectIdentifier otherRevInfoFormat)
+ {
+ var contents = new List();
+ if (crlSet != null && otherRevInfoFormat != null)
+ {
+ foreach (Asn1Encodable ae in crlSet)
+ {
+ if (ae != null && ae.ToAsn1Object() is Asn1TaggedObject taggedObject)
+ {
+ if (taggedObject.HasContextTag(1))
+ {
+ var otherRevocationInfo = OtherRevocationInfoFormat.GetInstance(taggedObject, false);
+
+ if (otherRevInfoFormat.Equals(otherRevocationInfo.InfoFormat))
+ {
+ contents.Add(otherRevocationInfo.Info);
+ }
+ }
+ }
+ }
+ }
+ return CollectionUtilities.CreateStore(contents);
+ }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSStreamException.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSStreamException.cs
index ef719d3..c617ec5 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSStreamException.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSStreamException.cs
@@ -2,32 +2,34 @@
#pragma warning disable
using System;
using System.IO;
+using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
-#if !(NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE)
[Serializable]
-#endif
public class CmsStreamException
: IOException
{
public CmsStreamException()
+ : base()
+ {
+ }
+
+ public CmsStreamException(string message)
+ : base(message)
{
}
- public CmsStreamException(
- string name)
- : base(name)
- {
- }
+ public CmsStreamException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
- public CmsStreamException(
- string name,
- Exception e)
- : base(name, e)
- {
- }
- }
+ protected CmsStreamException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSTypedStream.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSTypedStream.cs
index c8b0529..b109e94 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSTypedStream.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSTypedStream.cs
@@ -35,11 +35,7 @@ public CmsTypedStream(
int bufSize)
{
_oid = oid;
-#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || PORTABLE || NETFX_CORE
- _in = new FullReaderStream(inStream);
-#else
_in = new FullReaderStream(new BufferedStream(inStream, bufSize));
-#endif
}
public string ContentType
@@ -55,7 +51,7 @@ public Stream ContentStream
public void Drain()
{
Streams.Drain(_in);
- BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(_in);
+ _in.Dispose();
}
private class FullReaderStream : FilterStream
@@ -65,12 +61,19 @@ internal FullReaderStream(Stream input)
{
}
- public override int Read(byte[] buf, int off, int len)
+ public override int Read(byte[] buf, int off, int len)
{
- return Streams.ReadFully(base.s, buf, off, len);
+ return Streams.ReadFully(s, buf, off, len);
}
- }
- }
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
+ public override int Read(Span buffer)
+ {
+ return Streams.ReadFully(s, buffer);
+ }
+#endif
+ }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSUtils.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSUtils.cs
index b1a2b93..7b51d38 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSUtils.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/CMSUtils.cs
@@ -1,17 +1,16 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ocsp;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -71,98 +70,109 @@ private static ContentInfo ReadContentInfo(
}
}
- public static byte[] StreamToByteArray(
- Stream inStream)
+ internal static byte[] StreamToByteArray(Stream inStream)
{
return Streams.ReadAll(inStream);
}
- public static byte[] StreamToByteArray(
- Stream inStream,
- int limit)
+ internal static byte[] StreamToByteArray(Stream inStream, int limit)
{
return Streams.ReadAllLimited(inStream, limit);
}
- public static IList GetCertificatesFromStore(
- IX509Store certStore)
+ internal static List GetAttributeCertificatesFromStore(
+ IStore attrCertStore)
{
- try
- {
- IList certs = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- if (certStore != null)
+ var result = new List();
+ if (attrCertStore != null)
+ {
+ foreach (var attrCert in attrCertStore.EnumerateMatches(null))
{
- foreach (X509Certificate c in certStore.GetMatches(null))
- {
- certs.Add(
- X509CertificateStructure.GetInstance(
- Asn1Object.FromByteArray(c.GetEncoded())));
- }
+ result.Add(new DerTaggedObject(false, 2, attrCert.AttributeCertificate));
}
+ }
+ return result;
+ }
- return certs;
- }
- catch (CertificateEncodingException e)
- {
- throw new CmsException("error encoding certs", e);
- }
- catch (Exception e)
- {
- throw new CmsException("error processing certs", e);
+ internal static List GetCertificatesFromStore(IStore certStore)
+ {
+ var result = new List();
+ if (certStore != null)
+ {
+ foreach (var cert in certStore.EnumerateMatches(null))
+ {
+ result.Add(cert.CertificateStructure);
+ }
}
+ return result;
}
- public static IList GetCrlsFromStore(
- IX509Store crlStore)
+ internal static List GetCrlsFromStore(IStore crlStore)
{
- try
+ var result = new List();
+ if (crlStore != null)
{
- IList crls = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
-
- if (crlStore != null)
- {
- foreach (X509Crl c in crlStore.GetMatches(null))
- {
- crls.Add(
- CertificateList.GetInstance(
- Asn1Object.FromByteArray(c.GetEncoded())));
- }
+ foreach (var crl in crlStore.EnumerateMatches(null))
+ {
+ result.Add(crl.CertificateList);
}
-
- return crls;
- }
- catch (CrlException e)
- {
- throw new CmsException("error encoding crls", e);
}
- catch (Exception e)
+ return result;
+ }
+
+ internal static List GetOtherRevocationInfosFromStore(
+ IStore otherRevocationInfoStore)
+ {
+ var result = new List();
+ if (otherRevocationInfoStore != null)
+ {
+ foreach (var otherRevocationInfo in otherRevocationInfoStore.EnumerateMatches(null))
+ {
+ ValidateOtherRevocationInfo(otherRevocationInfo);
+
+ result.Add(new DerTaggedObject(false, 1, otherRevocationInfo));
+ }
+ }
+ return result;
+ }
+
+ internal static List GetOtherRevocationInfosFromStore(IStore otherRevInfoStore,
+ DerObjectIdentifier otherRevInfoFormat)
+ {
+ var result = new List();
+ if (otherRevInfoStore != null && otherRevInfoFormat != null)
{
- throw new CmsException("error processing crls", e);
+ foreach (var otherRevInfo in otherRevInfoStore.EnumerateMatches(null))
+ {
+ var otherRevocationInfo = new OtherRevocationInfoFormat(otherRevInfoFormat, otherRevInfo);
+
+ ValidateOtherRevocationInfo(otherRevocationInfo);
+
+ result.Add(new DerTaggedObject(false, 1, otherRevocationInfo));
+ }
}
- }
+ return result;
+ }
- public static Asn1Set CreateBerSetFromList(
- IList berObjects)
+ internal static Asn1Set CreateBerSetFromList(IEnumerable elements)
{
Asn1EncodableVector v = new Asn1EncodableVector();
- foreach (Asn1Encodable ae in berObjects)
+ foreach (Asn1Encodable element in elements)
{
- v.Add(ae);
+ v.Add(element);
}
return new BerSet(v);
}
- public static Asn1Set CreateDerSetFromList(
- IList derObjects)
+ internal static Asn1Set CreateDerSetFromList(IEnumerable elements)
{
Asn1EncodableVector v = new Asn1EncodableVector();
- foreach (Asn1Encodable ae in derObjects)
+ foreach (Asn1Encodable element in elements)
{
- v.Add(ae);
+ v.Add(element);
}
return new DerSet(v);
@@ -184,7 +194,18 @@ internal static IssuerAndSerialNumber GetIssuerAndSerialNumber(X509Certificate c
TbsCertificateStructure tbsCert = GetTbsCertificateStructure(cert);
return new IssuerAndSerialNumber(tbsCert.Issuer, tbsCert.SerialNumber.Value);
}
- }
+
+ internal static void ValidateOtherRevocationInfo(OtherRevocationInfoFormat otherRevocationInfo)
+ {
+ if (CmsObjectIdentifiers.id_ri_ocsp_response.Equals(otherRevocationInfo.InfoFormat))
+ {
+ OcspResponse ocspResponse = OcspResponse.GetInstance(otherRevocationInfo.Info);
+
+ if (OcspResponseStatus.Successful != ocspResponse.ResponseStatus.IntValueExact)
+ throw new ArgumentException("cannot add unsuccessful OCSP response to CMS SignedData");
+ }
+ }
+ }
}
#pragma warning restore
#endif
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultAuthenticatedAttributeTableGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultAuthenticatedAttributeTableGenerator.cs
index b588bde..c751e79 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultAuthenticatedAttributeTableGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultAuthenticatedAttributeTableGenerator.cs
@@ -1,11 +1,10 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -15,14 +14,14 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class DefaultAuthenticatedAttributeTableGenerator
: CmsAttributeTableGenerator
{
- private readonly IDictionary table;
+ private readonly IDictionary m_table;
/**
* Initialise to use all defaults
*/
public DefaultAuthenticatedAttributeTableGenerator()
{
- table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ m_table = new Dictionary();
}
/**
@@ -35,11 +34,11 @@ public DefaultAuthenticatedAttributeTableGenerator(
{
if (attributeTable != null)
{
- table = attributeTable.ToDictionary();
+ m_table = attributeTable.ToDictionary();
}
else
{
- table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ m_table = new Dictionary();
}
}
@@ -53,12 +52,12 @@ public DefaultAuthenticatedAttributeTableGenerator(
*
* @return a filled in IDictionary of attributes.
*/
- protected virtual IDictionary CreateStandardAttributeTable(
- IDictionary parameters)
+ protected virtual IDictionary CreateStandardAttributeTable(
+ IDictionary parameters)
{
- IDictionary std = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(table);
+ var std = new Dictionary(m_table);
- if (!std.Contains(CmsAttributes.ContentType))
+ if (!std.ContainsKey(CmsAttributes.ContentType))
{
DerObjectIdentifier contentType = (DerObjectIdentifier)
parameters[CmsAttributeTableParameter.ContentType];
@@ -67,7 +66,7 @@ protected virtual IDictionary CreateStandardAttributeTable(
std[attr.AttrType] = attr;
}
- if (!std.Contains(CmsAttributes.MessageDigest))
+ if (!std.ContainsKey(CmsAttributes.MessageDigest))
{
byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
@@ -78,14 +77,13 @@ protected virtual IDictionary CreateStandardAttributeTable(
return std;
}
- /**
+ /**
* @param parameters source parameters
* @return the populated attribute table
*/
- public virtual AttributeTable GetAttributes(
- IDictionary parameters)
+ public virtual AttributeTable GetAttributes(IDictionary parameters)
{
- IDictionary table = CreateStandardAttributeTable(parameters);
+ var table = CreateStandardAttributeTable(parameters);
return new AttributeTable(table);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultSignedAttributeTableGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultSignedAttributeTableGenerator.cs
index 44a4f04..49b76e2 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultSignedAttributeTableGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/DefaultSignedAttributeTableGenerator.cs
@@ -1,11 +1,10 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -15,14 +14,14 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class DefaultSignedAttributeTableGenerator
: CmsAttributeTableGenerator
{
- private readonly IDictionary table;
+ private readonly IDictionary m_table;
/**
* Initialise to use all defaults
*/
public DefaultSignedAttributeTableGenerator()
{
- table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ m_table = new Dictionary();
}
/**
@@ -30,38 +29,18 @@ public DefaultSignedAttributeTableGenerator()
*
* @param attributeTable initial attribute table to use.
*/
- public DefaultSignedAttributeTableGenerator(
- AttributeTable attributeTable)
+ public DefaultSignedAttributeTableGenerator(AttributeTable attributeTable)
{
if (attributeTable != null)
{
- table = attributeTable.ToDictionary();
+ m_table = attributeTable.ToDictionary();
}
else
{
- table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ m_table = new Dictionary();
}
}
-#if SILVERLIGHT || PORTABLE || NETFX_CORE
- /**
- * Create a standard attribute table from the passed in parameters - this will
- * normally include contentType, signingTime, and messageDigest. If the constructor
- * using an AttributeTable was used, entries in it for contentType, signingTime, and
- * messageDigest will override the generated ones.
- *
- * @param parameters source parameters for table generation.
- *
- * @return a filled in Hashtable of attributes.
- */
- protected virtual IDictionary createStandardAttributeTable(
- IDictionary parameters)
- {
- IDictionary std = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(table);
- DoCreateStandardAttributeTable(parameters, std);
- return std;
- }
-#else
/**
* Create a standard attribute table from the passed in parameters - this will
* normally include contentType, signingTime, and messageDigest. If the constructor
@@ -70,23 +49,24 @@ protected virtual IDictionary createStandardAttributeTable(
*
* @param parameters source parameters for table generation.
*
- * @return a filled in Hashtable of attributes.
+ * @return a filled in Dictionary of attributes.
*/
- protected virtual Hashtable createStandardAttributeTable(
- IDictionary parameters)
+ protected virtual IDictionary CreateStandardAttributeTable(
+ IDictionary parameters)
{
- Hashtable std = new Hashtable(table);
+ var std = new Dictionary(m_table);
DoCreateStandardAttributeTable(parameters, std);
return std;
}
-#endif
- private void DoCreateStandardAttributeTable(IDictionary parameters, IDictionary std)
+ private void DoCreateStandardAttributeTable(IDictionary parameters,
+ IDictionary std)
{
// contentType will be absent if we're trying to generate a counter signature.
- if (parameters.Contains(CmsAttributeTableParameter.ContentType))
+
+ if (parameters.ContainsKey(CmsAttributeTableParameter.ContentType))
{
- if (!std.Contains(CmsAttributes.ContentType))
+ if (!std.ContainsKey(CmsAttributes.ContentType))
{
DerObjectIdentifier contentType = (DerObjectIdentifier)
parameters[CmsAttributeTableParameter.ContentType];
@@ -96,14 +76,14 @@ private void DoCreateStandardAttributeTable(IDictionary parameters, IDictionary
}
}
- if (!std.Contains(CmsAttributes.SigningTime))
+ if (!std.ContainsKey(CmsAttributes.SigningTime))
{
Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.SigningTime,
new DerSet(new Time(DateTime.UtcNow)));
std[attr.AttrType] = attr;
}
- if (!std.Contains(CmsAttributes.MessageDigest))
+ if (!std.ContainsKey(CmsAttributes.MessageDigest))
{
byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
@@ -116,10 +96,9 @@ private void DoCreateStandardAttributeTable(IDictionary parameters, IDictionary
* @param parameters source parameters
* @return the populated attribute table
*/
- public virtual AttributeTable GetAttributes(
- IDictionary parameters)
+ public virtual AttributeTable GetAttributes(IDictionary parameters)
{
- IDictionary table = createStandardAttributeTable(parameters);
+ var table = CreateStandardAttributeTable(parameters);
return new AttributeTable(table);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/EnvelopedDataHelper.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/EnvelopedDataHelper.cs
index f633d18..1aad162 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/EnvelopedDataHelper.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/EnvelopedDataHelper.cs
@@ -1,49 +1,43 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Oiw;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
internal class EnvelopedDataHelper
{
- private static readonly IDictionary BaseCipherNames = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- private static readonly IDictionary MacAlgNames = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
- //private static readonly IDictionary PrfDigests = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
+ //private static readonly IDictionary BaseCipherNames =
+ // new Dictionary();
+ //private static readonly IDictionary MacAlgNames =
+ // new Dictionary();
+ //private static readonly IDictionary PrfDigests =
+ // new Dictionary();
- static EnvelopedDataHelper()
- {
- //PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha1, "SHA-1");
- //PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha224, "SHA-224");
- //PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha256, "SHA-256");
- //PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha384, "SHA-384");
- //PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha512, "SHA-512");
+ //static EnvelopedDataHelper()
+ //{
+ // PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha1, "SHA-1");
+ // PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha224, "SHA-224");
+ // PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha256, "SHA-256");
+ // PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha384, "SHA-384");
+ // PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha512, "SHA-512");
- BaseCipherNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDE");
- BaseCipherNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AES");
- BaseCipherNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AES");
- BaseCipherNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AES");
+ // BaseCipherNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDE");
+ // BaseCipherNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AES");
+ // BaseCipherNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AES");
+ // BaseCipherNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AES");
- MacAlgNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDEMac");
- MacAlgNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AESMac");
- MacAlgNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AESMac");
- MacAlgNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AESMac");
- MacAlgNames.Add(PkcsObjectIdentifiers.RC2Cbc, "RC2Mac");
- }
+ // MacAlgNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDEMac");
+ // MacAlgNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AESMac");
+ // MacAlgNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AESMac");
+ // MacAlgNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AESMac");
+ // MacAlgNames.Add(PkcsObjectIdentifiers.RC2Cbc, "RC2Mac");
+ //}
//internal static IDigest GetPrf(AlgorithmIdentifier algID)
//{
@@ -58,7 +52,7 @@ static EnvelopedDataHelper()
// || NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm)
// || NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm))
// {
- // return new Rfc3211WrapEngine(new AesEngine());
+ // return new Rfc3211WrapEngine(AesUtilities.CreateEngine());
// }
// else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm))
// {
@@ -84,7 +78,8 @@ public static object CreateContentCipher(bool forEncryption, ICipherParameters e
return CipherFactory.CreateContentCipher(forEncryption, encKey, encryptionAlgID);
}
- public AlgorithmIdentifier GenerateEncryptionAlgID(DerObjectIdentifier encryptionOID, KeyParameter encKey, SecureRandom random)
+ public AlgorithmIdentifier GenerateEncryptionAlgID(DerObjectIdentifier encryptionOID, KeyParameter encKey,
+ SecureRandom random)
{
return AlgorithmIdentifierFactory.GenerateEncryptionAlgID(encryptionOID, encKey.GetKey().Length * 8, random);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KEKRecipientInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KEKRecipientInfoGenerator.cs
index 703f62f..baea3d4 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KEKRecipientInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KEKRecipientInfoGenerator.cs
@@ -66,19 +66,19 @@ public RecipientInfo Generate(KeyParameter contentEncryptionKey, SecureRandom ra
private static AlgorithmIdentifier DetermineKeyEncAlg(
string algorithm, KeyParameter key)
{
- if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "DES"))
+ if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "DES"))
{
return new AlgorithmIdentifier(
PkcsObjectIdentifiers.IdAlgCms3DesWrap,
DerNull.Instance);
}
- else if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "RC2"))
+ else if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "RC2"))
{
return new AlgorithmIdentifier(
PkcsObjectIdentifiers.IdAlgCmsRC2Wrap,
new DerInteger(58));
}
- else if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "AES"))
+ else if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "AES"))
{
int length = key.GetKey().Length * 8;
DerObjectIdentifier wrapOid;
@@ -102,12 +102,12 @@ private static AlgorithmIdentifier DetermineKeyEncAlg(
return new AlgorithmIdentifier(wrapOid); // parameters absent
}
- else if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "SEED"))
+ else if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "SEED"))
{
// parameters absent
return new AlgorithmIdentifier(KisaObjectIdentifiers.IdNpkiAppCmsSeedWrap);
}
- else if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "CAMELLIA"))
+ else if (Org.BouncyCastle.Utilities.Platform.StartsWith(algorithm, "CAMELLIA"))
{
int length = key.GetKey().Length * 8;
DerObjectIdentifier wrapOid;
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInfoGenerator.cs
index 614ca5b..4879aae 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInfoGenerator.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -13,7 +13,6 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
@@ -24,7 +23,7 @@ internal class KeyAgreeRecipientInfoGenerator : RecipientInfoGenerator
private DerObjectIdentifier keyAgreementOID;
private DerObjectIdentifier keyEncryptionOID;
- private IList recipientCerts;
+ private IList recipientCerts;
private AsymmetricCipherKeyPair senderKeyPair;
internal KeyAgreeRecipientInfoGenerator()
@@ -41,9 +40,9 @@ internal DerObjectIdentifier KeyEncryptionOID
set { this.keyEncryptionOID = value; }
}
- internal ICollection RecipientCerts
+ internal IEnumerable RecipientCerts
{
- set { this.recipientCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(value); }
+ set { this.recipientCerts = new List(value); }
}
internal AsymmetricCipherKeyPair SenderKeyPair
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInformation.cs
index b6106e4..8d8f5f5 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyAgreeRecipientInformation.cs
@@ -1,14 +1,13 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms.Ecc;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X9;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
@@ -16,7 +15,6 @@
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -30,7 +28,7 @@ public class KeyAgreeRecipientInformation
private KeyAgreeRecipientInfo info;
private Asn1OctetString encryptedKey;
- internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info,
+ internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info,
CmsSecureReadable secureReadable)
{
try
@@ -212,11 +210,9 @@ internal KeyParameter GetSessionKey(
public override CmsTypedStream GetContentStream(
ICipherParameters key)
{
- if (!(key is AsymmetricKeyParameter))
+ if (!(key is AsymmetricKeyParameter receiverPrivateKey))
throw new ArgumentException("KeyAgreement requires asymmetric key", "key");
- AsymmetricKeyParameter receiverPrivateKey = (AsymmetricKeyParameter) key;
-
if (!receiverPrivateKey.IsPrivate)
throw new ArgumentException("Expected private key", "key");
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyTransRecipientInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyTransRecipientInfoGenerator.cs
index e2f697f..fff2b92 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyTransRecipientInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/KeyTransRecipientInfoGenerator.cs
@@ -1,7 +1,6 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
@@ -13,52 +12,45 @@
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
- public class KeyTransRecipientInfoGenerator : RecipientInfoGenerator
+ public class KeyTransRecipientInfoGenerator
+ : RecipientInfoGenerator
{
- private static readonly CmsEnvelopedHelper Helper = CmsEnvelopedHelper.Instance;
+ private readonly IKeyWrapper m_keyWrapper;
- private Asn1OctetString subjectKeyIdentifier;
- private IKeyWrapper keyWrapper;
-
- // Derived fields
- private SubjectPublicKeyInfo info;
- private IssuerAndSerialNumber issuerAndSerialNumber;
- private SecureRandom random;
-
+ private IssuerAndSerialNumber m_issuerAndSerialNumber;
+ private Asn1OctetString m_subjectKeyIdentifier;
public KeyTransRecipientInfoGenerator(X509Certificate recipCert, IKeyWrapper keyWrapper)
- : this(new Asn1.Cms.IssuerAndSerialNumber(recipCert.IssuerDN, new DerInteger(recipCert.SerialNumber)), keyWrapper)
+ : this(new IssuerAndSerialNumber(recipCert.IssuerDN, new DerInteger(recipCert.SerialNumber)), keyWrapper)
{
}
public KeyTransRecipientInfoGenerator(IssuerAndSerialNumber issuerAndSerial, IKeyWrapper keyWrapper)
{
- this.issuerAndSerialNumber = issuerAndSerial;
- this.keyWrapper = keyWrapper;
+ m_issuerAndSerialNumber = issuerAndSerial;
+ m_keyWrapper = keyWrapper;
}
public KeyTransRecipientInfoGenerator(byte[] subjectKeyID, IKeyWrapper keyWrapper)
{
- this.subjectKeyIdentifier = new DerOctetString(subjectKeyIdentifier);
- this.keyWrapper = keyWrapper;
+ m_subjectKeyIdentifier = new DerOctetString(subjectKeyID);
+ m_keyWrapper = keyWrapper;
}
public RecipientInfo Generate(KeyParameter contentEncryptionKey, SecureRandom random)
{
- AlgorithmIdentifier keyEncryptionAlgorithm = this.AlgorithmDetails;
-
- this.random = random;
+ AlgorithmIdentifier keyEncryptionAlgorithm = AlgorithmDetails;
byte[] encryptedKeyBytes = GenerateWrappedKey(contentEncryptionKey);
RecipientIdentifier recipId;
- if (issuerAndSerialNumber != null)
+ if (m_issuerAndSerialNumber != null)
{
- recipId = new RecipientIdentifier(issuerAndSerialNumber);
+ recipId = new RecipientIdentifier(m_issuerAndSerialNumber);
}
else
{
- recipId = new RecipientIdentifier(subjectKeyIdentifier);
+ recipId = new RecipientIdentifier(m_subjectKeyIdentifier);
}
return new RecipientInfo(new KeyTransRecipientInfo(recipId, keyEncryptionAlgorithm,
@@ -67,19 +59,12 @@ public RecipientInfo Generate(KeyParameter contentEncryptionKey, SecureRandom ra
protected virtual AlgorithmIdentifier AlgorithmDetails
{
- get
- {
- if (this.keyWrapper != null)
- {
- return (AlgorithmIdentifier)keyWrapper.AlgorithmDetails;
- }
- return info.AlgorithmID;
- }
+ get { return (AlgorithmIdentifier)m_keyWrapper.AlgorithmDetails; }
}
protected virtual byte[] GenerateWrappedKey(KeyParameter contentEncryptionKey)
{
- return keyWrapper.Wrap(contentEncryptionKey.GetKey()).Collect();
+ return m_keyWrapper.Wrap(contentEncryptionKey.GetKey()).Collect();
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorId.cs
index ff3f0b0..5ab836c 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorId.cs
@@ -46,7 +46,7 @@ public override bool Equals(
return false;
return Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier)
- && BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
+ && Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
&& IssuersMatch(Issuer, id.Issuer);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInfoGenerator.cs
index 6fcd715..72fee2e 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInfoGenerator.cs
@@ -1,42 +1,73 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
-using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
public class OriginatorInfoGenerator
{
- private readonly IList origCerts;
- private readonly IList origCrls;
+ private readonly List origCerts;
+ private readonly List origCrls;
public OriginatorInfoGenerator(X509Certificate origCert)
{
- this.origCerts = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
+ this.origCerts = new List{ origCert.CertificateStructure };
this.origCrls = null;
- origCerts.Add(origCert.CertificateStructure);
}
- public OriginatorInfoGenerator(IX509Store origCerts)
- : this(origCerts, null)
+ public OriginatorInfoGenerator(IStore x509Certs)
+ : this(x509Certs, null, null, null)
{
}
- public OriginatorInfoGenerator(IX509Store origCerts, IX509Store origCrls)
+ public OriginatorInfoGenerator(IStore x509Certs, IStore x509Crls)
+ : this(x509Certs, x509Crls, null, null)
{
- this.origCerts = CmsUtilities.GetCertificatesFromStore(origCerts);
- this.origCrls = origCrls == null ? null : CmsUtilities.GetCrlsFromStore(origCrls);
+ }
+
+ public OriginatorInfoGenerator(IStore x509Certs, IStore x509Crls,
+ IStore x509AttrCerts, IStore otherRevocationInfos)
+ {
+ List certificates = null;
+ if (x509Certs != null || x509AttrCerts != null)
+ {
+ certificates = new List();
+ if (x509Certs != null)
+ {
+ certificates.AddRange(CmsUtilities.GetCertificatesFromStore(x509Certs));
+ }
+ if (x509AttrCerts != null)
+ {
+ certificates.AddRange(CmsUtilities.GetAttributeCertificatesFromStore(x509AttrCerts));
+ }
+ }
+
+ List revocations = null;
+ if (x509Crls != null || otherRevocationInfos != null)
+ {
+ revocations = new List();
+ if (x509Crls != null)
+ {
+ revocations.AddRange(CmsUtilities.GetCrlsFromStore(x509Crls));
+ }
+ if (otherRevocationInfos != null)
+ {
+ revocations.AddRange(CmsUtilities.GetOtherRevocationInfosFromStore(otherRevocationInfos));
+ }
+ }
+
+ this.origCerts = certificates;
+ this.origCrls = revocations;
}
public virtual OriginatorInfo Generate()
{
- Asn1Set certSet = CmsUtilities.CreateDerSetFromList(origCerts);
+ Asn1Set certSet = origCerts == null ? null : CmsUtilities.CreateDerSetFromList(origCerts);
Asn1Set crlSet = origCrls == null ? null : CmsUtilities.CreateDerSetFromList(origCrls);
return new OriginatorInfo(certSet, crlSet);
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInformation.cs
index d122b6e..16b7fd1 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/OriginatorInformation.cs
@@ -1,14 +1,10 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
+using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
-using BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Store;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
@@ -26,31 +22,9 @@ internal OriginatorInformation(OriginatorInfo originatorInfo)
*
* @return a Store of X509CertificateHolder objects.
*/
- public virtual IX509Store GetCertificates()
+ public virtual IStore GetCertificates()
{
- Asn1Set certSet = originatorInfo.Certificates;
-
- if (certSet != null)
- {
- IList certList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(certSet.Count);
-
- foreach (Asn1Encodable enc in certSet)
- {
- Asn1Object obj = enc.ToAsn1Object();
- if (obj is Asn1Sequence)
- {
- certList.Add(new X509Certificate(X509CertificateStructure.GetInstance(obj)));
- }
- }
-
- return X509StoreFactory.Create(
- "Certificate/Collection",
- new X509CollectionStoreParameters(certList));
- }
-
- return X509StoreFactory.Create(
- "Certificate/Collection",
- new X509CollectionStoreParameters(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList()));
+ return CmsSignedHelper.Instance.GetCertificates(originatorInfo.Certificates);
}
/**
@@ -58,31 +32,9 @@ public virtual IX509Store GetCertificates()
*
* @return a Store of X509CRLHolder objects.
*/
- public virtual IX509Store GetCrls()
+ public virtual IStore GetCrls()
{
- Asn1Set crlSet = originatorInfo.Certificates;
-
- if (crlSet != null)
- {
- IList crlList = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(crlSet.Count);
-
- foreach (Asn1Encodable enc in crlSet)
- {
- Asn1Object obj = enc.ToAsn1Object();
- if (obj is Asn1Sequence)
- {
- crlList.Add(new X509Crl(CertificateList.GetInstance(obj)));
- }
- }
-
- return X509StoreFactory.Create(
- "CRL/Collection",
- new X509CollectionStoreParameters(crlList));
- }
-
- return X509StoreFactory.Create(
- "CRL/Collection",
- new X509CollectionStoreParameters(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList()));
+ return CmsSignedHelper.Instance.GetCrls(originatorInfo.Crls);
}
/**
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2PBEKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2PBEKey.cs
index 12aacd8..c32250a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2PBEKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2PBEKey.cs
@@ -16,23 +16,6 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class Pkcs5Scheme2PbeKey
: CmsPbeKey
{
-
- public Pkcs5Scheme2PbeKey(
- string password,
- byte[] salt,
- int iterationCount)
- : this(password.ToCharArray(), salt, iterationCount)
- {
- }
-
-
- public Pkcs5Scheme2PbeKey(
- string password,
- AlgorithmIdentifier keyDerivationAlgorithm)
- : this(password.ToCharArray(), keyDerivationAlgorithm)
- {
- }
-
public Pkcs5Scheme2PbeKey(
char[] password,
byte[] salt,
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2UTF8PBEKey.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2UTF8PBEKey.cs
index bf5aae0..d6de0cd 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2UTF8PBEKey.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PKCS5Scheme2UTF8PBEKey.cs
@@ -16,23 +16,6 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
public class Pkcs5Scheme2Utf8PbeKey
: CmsPbeKey
{
-
- public Pkcs5Scheme2Utf8PbeKey(
- string password,
- byte[] salt,
- int iterationCount)
- : this(password.ToCharArray(), salt, iterationCount)
- {
- }
-
-
- public Pkcs5Scheme2Utf8PbeKey(
- string password,
- AlgorithmIdentifier keyDerivationAlgorithm)
- : this(password.ToCharArray(), keyDerivationAlgorithm)
- {
- }
-
public Pkcs5Scheme2Utf8PbeKey(
char[] password,
byte[] salt,
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PasswordRecipientInfoGenerator.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PasswordRecipientInfoGenerator.cs
index 5f5dcb7..6efa8c7 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PasswordRecipientInfoGenerator.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/PasswordRecipientInfoGenerator.cs
@@ -49,7 +49,7 @@ public RecipientInfo Generate(KeyParameter contentEncryptionKey, SecureRandom ra
IWrapper keyWrapper = Helper.CreateWrapper(rfc3211WrapperName);
// Note: In Java build, the IV is automatically generated in JCE layer
- int ivLength = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(rfc3211WrapperName, "DESEDE") ? 8 : 16;
+ int ivLength = Org.BouncyCastle.Utilities.Platform.StartsWith(rfc3211WrapperName, "DESEDE") ? 8 : 16;
byte[] iv = new byte[ivLength];
random.NextBytes(iv);
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientId.cs
index 7a1a950..35413ea 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientId.cs
@@ -53,7 +53,7 @@ public override bool Equals(
return Arrays.AreEqual(keyIdentifier, id.keyIdentifier)
&& Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier)
- && BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
+ && Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
&& IssuersMatch(Issuer, id.Issuer);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformation.cs
index af116d4..de92035 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformation.cs
@@ -114,15 +114,15 @@ public byte[] GetMac()
if (resultMac == null)
{
object cryptoObject = secureReadable.CryptoObject;
- if (cryptoObject is IMac)
+ if (cryptoObject is IMac mac)
{
- resultMac = MacUtilities.DoFinal((IMac)cryptoObject);
+ resultMac = MacUtilities.DoFinal(mac);
}
}
return Arrays.Clone(resultMac);
}
-
+
public abstract CmsTypedStream GetContentStream(ICipherParameters key);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformationStore.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformationStore.cs
index e067b7c..89b777a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformationStore.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/RecipientInformationStore.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
@@ -9,26 +9,25 @@ namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
public class RecipientInformationStore
{
- private readonly IList all; //ArrayList[RecipientInformation]
- private readonly IDictionary table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(); // Hashtable[RecipientID, ArrayList[RecipientInformation]]
+ private readonly IList m_all;
+ private readonly IDictionary> m_table =
+ new Dictionary>();
- public RecipientInformationStore(
- ICollection recipientInfos)
+ public RecipientInformationStore(IEnumerable recipientInfos)
{
foreach (RecipientInformation recipientInformation in recipientInfos)
{
RecipientID rid = recipientInformation.RecipientID;
- IList list = (IList)table[rid];
- if (list == null)
- {
- table[rid] = list = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(1);
+ if (!m_table.TryGetValue(rid, out var list))
+ {
+ m_table[rid] = list = new List(1);
}
list.Add(recipientInformation);
}
- this.all = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(recipientInfos);
+ this.m_all = new List(recipientInfos);
}
public RecipientInformation this[RecipientID selector]
@@ -43,12 +42,12 @@ public RecipientInformation this[RecipientID selector]
* @param selector to identify a recipient
* @return a single RecipientInformation object. Null if none matches.
*/
- public RecipientInformation GetFirstRecipient(
- RecipientID selector)
+ public RecipientInformation GetFirstRecipient(RecipientID selector)
{
- IList list = (IList) table[selector];
+ if (!m_table.TryGetValue(selector, out var list))
+ return null;
- return list == null ? null : (RecipientInformation) list[0];
+ return list[0];
}
/**
@@ -58,7 +57,7 @@ public RecipientInformation GetFirstRecipient(
*/
public int Count
{
- get { return all.Count; }
+ get { return m_all.Count; }
}
/**
@@ -66,9 +65,9 @@ public int Count
*
* @return a collection of recipients.
*/
- public ICollection GetRecipients()
+ public IList GetRecipients()
{
- return BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(all);
+ return new List(m_all);
}
/**
@@ -77,12 +76,12 @@ public ICollection GetRecipients()
* @param selector a recipient id to select against.
* @return a collection of RecipientInformation objects.
*/
- public ICollection GetRecipients(
- RecipientID selector)
+ public IList GetRecipients(RecipientID selector)
{
- IList list = (IList)table[selector];
+ if (!m_table.TryGetValue(selector, out var list))
+ return new List(0);
- return list == null ? BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList() : BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(list);
+ return new List(list);
}
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerId.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerId.cs
index f707a24..d58f685 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerId.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerId.cs
@@ -46,7 +46,7 @@ public override bool Equals(
return false;
return Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier)
- && BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
+ && Org.BouncyCastle.Utilities.Platform.Equals(SerialNumber, id.SerialNumber)
&& IssuersMatch(Issuer, id.Issuer);
}
}
diff --git a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerInformation.cs b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerInformation.cs
index 83e244e..c8b9f7a 100644
--- a/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerInformation.cs
+++ b/Assets/URS/Best HTTP/Source/SecureProtocol/cms/SignerInformation.cs
@@ -1,7 +1,7 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
@@ -258,10 +258,10 @@ public SignerInformationStore GetCounterSignatures()
Asn1.Cms.AttributeTable unsignedAttributeTable = UnsignedAttributes;
if (unsignedAttributeTable == null)
{
- return new SignerInformationStore(BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(0));
+ return new SignerInformationStore(new List(0));
}
- IList counterSignatures = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
+ var counterSignatures = new List