private void DoTestZeroLengthStrings() { // basic construction DerBitString s1 = new DerBitString(new byte[0], 0); // check GetBytes() s1.GetBytes(); // check encoding/decoding DerBitString derBit = (DerBitString)Asn1Object.FromByteArray(s1.GetEncoded()); if (!Arrays.AreEqual(s1.GetEncoded(), Hex.Decode("030100"))) { Fail("zero encoding wrong"); } try { new DerBitString(null, 1); Fail("exception not thrown"); } catch (ArgumentNullException) { } try { new DerBitString(new byte[0], 1); Fail("exception not thrown"); } catch (ArgumentException) { } try { new DerBitString(new byte[1], 8); Fail("exception not thrown"); } catch (ArgumentException) { } DerBitString s2 = new DerBitString(0); if (!Arrays.AreEqual(s1.GetEncoded(), s2.GetEncoded())) { Fail("zero encoding wrong"); } }
private void DoShouldFailOnExtraData() { // basic construction DerBitString s1 = new DerBitString(new byte[0], 0); Asn1Object.FromByteArray(s1.GetEncoded()); Asn1Object.FromByteArray(new BerSequence(s1).GetEncoded()); try { Asn1Object obj = Asn1Object.FromByteArray(Arrays.Concatenate(s1.GetEncoded(), new byte[1])); Fail("no exception"); } catch (IOException e) { //if (!"Extra data detected in stream".Equals(e.Message)) if (!"extra data found after object".Equals(e.Message)) { Fail("wrong exception"); } } }
public Asn1Object AddObject(string oid, byte[] enc) { DerObjectIdentifier o = new DerObjectIdentifier(oid); var der = DerBitString.GetInstance(o); DerBitString s1 = new DerBitString(enc, 0); Asn1Object encO = Asn1Object.FromByteArray(s1.GetEncoded()); return(encO); }