internal override void encode( DEROutputStream derOut) { OIDTokenizer tok = new OIDTokenizer(identifier); MemoryStream bOut = new MemoryStream(); DEROutputStream dOut = new DEROutputStream(bOut); string token = ""; try { token = tok.nextToken(); int first = System.Int32.Parse(token); token = tok.nextToken(); int second = System.Int32.Parse(token); writeField(bOut, first * 40 + second); } catch (Exception) { throw new Exception("Problems parsing identifier: " + identifier + ", " + token); } while (tok.hasMoreTokens()) { writeField(bOut, System.Int64.Parse(tok.nextToken())); } dOut.Close(); byte[] bytes = bOut.ToArray(); derOut.writeEncoded(ASN1Tags.OBJECT_IDENTIFIER, bytes); }
protected ASN1OctetString( ASN1Encodable obj) { try { MemoryStream bOut = new MemoryStream(); DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(obj); dOut.Close(); this.str = bOut.ToArray(); } catch (IOException e) { throw new ArgumentException("Error processing object : " + e.ToString()); } }
/* * 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) { MemoryStream bOut = new MemoryStream(); DEROutputStream dOut = new DEROutputStream(bOut); IEnumerator e = this.getObjects(); while (e.MoveNext()) { object obj = e.Current; dOut.writeObject(obj); } dOut.Close(); byte[] bytes = bOut.ToArray(); derOut.writeEncoded(ASN1Tags.SET | ASN1Tags.CONSTRUCTED, bytes); }
internal override void encode( DEROutputStream derOut) { if (!empty) { MemoryStream bOut = new MemoryStream(); DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(obj); dOut.Close(); byte[] bytes = bOut.ToArray(); if (explicitly) { derOut.writeEncoded((int)(ASN1Tags.CONSTRUCTED | ASN1Tags.TAGGED) | tagNo, bytes); } else { // // need to mark constructed types... // if ((bytes[0] & (byte)ASN1Tags.CONSTRUCTED) != 0) { bytes[0] = (byte)((int)(ASN1Tags.CONSTRUCTED | ASN1Tags.TAGGED) | tagNo); } else { bytes[0] = (byte)((int)(ASN1Tags.TAGGED) | tagNo); } derOut.Write(bytes, 0, bytes.Length); } } else { derOut.writeEncoded((int)(ASN1Tags.CONSTRUCTED | ASN1Tags.TAGGED) | tagNo, new byte[0]); } }