public bool isValidTLVPack(byte[] apcBuf, int aiUsedSize, int offset) { if (apcBuf != null) { if (aiUsedSize < this.m_ptHeader.getSize()) { return(false); } TLVPackHeader header = new TLVPackHeader { h_pcBuf = apcBuf, offset = offset }; if (header.getMagic() != 0x81) { return(false); } int aiSize = aiUsedSize - header.getSize(); if (header.getUsedSize() != aiSize) { return(false); } byte[] buffer = TLVUtil.getCheckSum(apcBuf, offset + header.getSize(), aiSize); byte[] buffer2 = header.getCheckSum(); if ((buffer[0] != buffer2[0]) || (buffer[1] != buffer2[1])) { return(false); } if (aiSize == 0) { return(true); } FixedSizeTLVBody body = new FixedSizeTLVBody(); tVariableSizeTLVItem item = new tVariableSizeTLVItem(); TLVBody body2 = null; if (header.getMode() == 0) { body2 = body; } else if (header.getMode() == 1) { body2 = item; } else { return(false); } if (body2.MapTo(apcBuf, offset + aiUsedSize, offset + header.getSize())) { while (body2.iNextOffset != 0) { if (!body2.MapTo(apcBuf, offset + aiUsedSize, body2.iNextOffset)) { return(false); } } return(true); } } return(false); }
public int getNestedTLVBuf(int aiType, TLVPack appoVal) { if (appoVal == null) { return(-4); } if (this.m_iUsedSize == this.m_ptHeader.getSize()) { return(-6); } FixedSizeTLVBody body = new FixedSizeTLVBody(); tVariableSizeTLVItem item = new tVariableSizeTLVItem(); TLVBody body2 = null; if (this.m_eDefaultMode == 0) { body2 = body; } else if (this.m_eDefaultMode == 1) { body2 = item; } else { return(-8); } if (body2.MapTo(this.m_pcBuf, this.m_iUsedSize, this.m_ptHeader.getSize())) { while ((body2.iType != aiType) && (body2.iNextOffset != 0)) { if (!body2.MapTo(this.m_pcBuf, this.m_iUsedSize, body2.iNextOffset)) { return(-5); } } if (body2.iType != aiType) { return(-6); } if ((body2.iLength > 0) && (0 > appoVal.CopyFrom(body2.pcValPtr, body2.iLength, body2.pcValPtrOffset))) { appoVal.m_pcBuf = null; appoVal.m_ptHeader.h_pcBuf = null; return(-5); } return(0); } return(-5); }
public int getByteArray(int aiType, ref byte[] apoVal) { if (this.m_iUsedSize == this.m_ptHeader.getSize()) { return(-6); } FixedSizeTLVBody body = new FixedSizeTLVBody(); tVariableSizeTLVItem item = new tVariableSizeTLVItem(); TLVBody body2 = null; if (this.m_eDefaultMode == 0) { body2 = body; } else if (this.m_eDefaultMode == 1) { body2 = item; } else { return(-8); } if (body2.MapTo(this.m_pcBuf, this.m_iUsedSize, this.m_ptHeader.getSize())) { while ((body2.iType != aiType) && (body2.iNextOffset != 0)) { if (!body2.MapTo(this.m_pcBuf, this.m_iUsedSize, body2.iNextOffset)) { return(-5); } } if (body2.iType != aiType) { return(-6); } apoVal = new byte[body2.iLength]; Buffer.BlockCopy(body2.pcValPtr, body2.pcValPtrOffset, apoVal, 0, body2.iLength); return(0); } return(-5); }