diff options
author | David Hook <dgh@cryptoworkshop.com> | 2015-11-13 16:55:57 +1100 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2015-11-13 16:55:57 +1100 |
commit | 044deb08952282ffeffb502279ec18965f672d38 (patch) | |
tree | 2e546d0367d687b2f0599929793f8c7c9872d6e9 /crypto/src/asn1 | |
parent | Review of culture-independent String comparison methods (diff) | |
download | BouncyCastle.NET-ed25519-044deb08952282ffeffb502279ec18965f672d38.tar.xz |
added GetInstance methods
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/x9/X962Parameters.cs | 35 | ||||
-rw-r--r-- | crypto/src/asn1/x9/X9ECParameters.cs | 15 |
2 files changed, 50 insertions, 0 deletions
diff --git a/crypto/src/asn1/x9/X962Parameters.cs b/crypto/src/asn1/x9/X962Parameters.cs index 5b7eaa1de..04a5c9cbe 100644 --- a/crypto/src/asn1/x9/X962Parameters.cs +++ b/crypto/src/asn1/x9/X962Parameters.cs @@ -1,3 +1,5 @@ +using System; + using Org.BouncyCastle.Asn1; namespace Org.BouncyCastle.Asn1.X9 @@ -7,6 +9,34 @@ namespace Org.BouncyCastle.Asn1.X9 { private readonly Asn1Object _params; + public static X962Parameters GetInstance( + object obj) + { + if (obj == null || obj is X962Parameters) + { + return (X962Parameters)obj; + } + + if (obj is Asn1Object) + { + return new X962Parameters((Asn1Object)obj); + } + + if (obj is byte[]) + { + try + { + return new X962Parameters(Asn1Object.FromByteArray((byte[])obj)); + } + catch (Exception e) + { + throw new ArgumentException("unable to parse encoded data: " + e.Message, e); + } + } + + throw new ArgumentException("unknown object in getInstance()"); + } + public X962Parameters( X9ECParameters ecParameters) { @@ -30,6 +60,11 @@ namespace Org.BouncyCastle.Asn1.X9 get { return (_params is DerObjectIdentifier); } } + public bool IsImplicitlyCA + { + get { return (_params is Asn1Null); } + } + public Asn1Object Parameters { get { return _params; } diff --git a/crypto/src/asn1/x9/X9ECParameters.cs b/crypto/src/asn1/x9/X9ECParameters.cs index 2b6b14bcb..0fa343768 100644 --- a/crypto/src/asn1/x9/X9ECParameters.cs +++ b/crypto/src/asn1/x9/X9ECParameters.cs @@ -20,6 +20,21 @@ namespace Org.BouncyCastle.Asn1.X9 private BigInteger h; private byte[] seed; + public static X9ECParameters GetInstance(Object obj) + { + if (obj is X9ECParameters) + { + return (X9ECParameters)obj; + } + + if (obj != null) + { + return new X9ECParameters(Asn1Sequence.GetInstance(obj)); + } + + return null; + } + public X9ECParameters( Asn1Sequence seq) { |