diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-20 14:07:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-20 14:07:11 +0700 |
commit | c17e29d769cf8a87402ff4d819d334389a7faca4 (patch) | |
tree | e60811ecfc45b6c229ce2e87d8b4a6db6d9f2da9 /crypto/src/asn1/crmf/EncryptedValue.cs | |
parent | added randomized signing (diff) | |
download | BouncyCastle.NET-ed25519-c17e29d769cf8a87402ff4d819d334389a7faca4.tar.xz |
Update Asn1.Cmp from bc-java
Diffstat (limited to '')
-rw-r--r-- | crypto/src/asn1/crmf/EncryptedValue.cs | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/crypto/src/asn1/crmf/EncryptedValue.cs b/crypto/src/asn1/crmf/EncryptedValue.cs index 7c5cf18b4..ad3a4c3f7 100644 --- a/crypto/src/asn1/crmf/EncryptedValue.cs +++ b/crypto/src/asn1/crmf/EncryptedValue.cs @@ -7,6 +7,17 @@ namespace Org.BouncyCastle.Asn1.Crmf public class EncryptedValue : Asn1Encodable { + public static EncryptedValue GetInstance(object obj) + { + if (obj is EncryptedValue) + return (EncryptedValue)obj; + + if (obj != null) + return new EncryptedValue(Asn1Sequence.GetInstance(obj)); + + return null; + } + private readonly AlgorithmIdentifier intendedAlg; private readonly AlgorithmIdentifier symmAlg; private readonly DerBitString encSymmKey; @@ -17,45 +28,31 @@ namespace Org.BouncyCastle.Asn1.Crmf private EncryptedValue(Asn1Sequence seq) { int index = 0; - while (seq[index] is Asn1TaggedObject) + while (seq[index++] is Asn1TaggedObject tObj) { - Asn1TaggedObject tObj = (Asn1TaggedObject)seq[index]; - switch (tObj.TagNo) { - case 0: - intendedAlg = AlgorithmIdentifier.GetInstance(tObj, false); - break; - case 1: - symmAlg = AlgorithmIdentifier.GetInstance(tObj, false); - break; - case 2: - encSymmKey = DerBitString.GetInstance(tObj, false); - break; - case 3: - keyAlg = AlgorithmIdentifier.GetInstance(tObj, false); - break; - case 4: - valueHint = Asn1OctetString.GetInstance(tObj, false); - break; + case 0: + intendedAlg = AlgorithmIdentifier.GetInstance(tObj, false); + break; + case 1: + symmAlg = AlgorithmIdentifier.GetInstance(tObj, false); + break; + case 2: + encSymmKey = DerBitString.GetInstance(tObj, false); + break; + case 3: + keyAlg = AlgorithmIdentifier.GetInstance(tObj, false); + break; + case 4: + valueHint = Asn1OctetString.GetInstance(tObj, false); + break; } - ++index; } encValue = DerBitString.GetInstance(seq[index]); } - public static EncryptedValue GetInstance(object obj) - { - if (obj is EncryptedValue) - return (EncryptedValue)obj; - - if (obj != null) - return new EncryptedValue(Asn1Sequence.GetInstance(obj)); - - return null; - } - public EncryptedValue( AlgorithmIdentifier intendedAlg, AlgorithmIdentifier symmAlg, @@ -65,9 +62,7 @@ namespace Org.BouncyCastle.Asn1.Crmf DerBitString encValue) { if (encValue == null) - { - throw new ArgumentNullException("encValue"); - } + throw new ArgumentNullException(nameof(encValue)); this.intendedAlg = intendedAlg; this.symmAlg = symmAlg; @@ -109,6 +104,7 @@ namespace Org.BouncyCastle.Asn1.Crmf /** * <pre> + * (IMPLICIT TAGS) * EncryptedValue ::= SEQUENCE { * intendedAlg [0] AlgorithmIdentifier OPTIONAL, * -- the intended algorithm for which the value will be used |