init commit

This commit is contained in:
2025-10-09 09:57:24 +09:00
commit 4d551bd74f
6636 changed files with 1218703 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
using System;
using Org.BouncyCastle.Asn1.X500;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.X509.SigI;
public class NameOrPseudonym : Asn1Encodable, IAsn1Choice
{
private readonly DirectoryString pseudonym;
private readonly DirectoryString surname;
private readonly Asn1Sequence givenName;
public DirectoryString Pseudonym => pseudonym;
public DirectoryString Surname => surname;
public static NameOrPseudonym GetInstance(object obj)
{
if (obj == null || obj is NameOrPseudonym)
{
return (NameOrPseudonym)obj;
}
if (obj is IAsn1String)
{
return new NameOrPseudonym(DirectoryString.GetInstance(obj));
}
if (obj is Asn1Sequence)
{
return new NameOrPseudonym((Asn1Sequence)obj);
}
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
}
public NameOrPseudonym(DirectoryString pseudonym)
{
this.pseudonym = pseudonym;
}
private NameOrPseudonym(Asn1Sequence seq)
{
if (seq.Count != 2)
{
throw new ArgumentException("Bad sequence size: " + seq.Count);
}
if (!(seq[0] is IAsn1String))
{
throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(seq[0]));
}
surname = DirectoryString.GetInstance(seq[0]);
givenName = Asn1Sequence.GetInstance(seq[1]);
}
public NameOrPseudonym(string pseudonym)
: this(new DirectoryString(pseudonym))
{
}
public NameOrPseudonym(DirectoryString surname, Asn1Sequence givenName)
{
this.surname = surname;
this.givenName = givenName;
}
public DirectoryString[] GetGivenName()
{
DirectoryString[] array = new DirectoryString[givenName.Count];
int num = 0;
foreach (object item in givenName)
{
array[num++] = DirectoryString.GetInstance(item);
}
return array;
}
public override Asn1Object ToAsn1Object()
{
if (pseudonym != null)
{
return pseudonym.ToAsn1Object();
}
return new DerSequence(surname, givenName);
}
}

View File

@@ -0,0 +1,119 @@
using System;
using System.Collections;
using Org.BouncyCastle.Asn1.X500;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.X509.SigI;
public class PersonalData : Asn1Encodable
{
private readonly NameOrPseudonym nameOrPseudonym;
private readonly BigInteger nameDistinguisher;
private readonly DerGeneralizedTime dateOfBirth;
private readonly DirectoryString placeOfBirth;
private readonly string gender;
private readonly DirectoryString postalAddress;
public NameOrPseudonym NameOrPseudonym => nameOrPseudonym;
public BigInteger NameDistinguisher => nameDistinguisher;
public DerGeneralizedTime DateOfBirth => dateOfBirth;
public DirectoryString PlaceOfBirth => placeOfBirth;
public string Gender => gender;
public DirectoryString PostalAddress => postalAddress;
public static PersonalData GetInstance(object obj)
{
if (obj == null || obj is PersonalData)
{
return (PersonalData)obj;
}
if (obj is Asn1Sequence)
{
return new PersonalData((Asn1Sequence)obj);
}
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
}
private PersonalData(Asn1Sequence seq)
{
if (seq.Count < 1)
{
throw new ArgumentException("Bad sequence size: " + seq.Count);
}
IEnumerator enumerator = seq.GetEnumerator();
enumerator.MoveNext();
nameOrPseudonym = NameOrPseudonym.GetInstance(enumerator.Current);
while (enumerator.MoveNext())
{
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.Current);
switch (instance.TagNo)
{
case 0:
nameDistinguisher = DerInteger.GetInstance(instance, isExplicit: false).Value;
break;
case 1:
dateOfBirth = DerGeneralizedTime.GetInstance(instance, isExplicit: false);
break;
case 2:
placeOfBirth = DirectoryString.GetInstance(instance, isExplicit: true);
break;
case 3:
gender = DerPrintableString.GetInstance(instance, isExplicit: false).GetString();
break;
case 4:
postalAddress = DirectoryString.GetInstance(instance, isExplicit: true);
break;
default:
throw new ArgumentException("Bad tag number: " + instance.TagNo);
}
}
}
public PersonalData(NameOrPseudonym nameOrPseudonym, BigInteger nameDistinguisher, DerGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, string gender, DirectoryString postalAddress)
{
this.nameOrPseudonym = nameOrPseudonym;
this.dateOfBirth = dateOfBirth;
this.gender = gender;
this.nameDistinguisher = nameDistinguisher;
this.postalAddress = postalAddress;
this.placeOfBirth = placeOfBirth;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
asn1EncodableVector.Add(nameOrPseudonym);
if (nameDistinguisher != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, new DerInteger(nameDistinguisher)));
}
if (dateOfBirth != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, dateOfBirth));
}
if (placeOfBirth != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 2, placeOfBirth));
}
if (gender != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 3, new DerPrintableString(gender, validate: true)));
}
if (postalAddress != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 4, postalAddress));
}
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,22 @@
namespace Org.BouncyCastle.Asn1.X509.SigI;
public sealed class SigIObjectIdentifiers
{
public static readonly DerObjectIdentifier IdSigI = new DerObjectIdentifier("1.3.36.8");
public static readonly DerObjectIdentifier IdSigIKP = new DerObjectIdentifier(string.Concat(IdSigI, ".2"));
public static readonly DerObjectIdentifier IdSigICP = new DerObjectIdentifier(string.Concat(IdSigI, ".1"));
public static readonly DerObjectIdentifier IdSigION = new DerObjectIdentifier(string.Concat(IdSigI, ".4"));
public static readonly DerObjectIdentifier IdSigIKPDirectoryService = new DerObjectIdentifier(string.Concat(IdSigIKP, ".1"));
public static readonly DerObjectIdentifier IdSigIONPersonalData = new DerObjectIdentifier(string.Concat(IdSigION, ".1"));
public static readonly DerObjectIdentifier IdSigICPSigConform = new DerObjectIdentifier(string.Concat(IdSigICP, ".1"));
private SigIObjectIdentifiers()
{
}
}