public ASNNode[] getChilds() { ASNNode[] ch = new ASNNode[childs.Count]; for (int i = 0; i < childs.Count; i++) { ch[i] = (ASNNode)childs[i]; } return(ch); }
public static ArrayList parse(byte[] data) { ArrayList ret = new ArrayList(); bool reachedEnd = false; int start = 0; while (!reachedEnd) { ASNNode node = new ASNNode(); node.Type = data[start]; int len = Convert.ToInt32(data[start + 1]); int offset = 1; int length = 0; if ((len & 0x80) == 0x80) { len = len - 0x80; offset += 1 + len; for (int i = 0; i < len; i++) { length *= 0x100; length += Convert.ToInt32(data[start + 2 + i]); } } else { offset += 1; length = Convert.ToInt32(data[start + 1]); } byte[] tmp = new byte[length]; MemoryStream st = new MemoryStream(); st.Write(data, start + offset, length); st.Position = 0; st.Read(tmp, 0, length); node.setValue(tmp); if (tmp.Length > 0) { if (node.Type == AsnTag.SEQUENCE || node.Type == AsnTag.CONTEXT_SPECIFIC1 || node.Type == AsnTag.SET || node.Type == AsnTag.CONTEXT_SPECIFIC) { node.childs = ASNNode.parse(tmp); } } ret.Add(node); start += offset + tmp.Length; if (start >= data.Length) { reachedEnd = true; } } return(ret); }
public byte[] get() { if (rawData != null) { return(rawData); } int innerLength = this.getLength(false); byte[] len = ASNNode.getLengthBytes(innerLength); if (childs.Count > 0) { MemoryStream data2 = new MemoryStream(); foreach (ASNNode child in childs) { byte[] childBytes = child.get(); data2.Write(childBytes, 0, childBytes.Length); } MemoryStream ret = new MemoryStream(); ret.WriteByte(Type); ret.Write(len, 0, len.Length); data = new byte[data2.Length]; data2.Position = 0; data2.Read(data, 0, (int)data2.Length); ret.Write(data, 0, (int)data2.Length); byte[] ret1 = new byte[ret.Length]; ret.Position = 0; ret.Read(ret1, 0, (int)ret1.Length); return(ret1); } else { if (Type == AsnTag.UTF8_STRING) { int xx = 1; } MemoryStream ret = new MemoryStream(); ret.WriteByte(Type); ret.Write(len, 0, len.Length); if (data != null) { ret.Write(data, 0, (int)data.Length); } byte[] ret1 = new byte[ret.Length]; ret.Position = 0; ret.Read(ret1, 0, (int)ret1.Length); return(ret1); } }
public int getLength(bool includeHeader) { if (rawData != null) { return(rawData.Length); } int innerLength = 0; int ret = 0; if (data != null) { innerLength += data.Length; } foreach (ASNNode node in childs) { int l = node.getLength(); innerLength += l; if (innerLength == 0x0000011d) { int xx = 1; } } if (includeHeader) { ret += 1; byte[] len = ASNNode.getLengthBytes(innerLength); ret += len.Length; } ret += innerLength; if (ret == 199) { int zz = 1; } return(ret); }
public void AppendChild(ASNNode child) { childs.Add(child); }