internal override void Encode( DerOutputStream derOut) { OidTokenizer tok = new OidTokenizer(identifier); MemoryStream bOut = new MemoryStream(); DerOutputStream dOut = new DerOutputStream(bOut); string token = tok.NextToken(); int first = int.Parse(token); token = tok.NextToken(); int second = int.Parse(token); WriteField(bOut, first * 40 + second); while (tok.HasMoreTokens) { token = tok.NextToken(); if (token.Length < 18) { WriteField(bOut, Int64.Parse(token)); } else { WriteField(bOut, new BigInteger(token)); } } dOut.Close(); derOut.WriteEncoded(Asn1Tags.ObjectIdentifier, bOut.ToArray()); }
internal override void Encode(DerOutputStream derOut) { MemoryStream memoryStream = new MemoryStream(); DerOutputStream derOutputStream = new DerOutputStream(memoryStream); foreach (Asn1Encodable obj in this) { derOutputStream.WriteObject(obj); } derOutputStream.Close(); byte[] bytes = memoryStream.ToArray(); derOut.WriteEncoded(48, bytes); }
/* * A note on the implementation: * <p> * As Der requires the constructed, definite-length model to * be used for structured types, this varies slightly from the * ASN.1 descriptions given. Rather than just outputing Sequence, * we also have to specify Constructed, and the objects length. */ internal override void Encode( DerOutputStream derOut) { MemoryStream bOut = new MemoryStream(); DerOutputStream dOut = new DerOutputStream(bOut); foreach (object obj in this) { dOut.WriteObject(obj); } dOut.Close(); byte[] bytes = bOut.ToArray(); derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes); }
/* * A note on the implementation: * <p> * As Der requires the constructed, definite-length model to * be used for structured types, this varies slightly from the * ASN.1 descriptions given. Rather than just outputing Sequence, * we also have to specify Constructed, and the objects length. */ internal override void Encode( DerOutputStream derOut) { // TODO Intermediate buffer could be avoided if we could calculate expected length MemoryStream bOut = new MemoryStream(); DerOutputStream dOut = new DerOutputStream(bOut); foreach (Asn1Encodable obj in this) { dOut.WriteObject(obj); } dOut.Close(); byte[] bytes = bOut.ToArray(); derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes); }
/* * A note on the implementation: * <p> * As Der requires the constructed, definite-length model to * be used for structured types, this varies slightly from the * ASN.1 descriptions given. Rather than just outputing Set, * we also have to specify Constructed, and the objects length. */ internal override void Encode( DerOutputStream derOut) { // TODO Intermediate buffer could be avoided if we could calculate expected length MemoryStream bOut = new MemoryStream(); DerOutputStream dOut = new DerOutputStream(bOut); foreach (Asn1Encodable obj in this) { dOut.WriteObject(obj); } dOut.Close(); byte[] bytes = bOut.ToArray(); derOut.WriteEncoded(Asn1Tags.Set | Asn1Tags.Constructed, bytes); }
// : base("X.509") /** * Creates a CertPath of the specified type. * This constructor is protected because most users should use * a CertificateFactory to create CertPaths. * * @param type the standard name of the type of Certificatesin this path **/ public PkixCertPath( Stream inStream, String encoding) { try { if (encoding.ToUpper().Equals("PkiPath".ToUpper())) { Asn1InputStream derInStream = new Asn1InputStream(inStream); Asn1Object derObject = derInStream.ReadObject(); if (!(derObject is Asn1Sequence)) { throw new CertificateException( "input stream does not contain a ASN1 SEQUENCE while reading PkiPath encoded data to load CertPath"); } IEnumerator e = ((Asn1Sequence)derObject).GetEnumerator(); Stream certInStream; MemoryStream outStream; DerOutputStream derOutStream; certificates = new ArrayList(); while (e.MoveNext()) { outStream = new MemoryStream(); derOutStream = new DerOutputStream(outStream); derOutStream.WriteObject((Asn1Encodable)e.Current); derOutStream.Close(); certInStream = new MemoryStream(outStream.ToArray(), false); certificates.Insert(0, new X509CertificateParser().ReadCertificate(certInStream)); } } else if (encoding.ToUpper().Equals("PKCS7") || encoding.ToUpper().Equals("PEM")) { inStream = new BufferedStream(inStream); certificates = new ArrayList(); X509CertificateParser certParser = new X509CertificateParser(); X509Certificate cert = null; while ((cert = certParser.ReadCertificate(inStream)) != null) { certificates.Add(cert); } } else { throw new CertificateException("unsupported encoding: " + encoding); } } catch (IOException ex) { throw new CertificateException( "IOException throw while decoding CertPath:\n" + ex.ToString()); } this.certificates = SortCerts(certificates); }