diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-02-03 15:19:53 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-02-03 15:19:53 +0700 |
commit | b3a8c7160ce31e8b4ef03dc862f1dc7cfa0dd480 (patch) | |
tree | 241a1811db06dc3ceed1e61281f5e6ecb6388058 /crypto/src/asn1/x9/X9ECParametersHolder.cs | |
parent | Remove Obsolete methods (diff) | |
download | BouncyCastle.NET-ed25519-b3a8c7160ce31e8b4ef03dc862f1dc7cfa0dd480.tar.xz |
Improve curve registry laziness
Diffstat (limited to 'crypto/src/asn1/x9/X9ECParametersHolder.cs')
-rw-r--r-- | crypto/src/asn1/x9/X9ECParametersHolder.cs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/crypto/src/asn1/x9/X9ECParametersHolder.cs b/crypto/src/asn1/x9/X9ECParametersHolder.cs index e802b738c..ea72cc6ac 100644 --- a/crypto/src/asn1/x9/X9ECParametersHolder.cs +++ b/crypto/src/asn1/x9/X9ECParametersHolder.cs @@ -1,25 +1,49 @@ +using Org.BouncyCastle.Math.EC; + namespace 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(); } } |