// ----------------------------------------------------------------------------- // CExprUDPMsg::HandleReceivedDataL() // ----------------------------------------------------------------------------- // TBool CExprUDPMsg::HandleRecievedMsgL( TDes8& aData, TInt& aStartPos, TInt& aLength ) { // Check if the prefix matches aStartPos = aData.Find( KUDPPrefix ); if ( aStartPos != KErrNotFound ) { // Found a matching prefix // Let the observer know iObserver->FrameStarted(); TPtr8 dataToParse( aData.MidTPtr( aStartPos ) ); TInt err = TryParsingL( dataToParse, aLength ); if ( err != KErrNone ) { // corrupted data in the frame iObserver->ProtocolErrorL( err, aData ); // delete the corrupted data aData.SetLength( 0 ); } return ETrue; } else { return EFalse; } }
void CSdpPDUHandler::CompleteOPL(TDes8& aPdu, const TDesC8& aWritePdu, const TInt aMaxAttrCount) /** Verifies the size of the response parameters and writes out correct length for the attributes. @verbatim response descriptor DesC written area (attributes) DesC maximum byte count TInt @endverbatim Method will leave if response is bigger than requested or allowed for. Returns nothing **/ { TUint16 finalLength = (TUint16)aWritePdu.Length(); if (finalLength > aMaxAttrCount) User::Leave(KErrNoMemory); aPdu.SetLength(KRspAttributeCountSize + finalLength + KContStateHeader); BigEndian::Put16(&aPdu[KRspAttrCountOffset], finalLength); // now need to update the DES size if (iDesSize == 3) { BigEndian::Put16(&aPdu[KRspAttributeListOffset+1], (unsigned short)(finalLength-iDesSize)); } else if (iDesSize == 2) { if (finalLength > 0xff) User::Leave(KErrNoMemory); aPdu[KRspAttributeListOffset+1] = (unsigned char)((finalLength&0xff)-iDesSize); } else User::Leave(KErrUnknown); // perhaps this should be a panic aPdu[aPdu.Length()-1] = 0; // FIXME: Put contState here }
TInt RecvLine(RTest &aTest, TDes8 &aBuf, RSocket &aSock) { TInt offset=0; TText ch=0; do { TPtr8 ptr(NULL, 0); TSockXfrLength len; TRequestStatus stat; ptr.Set((TUint8 *)aBuf.Ptr()+offset, aBuf.Length()-offset, aBuf.Length()-offset); aSock.RecvOneOrMore(ptr,0,stat,len); User::WaitForRequest(stat); aTest(stat==KErrNone); TInt length=len(); TInt n=0; while (length--) { ch = *(ptr.Ptr()+n); if (ch=='\r' || ch=='\n') break; ++offset; ++n; } } while (ch!='\r' && ch!='\n' ); aBuf.SetLength(offset); return offset; }
/** Converts a buffer containing string of the hexadecimal characters, representing the binary data, into this binary data! @param aSrc The buffer containing text representation. @param aDst Binary data will be written to this buffer. */ void ConvertTextToBinary(const TDesC& aSrc, TDes8& aDst) { // Check that the ASCII PDU length is even __ASSERT_ALWAYS((aSrc.Length()&0x1)==0x0, SimPanic(EInvalidParameterFormatInConfigFile)); aDst.SetLength(aSrc.Length() / 2); for (TInt ii = 0; ii < aSrc.Length(); ii += 2) { TInt val = 0; if ((aSrc[ii] >= '0') && (aSrc[ii] <= '9')) { val = ((aSrc[ii] - '0') << 4); } else if ((aSrc[ii] >= 'A') && (aSrc[ii] <= 'F')) { val = ((aSrc[ii] - 'A' + 10) << 4); } if ((aSrc[ii+1] >= '0') && (aSrc[ii+1] <= '9')) { val += (aSrc[ii+1] - '0'); } else if ((aSrc[ii+1] >= 'A') && (aSrc[ii+1] <= 'F')) { val += (aSrc[ii+1] - 'A' + 10); } aDst[ii/2] = (TUint8) val; } }
/** Reads data from the stream buffer into the specified descriptor. This function is called by ReadL(TDes8&,TInt,TRequestStatus&). This implementation deals with the request synchronously, and completes the request with KErrNone. Other implementations may choose to deal with this in a true asynchronous manner. In addition, the read operation itself uses the DoReadL(TAny*,TInt) variant. @param aDes The target descriptor for the data read from the stream buffer. On return, the length of the descriptor is set to the number of bytes read from the stream buffer. @param aMaxLength The maximum number of bytes to be read. This value must not be greater than the maximum length of the descriptor, otherwise the function raises a STORE-Stream 2 panic. @param aStatus The request status that indicates the completion status of this asynchronous request. @return The maximum number of bytes to be read, as used in this request. This implementation uses, and returns, the value supplied in aMaxLength. Other implementations may choose to use a different value. @see MStreamBuf::ReadL() */ EXPORT_C TInt MStreamBuf::DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus) { __ASSERT_DEBUG(aMaxLength<=aDes.MaxLength(),Panic(EStreamReadBeyondEnd)); aDes.SetLength(DoReadL((TUint8*)aDes.Ptr(),aMaxLength)); TRequestStatus* stat=&aStatus; User::RequestComplete(stat,KErrNone); return aMaxLength; }
void CPBEncryptSet::DecryptMasterKeyL(TDes8& aMasterKey) const { CPBDecryptorElement* decryptor = CPBDecryptorElement::NewLC( iData->EncryptParms().Cipher(), *iEncryptKey, iData->EncryptParms().IV()); aMasterKey.SetLength(0); decryptor->Process(*iEncryptedMasterKey, aMasterKey); CleanupStack::PopAndDestroy(decryptor); }
TInt CBulkOnlyTransport::SendDataRxCmdL(const MClientCommandServiceReq* aCommand, TDes8& aCopyBuf, TInt& aLen) { __MSFNLOG TInt r = KErrNone; SendCbwL(aCommand, TBotCbw::EDataIn, aLen); // store initial length as data is appended to the buffer TInt startPos = aCopyBuf.Length(); TInt len = aLen; while (len) { if(len > KResponsePacketSize) iBulkDataTd.SaveData(KResponsePacketSize); else iBulkDataTd.SaveData(len); iBulkPipeIn.Transfer(iBulkDataTd, iStatus); User::WaitForRequest(iStatus); r = iStatus.Int(); if (r != KErrNone) { if (r == KErrUsbStalled) { __BOTPRINT(_L("SendDataRxCmdL ClearRemoteStall")); iBulkPipeIn.ClearRemoteStall(); #ifdef MASSSTORAGE_PUBLISHER TMsPublisher publisher(TMsPublisher::KStallProperty); #endif break; } DoResetRecovery(); __BOTPRINT1(_L("Usb transfer error %d"),r); User::Leave(KErrGeneral); } TPtrC8 data = iBulkDataTd.Buffer(); aCopyBuf.Append(data.Ptr(), data.Length()); if(len > KResponsePacketSize) len -= KResponsePacketSize; else len = 0; } ReceiveCswL(); TUint32 lenReceived = 0; r = ProcessInTransferL(lenReceived); aLen = lenReceived; aCopyBuf.SetLength(startPos + lenReceived); return r; }
// ----------------------------------------------------------------------------- // CDirectoryDesc::Read : Reading from a Directory // ----------------------------------------------------------------------------- void CDirectoryDesc::Read(TDes8& aDesc, TRequestStatus& aStatus) { TInt errorNum = KErrNone; const TInt16 KDirentSize = 8; TInt readLen = aDesc.MaxLength(); TUint8* bufPtr = const_cast<TUint8*>(aDesc.Ptr()); TInt copiedInfo = 0; TEntryArray entries; errorNum = iDir.Read( entries ); TDirent direntEntry; if (errorNum == KErrNone || errorNum == KErrEof) { errorNum = KErrNone; TEntry entry; TInt len = 0; TInt count = entries.Count(); TBuf8<KMaxFileName> fileName; TInt index = 0; TInt copyLen = 0; //Loop through each entry and get all the informations for (; index<count && copiedInfo<readLen; index++, copiedInfo += copyLen) { entry = entries[index]; //Copy File's UID TUid fileUID = entry.iType.MostDerived(); direntEntry.iEntryNum = fileUID.iUid; HBufC8 *name; if(ConvertUnicodeToUtf8(entry.iName,name,errorNum) == -1) { break; } //Copy entry type and record Length fileName.Copy( name->Des() ); delete name; len = fileName.Length(); direntEntry.iRecLen = KDirentSize + len + 1; //Maintaing a four byte boundary. direntEntry.iRecLen = Align4(direntEntry.iRecLen); direntEntry.iEntryType = 0; direntEntry.iNameLen = len; //Copy entry name Mem::Copy( direntEntry.iEntryName, fileName.PtrZ(), len+1); //Copy structure on to the buffer copyLen = Min(direntEntry.iRecLen, (readLen - copiedInfo)); Mem::Copy( bufPtr, &direntEntry, copyLen ); bufPtr += copyLen; } } //Set the Length aDesc.SetLength( copiedInfo ); TRequestStatus* status = &aStatus; User::RequestComplete(status, errorNum); }
void CPaddingSSLv3::DoPadL(const TDesC8& aInput,TDes8& aOutput) { TInt paddingBytes=BlockSize()-(aInput.Length()%BlockSize()); aOutput.Append(aInput); aOutput.SetLength(aOutput.Length()+paddingBytes); for (TInt i=1;i<=paddingBytes;i++) { aOutput[aOutput.Length()-i]=(TUint8)(paddingBytes-1); } }
// --------------------------------------------------------- // CNSmlCmdsBase::TrimRightSpaceAndNull // Trims right spaces and zero terminator (NULL) // --------------------------------------------------------- EXPORT_C void CNSmlCmdsBase::TrimRightSpaceAndNull( TDes8& aDes ) const { aDes.TrimRight(); if ( aDes.Length() > 0 ) { if ( aDes[aDes.Length() - 1] == NULL ) { aDes.SetLength( aDes.Length() - 1 ); } } }
static void FormatSqlStmt(TDes8& aSqlBuf, const char aSql[], TInt aRecIds[], TInt aRecCnt) { aSqlBuf.Copy(TPtrC8((const TUint8*)aSql)); aSqlBuf.Append(_L8("(")); for(TInt i=0;i<aRecCnt;++i) { aSqlBuf.AppendNum((TInt64)aRecIds[i]); aSqlBuf.Append(_L8(",")); } aSqlBuf.SetLength(aSqlBuf.Length() - 1); aSqlBuf.Append(_L8(")")); }
/** Copies the content of the source descriptor to the destination descriptor. If the current thread is a user thread, i.e. the mode in spsr_svc is 'User', then data is read using user mode privileges . @param aDest The destination descriptor. @param aSrc The source descriptor. @panic KERN-COMMON 19, if aDest is not a valid descriptor type. @panic KERN-COMMON 23, if aSrc is longer that the maximum length of aDest. @panic KERN-EXEC 33, if aSrc is not a valid descriptor type. @pre Do not call from User thread if in a critical section. @pre Interrupts must be enabled. @pre Kernel must be unlocked. @pre No fast mutex can be held. @pre Call in a thread context. @pre Can be used in a device driver. @post The length of the destination descriptor is equal to the length of the source descriptor. */ EXPORT_C void Kern::KUDesGet(TDes8& aDest, const TDesC8& aSrc) { CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_THREAD_STANDARD,"Kern::KUDesGet"); //ETDes8BadDescriptorType = 19 //ETDes8Overflow = 23 //EKUDesInfoInvalidType= 33 TInt ulen, umax; TUint8* kptr=(TUint8*)aDest.Ptr(); const TUint8* uptr=Kern::KUDesInfo(aSrc, ulen, umax); aDest.SetLength(ulen); kumemget(kptr,uptr,ulen); }
TBool CSTPreferences::ReadSettingName(RFile& aFile, TDes8& aSettingName, TInt& aSettingLength) { aSettingName.SetLength(0); TBuf8<KMaxSettingNameLength + 10> buffer; if (aFile.Read(buffer) != KErrNone) return EFalse; TInt filePos = 0; if (aFile.Seek(ESeekCurrent, filePos) != KErrNone) return EFalse; TLex8 lex(buffer); lex.SkipSpaceAndMark(); while (lex.Peek()) { if (lex.Peek() == ':') { aSettingName = lex.MarkedToken(); LWRITELN(iLog, aSettingName); lex.Inc(); break; } lex.Inc(); } if (lex.Val(aSettingLength) != KErrNone) return EFalse; //iLog->WriteLineL(aSettingLength); while (lex.Peek()) { if (lex.Peek() == '=') break; lex.Inc(); } if (lex.Peek() != '=') return EFalse; lex.Inc(); TInt offset = filePos - (buffer.Length() - lex.Offset()); if (aFile.Seek(ESeekStart, offset) != KErrNone) return EFalse; return ETrue; }
void CEnumerator::GetUniqueKey( TDes8& aKey ) { LOGFN( "CEnumerator::GetUniqueKey" ); aKey.SetLength( 0 ); if ( iUniqueKey.CompareC( KZeroID ) == 0 ) { aKey.Fill( '\0', KWmDrmIdSize ); } else { aKey.Copy( iUniqueKey ); } }
TInt YModem::ReadPacket(TDes8& aDest) { TUint8* pD = (TUint8*)aDest.Ptr(); TInt r; TPtr8 d(pD, 0, 1); r = ReadBlock(d); if (r != KErrNone) return r; if (d.Length()==0) return KErrZeroLengthPacket; TUint8 b0 = *pD; if (b0==CAN) return KErrAbort; if (b0==EOT) return KErrEof; if (b0==SOH) iBlockSize=128; else if (b0==STX) iBlockSize=1024; else return KErrBadPacketType; iTimeout=5000000; iPacketSize = iBlockSize+5; d.Set(pD+1, 0, iPacketSize-1); r = ReadBlock(d); if (r!=KErrNone && r!=KErrTimedOut) return r; if (d.Length() < iPacketSize-1) return KErrPacketTooShort; TUint8 seq = pD[1]; TUint8 seqbar = pD[2]; seqbar^=seq; if (seqbar != 0xff) return KErrCorruptSequenceNumber; if (seq==iSeqNum) return KErrAlreadyExists; else { TUint8 nextseq=(TUint8)(iSeqNum+1); if (seq!=nextseq) return KErrWrongSequenceNumber; } iCrc=0; UpdateCrc(pD+3, iBlockSize); aDest.SetLength(iPacketSize); TUint16 rx_crc = (TUint16)((pD[iPacketSize-2]<<8) | pD[iPacketSize-1]); if (rx_crc != iCrc) return KErrBadCrc; ++iSeqNum; return KErrNone; }
void CImSmtpSession::GetIpAddress(TDes8& aAddress) /** Gets the local IP address from the socket without any trailing scope identifiers @param aAddress Buffer in which the IP address of the socket will be returned */ { aAddress.Copy(iSocket->LocalName()); // Remove the %nn scope identifier if present Eg. x.x.x.x.x.x%1 becomes x.x.x.x.x.x // This only occurs with IPv6 and was a requirement of multi-homing. TInt pos = aAddress.Locate(TChar('%')); if (pos>0) { aAddress.SetLength(pos); } }
// ----------------------------------------------------------------------------- // CWimCertHandler::ParseCertPublicKeyL // Parse public key from certificate. // ----------------------------------------------------------------------------- // void CWimCertHandler::ParseCertPublicKeyL( const TDesC8& aCertData, TDes8& aPublicKey, const TUint8 aCertType ) const { _WIMTRACE2(_L("WIM | WIMServer | CWimPublicKeyHandler::ParseCertPublicKeyL | Begin, type %d"), aCertType); CCertificate* certificate = NULL; CRSAPublicKey* publicKey = NULL; switch ( aCertType ) { case WIMI_CT_WTLS: { certificate = CWTLSCertificate::NewLC( aCertData ); publicKey = CWTLSRSAPublicKey::NewLC( certificate->PublicKey().KeyData() ); break; } case WIMI_CT_X509: { certificate = CX509Certificate::NewLC( aCertData ); publicKey = CX509RSAPublicKey::NewLC( certificate->PublicKey().KeyData() ); break; } default: { _WIMTRACE2(_L("WIM|WIMServer|CWimCertHandler::ParseCertPublicKeyL, type %d not supported"), aCertType); User::Leave( KErrNotSupported ); break; } } TX509RSAKeyEncoder encoder( *publicKey, ESHA1 ); CASN1EncBase* encoded = encoder.EncodeKeyLC(); TUint pos = 0; aPublicKey.SetLength( KPublicKeyLength ); // Check that Max. length is not exceeded if ( encoded->LengthDER() > static_cast< TUint >( KPublicKeyLength ) ) { _WIMTRACE(_L("WIM|WIMServer|CWimCertHandler::ParseCertPublicKeyL, too long public key")); User::Leave( KErrBadDescriptor ); } // Write encoded key to prealloced buffer encoded->WriteDERL( aPublicKey, pos ); CleanupStack::PopAndDestroy( 3, certificate ); // encoded, publicKey, certificate _WIMTRACE(_L("WIM | WIMServer | CWimPublicKeyHandler::ParseCertPublicKeyL | End")); }
LOCAL_C void ExtractEnumeratorComponentsL( const TDesC8& aMessageBuffer, TDes8& aStore, TDes8& aNamespace, TDes8& aHashKey ) { TInt len; TInt offset; TInt total = aMessageBuffer.Length(); offset = 0; len = aMessageBuffer[offset]; if ( len <= 0 || len > KMaxWmDrmStoreNameSize || offset + len + 1> total ) { User::Leave( KErrArgument ); } aStore.Copy( aMessageBuffer.Mid( offset + 1, len ) ); offset += len + 1; if ( offset >= total ) { User::Leave( KErrArgument ); } len = aMessageBuffer[offset]; if ( len <= 0 || len > KMaxWmDrmNamespaceNameSize || offset + len + 1 > total ) { User::Leave( KErrArgument ); } aNamespace.Copy( aMessageBuffer.Mid( offset + 1, len ) ); offset += len + 1; len = aMessageBuffer[offset]; if ( offset >= total ) { User::Leave( KErrArgument ); } if ( ( len > 0 && len != KWmDrmIdSize ) || offset + len + 1 > total ) { User::Leave( KErrArgument ); } else if ( len > 0 ) { aHashKey.Copy( aMessageBuffer.Mid( offset + 1, len ) ); } else { aHashKey.SetLength( 0 ); } }
/** * @internalTechnology * Writes DER-encoded bit string contents to aBuf. Prepends * the actual bit string octets with extra octet containing * number of unused bits in the last octet. Before writing, * converts contents of the bit string to big-endian form. * @param aBuf Buffer to write to; must be long enough; * see #CalculateContentsLengthDER method. */ void CASN1EncBitString::WriteContentsDERL(TDes8& aBuf) const { if (iContents->Length() > 0) { aBuf[0] = iPadding; TUint len = iContents->Length(); // We do not need to swap bits, as it is already done. aBuf.Replace(1, len, *iContents); } else { // no padding octet for the empty bit string aBuf.SetLength(0); } }
void TCafUtils::ReadDescriptor8L(RReadStream& aStream, TDes8& aBuffer) { aBuffer.SetLength(0); // Read the 8 bit data from a stream TInt dataLength = aStream.ReadInt32L(); if(dataLength > aBuffer.MaxLength()) { User::Leave(KErrOverflow); } if(dataLength > 0) { aStream.ReadL(aBuffer, dataLength); } }
TBool TDebugFunctionality::GetStopModeFunctionality(TDes8& aDFBlock) { TUint32 size = GetStopModeFunctionalityBufSize(); if (aDFBlock.MaxLength() < size) { // Insufficient space to contain the debug functionality block return EFalse; } TUint8* ptr = (TUint8*)&size; aDFBlock.SetLength(0); aDFBlock.Append(ptr, 4); TVersion version = TVersion(KStopModeMajorVersionNumber, KStopModeMinorVersionNumber, KStopModePatchVersionNumber); ptr = (TUint8*)&version; aDFBlock.Append(ptr, sizeof(TVersion)); AppendBlock((const TSubBlock&)StopModeFunctionalityCore,aDFBlock); AppendBlock((const TSubBlock&)StopModeFunctionalityFunctions,aDFBlock); AppendBlock((const TSubBlock&)StopModeFunctionalityList,aDFBlock); const TTagHeader& header = StopModeFunctionalityBuffers->iHeader; aDFBlock.Append((TUint8*)&header, sizeof(TTagHeader)); for(TInt i=0; i<EBuffersLast; i++) { TTag tag; TheDBufferManager.GetBufferDetails((TBufferType)i, tag); aDFBlock.Append((TUint8*)&tag, sizeof(TTag)); } if(aDFBlock.Length() != size - 4) { return EFalse; } TUint32* ptr32 = (TUint32*)aDFBlock.Ptr(); TUint32 checksum = 0; for(TInt i=0; i<aDFBlock.Length(); i+=4) { checksum^=*ptr32; ptr32++; } ptr = (TUint8*)&checksum; aDFBlock.Append(ptr, 4); return ETrue; }
TInt DArmPlatThread::Context(TDes8& aDes) { TArmRegSet& s=*(TArmRegSet*)aDes.Ptr(); aDes.SetLength(sizeof(s)); TInt r=KErrNone; if (iThreadType!=EThreadUser || this==TheCurrentThread) r=KErrAccessDenied; else if (iExiting) r=KErrDied; else { TUint32 unused; NKern::ThreadGetUserContext(&iNThread,&s,unused); } return r; }
void CPaddingPKCS1Signature::UnPadL(const TDesC8& aInput,TDes8& aOutput) { // erm, oops, this is not quite as simplistic as it first looks... // our integer class will strip any leading zeros so we might actually // get some real data that starts out looking like padding but isn't // really TInt inputLen = aInput.Length(); if (inputLen <=0 ) User::Leave(KErrInvalidPadding); // Invalid padding data // Leading zero may have been stripped off by integer class TInt dataStart=0; if (aInput[dataStart] == 0) { ++dataStart; } if (dataStart < inputLen && aInput[dataStart]) // might be mode one or mode zero, { ++dataStart; while (dataStart < inputLen && aInput[dataStart] == 0xff) { ++dataStart; } if (dataStart == inputLen || aInput[dataStart]) // this would mean theres no zero between 0x01ff and data...so its not mode one dataStart=0; // mode zero, start from begining of data else ++dataStart; } else // We've definitely got a mode zero { // or broken data, assume mode zero dataStart=0; } TInt len=inputLen-dataStart; __ASSERT_DEBUG(aOutput.MaxLength() >= len, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); aOutput.SetLength(len); TInt i=0; while (dataStart<inputLen) { aOutput[i++]=aInput[dataStart++]; } }
EXPORT_C TInt CSecureSocket::AvailableCipherSuites( TDes8& aCiphers ) { if ( aCiphers.MaxLength() < 64 ) { return KErrArgument; } aCiphers.SetLength( 6 ); BigEndian::Put16( &aCiphers[ 0 ], 4 ); const TUint TLS_RSA_WITH_AES_128_CBC_SHA_Value = 0x2F; BigEndian::Put16( &aCiphers[ 2 ], TLS_RSA_WITH_AES_128_CBC_SHA_Value ); BigEndian::Put16( &aCiphers[ 4 ], 64 ); return KErrNone; }
void CMemSpyMemStreamReader::ReadL( TDes8& aDes ) { const TInt length = ReadInt32L(); // Need to check the remaining text is actually present... IsAvailableL( length ); // Now read into client descriptor aDes.SetLength( length ); if ( length > 0 ) { TUint8* dest = const_cast< TUint8* >( aDes.Ptr() ); Mem::Copy( dest, iCurrent, length ); } // IncrementPos( length ); }
EXPORT_C TBool IkePkiUtils::GetCertSubjectNameDERL(const CX509Certificate* aCert, TDes8& aSubjectName) { TBool status = ETrue; HBufC8* nameBfr = IkeCert::GetCertificateFieldDERL(aCert, KSubjectName); if ( nameBfr && ( nameBfr->Des().Length() <= aSubjectName.MaxLength() ) ) { aSubjectName.Copy(nameBfr->Des()); delete nameBfr; } else { aSubjectName.SetLength(0); status = EFalse; } return status; }
EXPORT_C TInt TExtendedInquiryResponseDataCodec::DoSanityCheck(TDes8& aDes) { TInt error = KErrNone; TInt offset = NextDataType(0); TUint32 eirTagPresentFlag = 0; // this is a bit mask for existing eir types TInt tag = 0; while(offset >= KErrNone) { if(!IsValideDataType(iEir[offset])) { // the next data type isn't a known(valid) eir tag error = KErrNotSupported; break; } if(static_cast<TInt>(iEir[offset - KEIRLengthToTagOffset]) < 0) { // length is less than 0 error = KErrUnderflow; break; } tag = (iEir[offset] == EEirVendorSpecific ? KSizeOfEIRTagBitMask : iEir[offset]); // check if the tag is already present from previous parsing if(eirTagPresentFlag & (1 << tag)) { error = KErrAlreadyExists; break; } else { // set flag for this data tag eirTagPresentFlag |= (1 << tag); offset = NextDataType(offset); } } error = offset == KErrCorrupt ? offset : error; if(error != KErrNone) { // remove all the data after this LTV unit iEir.SetLength(offset - KEIRLengthToTagOffset); aDes.SetLength(offset - KEIRLengthToTagOffset); } return error; }
/** @prototype @deprecated @see RFilePlugin::Read */ EXPORT_C TInt CFsPlugin::FileRead(TFsPluginRequest& aRequest, TDes8& aDes, TInt64 aPos) { CFileShare* share; CFileCB* file; GetFileFromScratch((CFsMessageRequest*) aRequest.Request(), share, file); TInt64 fileSize = file->CachedSize64(); if (aPos > fileSize) aPos = fileSize; TInt len = aDes.Length(); if (aPos >= fileSize) len = 0; if (aPos + len > fileSize) // filesize - pos shall of TInt size // Hence to suppress warning len = (TInt)(fileSize - aPos); aDes.SetLength(len); return DispatchOperation(aRequest, aDes, aPos, EFsFileRead); }
void CPaddingPKCS1Encryption::UnPadL(const TDesC8& aInput,TDes8& aOutput) { TInt inputLen = aInput.Length(); if (inputLen <= 0) User::Leave(KErrInvalidPadding); // Invalid padding data // Leading zero may have been stripped off by integer class TInt dataStart=0; if (aInput[dataStart] == 0) { ++dataStart; } // expecting mode 2 padding, otherwise broken if (dataStart == inputLen || aInput[dataStart] != 2) { User::Leave(KErrInvalidPadding); } ++dataStart; // skip random non zero bytes while (dataStart < inputLen && aInput[dataStart]) { ++dataStart; } // expecting zero separator if (dataStart == inputLen || aInput[dataStart] != 0) { User::Leave(KErrInvalidPadding); } ++dataStart; TInt len = inputLen - dataStart; __ASSERT_DEBUG(aOutput.MaxLength() >= len, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); aOutput.SetLength(len); TInt i=0; while (dataStart<inputLen) { aOutput[i++]=aInput[dataStart++]; } }
void CDatabase::HexToStrL(TDes8& aSource) /** Convert a string containing hexadecimal representation to another string containing binary representation @param aSource Source data containing a string */ { TUint8 *pSource = (TUint8 *)aSource.Ptr(); TUint8 *pDest = (TUint8 *)aSource.Ptr(); TInt len = aSource.Length(); TInt idxSource; TInt idxDest; for(idxSource=0, idxDest=0; idxSource<len; ++idxDest,idxSource+=2) { pDest[idxDest] = HexToIntL(pSource+idxSource); } aSource.SetLength(idxDest); }