diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 19:42:44 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 19:42:44 +0700 |
commit | 34404b3e7cfd8a1e21591eea2c7812b5805d191f (patch) | |
tree | 1b25eb3a89062993170eeeebc2356fc874a632c8 /crypto/src | |
parent | Reformat (diff) | |
download | BouncyCastle.NET-ed25519-34404b3e7cfd8a1e21591eea2c7812b5805d191f.tar.xz |
BMA-118
Handle null properly in AuthorityInformationAccess.GetInstance
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/asn1/x509/AuthorityInformationAccess.cs | 183 |
1 files changed, 88 insertions, 95 deletions
diff --git a/crypto/src/asn1/x509/AuthorityInformationAccess.cs b/crypto/src/asn1/x509/AuthorityInformationAccess.cs index 3eeba8cd2..9329e2b98 100644 --- a/crypto/src/asn1/x509/AuthorityInformationAccess.cs +++ b/crypto/src/asn1/x509/AuthorityInformationAccess.cs @@ -7,99 +7,92 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.X509 { - /** - * The AuthorityInformationAccess object. - * <pre> - * id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 } - * - * AuthorityInfoAccessSyntax ::= - * Sequence SIZE (1..MAX) OF AccessDescription - * AccessDescription ::= Sequence { - * accessMethod OBJECT IDENTIFIER, - * accessLocation GeneralName } - * - * id-ad OBJECT IDENTIFIER ::= { id-pkix 48 } - * id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 } - * id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 } - * </pre> - */ - public class AuthorityInformationAccess - : Asn1Encodable - { - private readonly AccessDescription[] descriptions; - - public static AuthorityInformationAccess GetInstance( - object obj) - { - if (obj is AuthorityInformationAccess) - return (AuthorityInformationAccess) obj; - - if (obj is Asn1Sequence) - return new AuthorityInformationAccess((Asn1Sequence) obj); - - if (obj is X509Extension) - return GetInstance(X509Extension.ConvertValueToObject((X509Extension) obj)); - - throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj"); - } - - private AuthorityInformationAccess( - Asn1Sequence seq) - { - if (seq.Count < 1) - throw new ArgumentException("sequence may not be empty"); - - this.descriptions = new AccessDescription[seq.Count]; - - for (int i = 0; i < seq.Count; ++i) - { - descriptions[i] = AccessDescription.GetInstance(seq[i]); - } - } - - /** - * create an AuthorityInformationAccess with the oid and location provided. - */ - [Obsolete("Use version taking an AccessDescription instead")] - public AuthorityInformationAccess( - DerObjectIdentifier oid, - GeneralName location) - { - this.descriptions = new AccessDescription[]{ new AccessDescription(oid, location) }; - } - - public AuthorityInformationAccess( - AccessDescription description) - { - this.descriptions = new AccessDescription[]{ description }; - } - - public AccessDescription[] GetAccessDescriptions() - { - return (AccessDescription[]) descriptions.Clone(); - } - - public override Asn1Object ToAsn1Object() - { - return new DerSequence(descriptions); - } - - public override string ToString() - { - StringBuilder buf = new StringBuilder(); - string sep = Platform.NewLine; - - buf.Append("AuthorityInformationAccess:"); - buf.Append(sep); - - foreach (AccessDescription description in descriptions) - { - buf.Append(" "); - buf.Append(description); - buf.Append(sep); - } - - return buf.ToString(); - } - } + /** + * The AuthorityInformationAccess object. + * <pre> + * id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 } + * + * AuthorityInfoAccessSyntax ::= + * Sequence SIZE (1..MAX) OF AccessDescription + * AccessDescription ::= Sequence { + * accessMethod OBJECT IDENTIFIER, + * accessLocation GeneralName } + * + * id-ad OBJECT IDENTIFIER ::= { id-pkix 48 } + * id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 } + * id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 } + * </pre> + */ + public class AuthorityInformationAccess + : Asn1Encodable + { + private readonly AccessDescription[] descriptions; + + public static AuthorityInformationAccess GetInstance(object obj) + { + if (obj is AuthorityInformationAccess) + return (AuthorityInformationAccess)obj; + if (obj == null) + return null; + return new AuthorityInformationAccess(Asn1Sequence.GetInstance(obj)); + } + + private AuthorityInformationAccess( + Asn1Sequence seq) + { + if (seq.Count < 1) + throw new ArgumentException("sequence may not be empty"); + + this.descriptions = new AccessDescription[seq.Count]; + + for (int i = 0; i < seq.Count; ++i) + { + descriptions[i] = AccessDescription.GetInstance(seq[i]); + } + } + + public AuthorityInformationAccess( + AccessDescription description) + { + this.descriptions = new AccessDescription[]{ description }; + } + + /** + * create an AuthorityInformationAccess with the oid and location provided. + */ + public AuthorityInformationAccess(DerObjectIdentifier oid, GeneralName location) + : this(new AccessDescription(oid, location)) + { + } + + public AccessDescription[] GetAccessDescriptions() + { + return (AccessDescription[])descriptions.Clone(); + } + + public override Asn1Object ToAsn1Object() + { + return new DerSequence(descriptions); + } + + public override string ToString() + { + //return "AuthorityInformationAccess: Oid(" + this.descriptions[0].AccessMethod.Id + ")"; + + StringBuilder buf = new StringBuilder(); + string sep = Platform.NewLine; + + buf.Append("AuthorityInformationAccess:"); + buf.Append(sep); + + foreach (AccessDescription description in descriptions) + { + buf.Append(" "); + buf.Append(description); + buf.Append(sep); + } + + return buf.ToString(); + } + } } |