diff options
Diffstat (limited to 'crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs')
-rw-r--r-- | crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs index 4cd568e81..4530b18b8 100644 --- a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs +++ b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs @@ -38,27 +38,22 @@ namespace Org.BouncyCastle.Crmf { IMacFactory fact = generator.Build(password); - byte[] d = _pubKeyInfo.GetDerEncoded(); - - IStreamCalculator<IBlockResult> calc = fact.CreateCalculator(); - using (var stream = calc.Stream) - { - stream.Write(d, 0, d.Length); - } + return ImplSetPublicKeyMac(fact); + } - this._publicKeyMAC = new PKMacValue( - (AlgorithmIdentifier)fact.AlgorithmDetails, - new DerBitString(calc.GetResult().Collect())); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public ProofOfPossessionSigningKeyBuilder SetPublicKeyMac(PKMacBuilder generator, ReadOnlySpan<char> password) + { + IMacFactory fact = generator.Build(password); - return this; + return ImplSetPublicKeyMac(fact); } +#endif public PopoSigningKey Build(ISignatureFactory signer) { if (_name != null && _publicKeyMAC != null) - { throw new InvalidOperationException("name and publicKeyMAC cannot both be set."); - } PopoSigningKeyInput popo; @@ -86,5 +81,22 @@ namespace Org.BouncyCastle.Crmf return new PopoSigningKey(popo, (AlgorithmIdentifier)signer.AlgorithmDetails, new DerBitString(signature)); } + + private ProofOfPossessionSigningKeyBuilder ImplSetPublicKeyMac(IMacFactory fact) + { + byte[] d = _pubKeyInfo.GetDerEncoded(); + + IStreamCalculator<IBlockResult> calc = fact.CreateCalculator(); + using (var stream = calc.Stream) + { + stream.Write(d, 0, d.Length); + } + + this._publicKeyMAC = new PKMacValue( + (AlgorithmIdentifier)fact.AlgorithmDetails, + new DerBitString(calc.GetResult().Collect())); + + return this; + } } } |