void CAsn1PerOctetString::DecodeL(const TDesC8& aBuf, const TInt aStartBit, const TBool aLengthIsVariable, const TBool aLengthIsConstrained, const TInt aMinLength, const TInt aMaxLength, const TBool aIsExtensible, const TBool /*aIsPadded*/, TBool& aIsExtended, TInt& aBitsDecoded, RBuf8& aDecodedBuf) { TInt currentBitPos=aStartBit; TInt bitDecoded=0; aBitsDecoded=0; aIsExtended=EFalse; TInt stringLen=0; CAsn1PerUtil::DecodeStringEBitAndLengthL(aBuf, currentBitPos, aLengthIsVariable, aLengthIsConstrained, aMinLength, aMaxLength, aIsExtensible, aIsExtended, bitDecoded, stringLen); currentBitPos+=bitDecoded; aBitsDecoded+=bitDecoded; bitDecoded=0; //check if the input buffer is long enough if (currentBitPos+stringLen*8>aBuf.Length()*8) { User::Leave(KErrUnderflow); } //Finally, decode the string content for cases aDecodedBuf.ReAllocL(stringLen); aDecodedBuf.SetLength(stringLen); aDecodedBuf.FillZ(); TInt stringBitLength=stringLen*8; //Copy the String to the Dest Buffer . TInt destBitNum=8; TInt destOctetNum=0; //Copy ... CAsn1PerUtil::CopyDataTrunkL(aBuf, currentBitPos, stringBitLength, aDecodedBuf, destOctetNum, destBitNum); aBitsDecoded+=stringBitLength; }
LOCAL_C TInt CreateVerifyFileX(const TDesC& aFileName, TInt aSize, RFs& aFs, TInt aPattern) // // Create and verify a file. // { // Note, the directory structure is provided by MakeFileName(). Hence it // is assumed at this point that the path to the file exists already. RFile file; TInt r; r = file.Replace(aFs, aFileName, EFileWrite); if (r!=KErrNone) { LogError( r, KReplace, aFileName, EFileWrite, 0 ); return(r); } // Grow it to the specified size by writing a pattern buffer to it // Alternate the pattern buffer each time RBuf8 wBuf; r = wBuf.CreateMax(KCreateFileBufSize); if(r != KErrNone) { LogError(r, KMemory, aFileName, 0, 0, __LINE__); wBuf.Close(); file.Close(); return(r); } TInt i; if (aPattern) { // ascending pattern for (i = 0; i < KCreateFileBufSize; i++) { wBuf[i] = (TUint8) i; } } else { // descending pattern for (i = 0; i < KCreateFileBufSize; i++) { wBuf[i] = (TUint8) ((KCreateFileBufSize - 1) - i); } } TInt pos; TInt chunkSize; TInt sectorCount = 0; for (pos = 0; pos < aSize; pos += chunkSize) { wBuf[0]=(TUint8)i; // Insert sector count chunkSize = Min((aSize-pos), KCreateFileBufSize); r = file.Write(pos, wBuf, chunkSize); if (r != KErrNone) { LogError(r, KWrite, aFileName, pos, chunkSize, __LINE__); file.Close(); wBuf.Close(); return(r); } sectorCount++; } // Flush it r=file.Flush(); if (r!=KErrNone) { LogError( r, KFlush, aFileName, 0, 0, __LINE__); file.Close(); wBuf.Close(); return(r); } // Test still works if this is commented out just doesn't verify // Read back and verify it RBuf8 rBuf; r = rBuf.CreateMax(KCreateFileBufSize); if(r != KErrNone) { LogError( r, KMemory, aFileName, 0, 0, __LINE__); file.Close(); wBuf.Close(); rBuf.Close(); return(KErrGeneral); } for (pos = 0;pos < aSize; pos += chunkSize) { chunkSize = Min((aSize-pos), KCreateFileBufSize); r = file.Read(pos, rBuf, chunkSize); if (r != KErrNone) { LogError(r, KRead, aFileName, pos, 0, __LINE__); file.Close(); wBuf.Close(); rBuf.Close(); return(r); } wBuf[0] = (TUint8) i; // Insert sector count wBuf.SetLength(chunkSize); r = rBuf.Compare(wBuf); if (r != 0) { LogError(r, KDataCompare, aFileName, 0, 0, __LINE__); file.Close(); wBuf.Close(); rBuf.Close(); return(KErrGeneral); } } // file.Close(); wBuf.Close(); rBuf.Close(); return(KErrNone); }