diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-10 21:21:34 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-10 21:21:34 +0700 |
commit | a6593fddf3d6ddd81fd53caa4a7b983564d3ba9f (patch) | |
tree | 3bd7e50b85ad157fd14998f860e8f0e739bd3b10 | |
parent | Update CHACHA20_POLY1305 out of draft range (diff) | |
download | BouncyCastle.NET-ed25519-a6593fddf3d6ddd81fd53caa4a7b983564d3ba9f.tar.xz |
Misc. asn1 changes from Java API
-rw-r--r-- | crypto/src/asn1/pkcs/CertificationRequest.cs | 3 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/CertificationRequestInfo.cs | 43 |
2 files changed, 30 insertions, 16 deletions
diff --git a/crypto/src/asn1/pkcs/CertificationRequest.cs b/crypto/src/asn1/pkcs/CertificationRequest.cs index 35bdd56eb..98caa2268 100644 --- a/crypto/src/asn1/pkcs/CertificationRequest.cs +++ b/crypto/src/asn1/pkcs/CertificationRequest.cs @@ -47,7 +47,8 @@ namespace Org.BouncyCastle.Asn1.Pkcs this.sigBits = signature; } - public CertificationRequest( + [Obsolete("Use 'GetInstance' instead")] + public CertificationRequest( Asn1Sequence seq) { if (seq.Count != 3) diff --git a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs index d57753235..6d980131e 100644 --- a/crypto/src/asn1/pkcs/CertificationRequestInfo.cs +++ b/crypto/src/asn1/pkcs/CertificationRequestInfo.cs @@ -1,7 +1,6 @@ using System; using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Pkcs { @@ -31,20 +30,13 @@ namespace Org.BouncyCastle.Asn1.Pkcs internal SubjectPublicKeyInfo subjectPKInfo; internal Asn1Set attributes; - public static CertificationRequestInfo GetInstance( - object obj) + public static CertificationRequestInfo GetInstance(object obj) { if (obj is CertificationRequestInfo) - { - return (CertificationRequestInfo) obj; - } - - if (obj is Asn1Sequence) - { - return new CertificationRequestInfo((Asn1Sequence) obj); - } - - throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj"); + return (CertificationRequestInfo)obj; + if (obj != null) + return new CertificationRequestInfo(Asn1Sequence.GetInstance(obj)); + return null; } public CertificationRequestInfo( @@ -56,7 +48,9 @@ namespace Org.BouncyCastle.Asn1.Pkcs this.subjectPKInfo = pkInfo; this.attributes = attributes; - if (subject == null || version == null || subjectPKInfo == null) + ValidateAttributes(attributes); + + if (subject == null || version == null || subjectPKInfo == null) { throw new ArgumentException( "Not all mandatory fields set in CertificationRequestInfo generator."); @@ -81,7 +75,9 @@ namespace Org.BouncyCastle.Asn1.Pkcs attributes = Asn1Set.GetInstance(tagobj, false); } - if (subject == null || version == null || subjectPKInfo == null) + ValidateAttributes(attributes); + + if (subject == null || version == null || subjectPKInfo == null) { throw new ArgumentException( "Not all mandatory fields set in CertificationRequestInfo generator."); @@ -120,5 +116,22 @@ namespace Org.BouncyCastle.Asn1.Pkcs return new DerSequence(v); } + + private static void ValidateAttributes(Asn1Set attributes) + { + if (attributes == null) + return; + + foreach (Asn1Encodable ae in attributes) + { + Asn1Object obj = ae.ToAsn1Object(); + AttributePkcs attr = AttributePkcs.GetInstance(obj); + if (attr.AttrType.Equals(PkcsObjectIdentifiers.Pkcs9AtChallengePassword)) + { + if (attr.AttrValues.Count != 1) + throw new ArgumentException("challengePassword attribute must have one value"); + } + } + } } } |